@Test public void create_ShouldSaveNewCustomerEntry() { CustomerDTO newCustomerDTO = new CustomerDTOBuilder() .firstName(FIRST_NAME) .lastName(FIRST_NAME) .company(COMPONY) .phone(PHONE) .fax(FAX) .email(EMAIL) .website(WEBSITE) .description(DESCRIPTION) .build(); when(repository.save(isA(Customer.class))) .thenAnswer(invocation -> (Customer) invocation.getArguments()[0]); service.create(newCustomerDTO); ArgumentCaptor<Customer> savedCustomerrgument = ArgumentCaptor.forClass(Customer.class); verify(repository, times(1)).save(savedCustomerrgument.capture()); verifyNoMoreInteractions(repository); assertThatTodoDTO(newCustomerDTO).hasEmailId(EMAIL).hasDescription(DESCRIPTION); }
@Test(expected = CustomerNotFoundException.class) public void findById_CustomerEntryNotFound_ShouldThrowException() { when(repository.findOne(ID)).thenReturn(null); CustomerDTO newCustomerDTO = new CustomerDTOBuilder().id(ID).build(); service.update(newCustomerDTO); }
@Test public void findAll_OneCustomerEntryFound_ShouldReturnTheInformationOfFoundCustomerEntry() { Customer expected = new CustomerBuilder() .id(ID) .firstName(FIRST_NAME) .company(COMPONY) .lastName(LAST_NAME) .fax(FAX) .phone(PHONE) .email(EMAIL) .description(DESCRIPTION) .build(); when(repository.findAll()).thenReturn(Arrays.asList(expected)); List<CustomerDTO> todoEntries = service.findAll(); assertThat(todoEntries).hasSize(1); CustomerDTO actual = todoEntries.iterator().next(); assertThatTodoDTO(actual).hasId(ID).hasEmailId(EMAIL).hasDescription(DESCRIPTION); }