@Test public void savesRegistration() { OrchestraRegistration registration = new OrchestraRegistration(); beanUnderTest.createRegistration(registration); verify(mockedEntityManager).merge(registration); verifyNoMoreInteractions(mockedEntityManager); }
@Test public void returnsAllRegistrations() { final OrchestraRegistration expected = new OrchestraRegistration(); TypedQuery<OrchestraRegistration> mockQuery = getQueryThatReturnsList(Collections.singletonList(expected)); when(mockedEntityManager.createQuery(anyString(), eq(OrchestraRegistration.class))) .thenReturn(mockQuery); List<OrchestraRegistration> actualRegistrations = beanUnderTest.getRegistrations(); assertNotNull( actualRegistrations, "OrchestraRegistrationHandlerBean.getRegistrations returned null."); assertEquals(actualRegistrations.size(), 1, "Wrong number of registrations"); OrchestraRegistration actual = actualRegistrations.get(0); assertEquals(actual, expected, "Wrong registration returned"); }
@BeforeMethod public void setUp() throws Exception { beanUnderTest = new OrchestraRegistrationHandlerBean(); mockedEntityManager = mock(EntityManager.class); beanUnderTest.setEntityManager(mockedEntityManager); }