So i have this code, where im trying to mock that atendees receive the notifications:
@Mock
Event event;
@Mock
Attendee attende;
@InjectMocks
EventNotificationServiceImpl eventNotificationService;
@Test
public void checkIfAttendesAreNotified() {
event.addAttendee(attende);
eventNotificationService.announce(event);
System.out.println(attende.getNotifications());
List<Notification> notifications = attende.getNotifications();
for (Notification notification : notifications) {
assertEquals("The next big event is coming!", notification.getMessage());
}
}
however here i dont see that atendees receive any notifications.But when I put this code, i see attendes receive notifications:
@Mock
Event event;
@Mock
Attendee attende;
@InjectMocks
EventNotificationServiceImpl eventNotificationService;
@Test
public void checkIfAttendesAreNotified() {
attende = new Attendee(1L,"sara", "sara@example.com");
event = new Event();
event.addAttendee(attende);
eventNotificationService.announce(event);
System.out.println(attende.getNotifications());
List<Notification> notifications = attende.getNotifications();
for (Notification notification : notifications) {
assertEquals("The next big event is coming!", notification.getMessage());
}
}
Id like to know why mocks are not being inicitialized. Id like to not have to create the event and attendees objects in the tests since this bring me problems cause when i try to verify, attendees and events are not recognized as mocks. If someone can help me Id be very thankful! :)))
Aucun commentaire:
Enregistrer un commentaire