Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException in EmailServiceImplTest.sendNotificationByEmail #429

Closed
LazarenkoDmytro opened this issue Dec 18, 2024 · 0 comments
Closed
Assignees
Labels
bug Something isn't working

Comments

@LazarenkoDmytro
Copy link
Contributor

The test EmailServiceImplTest.sendNotificationByEmail fails with a NullPointerException when calling user.getLanguage().getCode() in the sendNotificationByEmail method of EmailServiceImpl.

Cause

The issue occurs because the User object created in the test does not have a Language specified. As a result, user.getLanguage() returns null, leading to the exception.

Error Stack Trace

java.lang.NullPointerException
	at greencity.service.EmailServiceImpl.sendNotificationByEmail(EmailServiceImpl.java:339)
	at greencity.service.EmailServiceImplTest.sendNotificationByEmail(EmailServiceImplTest.java:283)
	...

Steps to Reproduce

  1. Run the sendNotificationByEmail test in EmailServiceImplTest.
  2. Observe the NullPointerException in the test output.

Suggested Fix

Update the test sendNotificationByEmail to include a Language object in the User builder. Replace:

User user = User.builder().build();

with:

User user = User.builder().language(new Language()).build();

This ensures that the Language object is not null and prevents the NullPointerException.

Additional Information

  • Class: EmailServiceImpl
  • Method: sendNotificationByEmail
  • Test Class: EmailServiceImplTest
@LazarenkoDmytro LazarenkoDmytro added the bug Something isn't working label Dec 18, 2024
@LazarenkoDmytro LazarenkoDmytro moved this to Bugs in GreenCity Dec 18, 2024
@LazarenkoDmytro LazarenkoDmytro changed the title # NullPointerException in EmailServiceImplTest.sendNotificationByEmail NullPointerException in EmailServiceImplTest.sendNotificationByEmail Dec 18, 2024
@LazarenkoDmytro LazarenkoDmytro self-assigned this Dec 18, 2024
@LazarenkoDmytro LazarenkoDmytro moved this from Bugs to Bugs in progress in GreenCity Dec 18, 2024
@LazarenkoDmytro LazarenkoDmytro moved this from Bugs in progress to Done in GreenCity Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

No branches or pull requests

1 participant