@Test public void testAddCustomer() throws Exception { Customer customer = new Customer(); customer.setFirstname("John"); customer.setLastname("Isaac"); customer.setEmail("*****@*****.**"); customer.setTelephone("0466985854"); when(customerDAO.addCustomer(customer)).thenReturn(true); assertTrue(customerService.addCustomer(customer)); }
@Test public void testListCustomer() throws Exception { Customer customer = new Customer(); customer.setFirstname("John"); customer.setLastname("Isaac"); customer.setEmail("*****@*****.**"); customer.setTelephone("0466985854"); List mockedList = mock(List.class); mockedList.add("abc"); System.out.println(mockedList.size()); when(customerDAO.listCustomer()).thenReturn(mockedList); when(mockedList.get(0)).thenReturn(customer); List cusList = customerDAO.listCustomer(); assertNotNull(cusList); Customer testCustomer = (Customer) cusList.get(0); assertNotNull(testCustomer); assertEquals("Asserting First Name", "John", testCustomer.getFirstname()); assertEquals("Asserting Last Name", "Isaac", testCustomer.getLastname()); assertEquals("Asserting Email", "*****@*****.**", testCustomer.getEmail()); assertEquals("Asserting Phone", "0466985854", testCustomer.getTelephone()); }