ResourceHandler { Properties getResourceAsProperties(String path) throws IOException { final Properties properties = new Properties(); final InputStream is = getResourceStream(path); if (is != null) { properties.load(is); is.close(); } return properties; }    }
@Test public void testGetResourceAsProperties_fromJar() throws IOException { final Properties properties = resourceHandler.getResourceAsProperties("structs_MIR_SCXX1C.properties"); assertNotNull(properties); assertEquals("true", properties.getProperty("Quality_Information_Type")); }
@Test public void testGetResourceAsProperties_fromJar_unknownProperty() throws IOException { final Properties properties = resourceHandler.getResourceAsProperties("stupid_and_invalid.properties"); assertNotNull(properties); assertEquals(0, properties.size()); }
@Test public void testGetResourceAsProperties_fromDirectory() throws IOException { File targetDirectory = null; try { targetDirectory = createTestDirectory(); System.setProperty(ResourceHandler.SMOS_DDDB_DIR_PROPERTY_NAME, targetDirectory.getAbsolutePath()); final File testFile = createTestFile(targetDirectory, "test.properties"); final PrintWriter writer = new PrintWriter(testFile); writer.println("the_property = a_value"); writer.close(); final Properties properties = resourceHandler.getResourceAsProperties("test.properties"); assertNotNull(properties); assertEquals("a_value", properties.getProperty("the_property")); } finally { System.clearProperty(ResourceHandler.SMOS_DDDB_DIR_PROPERTY_NAME); if (targetDirectory != null && targetDirectory.isDirectory()) { if (!FileUtils.deleteTree(targetDirectory)) { fail("Unable to delete test directory"); } } } }