@Test public void testFindCustomerByCustomerName() { Customer expectedCustomer = new Customer(); expectedCustomer.setFirstName("John"); expectedCustomer.setLastName("Doe"); String customerName = expectedCustomer.getFirstName() + " " + expectedCustomer.getLastName(); Mockito.when(customerRepository.findByFirstNameAndLastName(Matchers.anyString(), Matchers.anyString())) .thenReturn(expectedCustomer); Customer customer = customerService.findCustomerByCustomerName(customerName); assertThat(customer.getFirstName()).isEqualTo("John"); assertThat(customer.getLastName()).isEqualTo("Doe"); }
@Override public Customer findCustomerByCustomerName(String customerName) { String[] firstNameAndLastName = customerName.split(" "); Customer customer = customerRepository.findByFirstNameAndLastName(firstNameAndLastName[0], firstNameAndLastName[1]); if(customer != null) { return customer; } throw new RuntimeException("Unknown Customer with name: " + customerName); }
CustomerServiceImpl implements CustomerService { @Override public Customer findCustomerByCustomerName(String customerName) { String[] firstNameAndLastName = customerName.split(" "); Customer customer = customerRepository.findByFirstNameAndLastName(firstNameAndLastName[0], firstNameAndLastName[1]); if(customer != null) { return customer; } throw new RuntimeException("Unknown Customer with name: " + customerName); } }
CustomerServiceImpl implements CustomerService { @Override public Customer findCustomerByCustomerName(String customerName) { String[] firstNameAndLastName = customerName.split(" "); Customer customer = customerRepository.findByFirstNameAndLastName(firstNameAndLastName[0], firstNameAndLastName[1]); if(customer != null) { return customer; } throw new RuntimeException("Unknown Customer with name: " + customerName); }  }
CustomerServiceImpl implements CustomerService { @Override public Customer findCustomerByCustomerName(String customerName) { String[] firstNameAndLastName = customerName.split(" "); Customer customer = customerRepository.findByFirstNameAndLastName(firstNameAndLastName[0], firstNameAndLastName[1]); if(customer != null) { return customer; } throw new RuntimeException("Unknown Customer with name: " + customerName); }  @Override Customer addCustomer(Customer customer); @Override @Transactional(readOnly = true) List<Customer> getCustomers(); @Override Customer findCustomerByCustomerName(String customerName); @Override @Transactional(readOnly = true) Customer findCustomerByCustomerId(int customerId); }
CustomerServiceImpl implements CustomerService { @Override public Customer findCustomerByCustomerName(String customerName) { String[] firstNameAndLastName = customerName.split(" "); Customer customer = customerRepository.findByFirstNameAndLastName(firstNameAndLastName[0], firstNameAndLastName[1]); if(customer != null) { return customer; } throw new RuntimeException("Unknown Customer with name: " + customerName); }  @Override Customer addCustomer(Customer customer); @Override @Transactional(readOnly = true) List<Customer> getCustomers(); @Override Customer findCustomerByCustomerName(String customerName); @Override @Transactional(readOnly = true) Customer findCustomerByCustomerId(int customerId);  }