EmployeeGeneratorService { @Transactional public void resetEmployees(Long numberOfEmployees) { if (numberOfEmployees < 1 || numberOfEmployees > MAX_GENERATED_EMPLOYEES) { throw new IllegalArgumentException("The number of generated employees must be between 1 and " + MAX_GENERATED_EMPLOYEES); } deleteEmployeesAndEverythingRelated(); generateNewEmployees(numberOfEmployees); }  @Transactional void resetEmployees(Long numberOfEmployees); static final Long MAX_GENERATED_EMPLOYEES; }
@Test(expected = IllegalArgumentException.class) public void whenGenerateTooManyEmployees_thenThrowException() { employeeGeneratorService.resetEmployees(TEST_MAX_GENERATED_EMPLOYEES); }
@Test(expected = IllegalArgumentException.class) public void whenGenerateNoEmployees_thenThrowException() { employeeGeneratorService.resetEmployees(TEST_ZERO_EMPLOYEES); }
@Test public void whenGenerateEmployees_thenEmployeesGetSaved() { employeeGeneratorService.resetEmployees(3L); verify(employeeGeneratorCleaner).deleteAll(); verify(employeeRepositoryMock, times(3)).save(any(Employee.class)); }