PropertyLoader { static Properties loadProperties(@Nonnull File pluginsDirectory) throws IOException { if (!pluginsDirectory.exists()) { throw new IOException(format(DIRECTORY_NOT_FOUND_ERROR_MESSAGE, pluginsDirectory.getAbsolutePath())); } File propertyFile = new File(pluginsDirectory, PROPERTY_FILE); if (!propertyFile.exists()) { throw new IOException(format(FILE_NOT_FOUND_ERROR_MESSAGE, propertyFile.getAbsolutePath())); } Properties properties = new Properties(); try (FileInputStream fis = new FileInputStream(propertyFile)) { properties.load(fis); } return properties; } private  PropertyLoader();   }
@Test void loadProperties_shouldThrowIOE_ifPluginsDirNotExist() { Path notExistingPluginsDir = Paths.get(TEST_DIRECTORY.getAbsolutePath(), "not-existing-plugins-dir"); IOException exception = assertThrows(IOException.class, () -> PropertyLoader.loadProperties(notExistingPluginsDir.toFile())); assertLinesMatch(singletonList("^Directory '.*' not found$"), singletonList(exception.getMessage())); }
@Test void loadProperties_shouldThrowIOE_ifPropertyFileNotExist() { Path pluginsDirWithoutPropertyFile = Paths.get(TEST_DIRECTORY.getAbsolutePath(), "without-property-file"); IOException exception = assertThrows(IOException.class, () -> PropertyLoader.loadProperties(pluginsDirWithoutPropertyFile.toFile())); assertLinesMatch(singletonList("^File '.*' not found$"), singletonList(exception.getMessage())); }
@Test void loadProperties_shouldNotThrowException_ifPropertyFileExist() throws IOException { Path pluginsDirWithoutPropertyFile = Paths.get(TEST_DIRECTORY.getAbsolutePath(), "valid-property-file"); PropertyLoader.loadProperties(pluginsDirWithoutPropertyFile.toFile()); }