EventRegistrationService { public Registration getByEventIdAndRegistrationId(String eventId, String registrationId) throws EntityMismatchException, EntityNotFoundException { Event event = eventEntityService.getById(eventId); Registration registration = registrationEntityService.getById(registrationId); if (!registration.getEvent().getId().equals(event.getId())) { throw new EntityMismatchException(); } return registration; } @Inject  EventRegistrationService(
            EventEntityService eventEntityService,
            RegistrationEntityService registrationEntityService
    ); Registration getByEventIdAndRegistrationId(String eventId, String registrationId); List<Registration> getAllWithEventId(String eventId); Registration add(RegistrationAddPayload addPayload);  }
@Test public void whenGetByEventIdAndRegistrationIdValid() throws Exception { Event event = mock(Event.class); Registration registration = mock(Registration.class); when(registration.getEvent()).thenReturn(event); when(event.getId()).thenReturn(TestConstants.EVENT_ID); when(eventEntityService.getById(TestConstants.EVENT_ID)).thenReturn(event); when(registrationEntityService.getById(TestConstants.REGISTRATION_ID)).thenReturn(registration); Registration actual = eventRegistrationService.getByEventIdAndRegistrationId( TestConstants.EVENT_ID, TestConstants.REGISTRATION_ID ); verify(eventEntityService).getById(TestConstants.EVENT_ID); verify(registrationEntityService).getById(TestConstants.REGISTRATION_ID); assertThat(actual).isSameAs(registration); }