@Test public void testCreateCustomer() { Customer cust = new Customer(); cust.setId(1L); service.createCustomer(cust); verify(customerDaoMock).create(cust); verifyNoMoreInteractions(customerDaoMock); }
@Test public void testFindCustomerById() { Customer c1 = new Customer(); c1.setId(1L); doReturn(c1).when(customerDaoMock).findById(1L); Customer customer = service.findCustomerById(1L); verify(customerDaoMock).findById(1L); verifyNoMoreInteractions(customerDaoMock); Assert.assertEquals(Long.valueOf(1), customer.getId()); }
@Test public void testDeleteCustomer() { Customer c1 = new Customer(); c1.setId(1L); doReturn(c1).when(customerDaoMock).findById(1L); service.deleteCustomer(1L); verify(customerDaoMock).findById(1L); verify(customerDaoMock).remove(c1); verifyNoMoreInteractions(customerDaoMock); }
@Test public void testFindCustomerByEmail() { Customer c1 = new Customer(); String email = "*****@*****.**"; c1.setEmail(email); doReturn(c1).when(customerDaoMock).findByEmail(email); Customer customer = service.findCustomerByEmail(email); verify(customerDaoMock).findByEmail(email); verifyNoMoreInteractions(customerDaoMock); Assert.assertEquals(email, customer.getEmail()); }
@Test public void testFindAllCustomers() { Customer c1 = new Customer(); c1.setId(1L); Customer c2 = new Customer(); c2.setId(2L); doReturn(toList(new Customer[] {c1, c2})).when(customerDaoMock).findAll(); Collection<Customer> customers = service.findAllCustomers(); verify(customerDaoMock).findAll(); verifyNoMoreInteractions(orderDaoMock); Assert.assertEquals(2, customers.size()); }