### Question:
SimpleUserSystemService implements UserSystemService { @Override public void start() { final String usersFile = System.getProperty(USERS_FILE); if (isEmpty(usersFile)) { String msg = String.format(USERS_FILE_NOT_CONFIGURED_ERROR, USERS_FILE); throw new SimpleUserSystemServiceException(msg); } final String skillsFile = System.getProperty(SKILLS_FILE); if (isNotEmpty(skillsFile)) { LOGGER.info("Using skills configuration from: {}", skillsFile); } final String affinitiesFile = System.getProperty(AFFINITIES_FILE); if (isNotEmpty(affinitiesFile)) { LOGGER.info("Using affinities configuration from: {}", affinitiesFile); } try { this.userGroupInfo = SimpleUserSystemServiceHelper.buildInfo(Paths.get(usersFile), isNotEmpty(skillsFile) ? Paths.get(skillsFile) : null, isNotEmpty(affinitiesFile) ? Paths.get(affinitiesFile) : null); this.userById = userGroupInfo.getUsers().stream().collect(Collectors.toMap(User::getId, Function.identity())); } catch (Exception e) { String msg = String.format(USERS_INFO_LOADING_ERROR, usersFile, skillsFile, affinitiesFile); throw new SimpleUserSystemServiceException(msg, e); } } SimpleUserSystemService(); @Override void start(); @Override String getName(); @Override List<User> findAllUsers(); List<Group> findAllGroups(); @Override void test(); @Override User findUser(String id); static final String USERS_FILE; static final String SKILLS_FILE; static final String AFFINITIES_FILE; static final String NAME; }### Answer:
@Test public void startSuccess() { Assertions.assertThatCode(() -> userSystem.start()) .doesNotThrowAnyException(); }
@Test public void startWithoutSkillsAndAffinitiesSuccess() { System.clearProperty(SimpleUserSystemService.SKILLS_FILE); System.clearProperty(SimpleUserSystemService.AFFINITIES_FILE); Assertions.assertThatCode(() -> userSystem.start()) .doesNotThrowAnyException(); }
@Test public void startWithUsersFileNotConfiguredError() { System.clearProperty(SimpleUserSystemService.USERS_FILE); String expectedMessage = String.format(USERS_FILE_NOT_CONFIGURED_ERROR, SimpleUserSystemService.USERS_FILE); Assertions.assertThatThrownBy(() -> userSystem.start()) .hasMessage(expectedMessage); }
@Test public void startWithUsersFileLoadingError() { System.setProperty(SimpleUserSystemService.USERS_FILE, NON_EXISTING_PATH); String expectedMessage = String.format(USERS_INFO_LOADING_ERROR, NON_EXISTING_PATH, skillsPath, affinitiesPath); Assertions.assertThatThrownBy(() -> userSystem.start()) .hasMessage(expectedMessage); }
@Test public void startWithSkillsFileLoadingError() { System.setProperty(SimpleUserSystemService.SKILLS_FILE, NON_EXISTING_PATH); String expectedMessage = String.format(USERS_INFO_LOADING_ERROR, usersPath, NON_EXISTING_PATH, affinitiesPath); Assertions.assertThatThrownBy(() -> userSystem.start()) .hasMessage(expectedMessage); }
@Test public void startWithAffinitiesFileLoadingError() { System.setProperty(SimpleUserSystemService.AFFINITIES_FILE, NON_EXISTING_PATH); String expectedMessage = String.format(USERS_INFO_LOADING_ERROR, usersPath, skillsPath, NON_EXISTING_PATH); Assertions.assertThatThrownBy(() -> userSystem.start()) .hasMessage(expectedMessage); }