PropertyFileParser { public static Properties parse(FileReference propertiesFile) throws ConfigurationException { Properties properties = new Properties(); try { properties.load(new StringReader(propertiesFile.getContent())); } catch (FileOperationException e) { throw new ConfigurationException( "Cannot read the properties file '" + propertiesFile.getAbsolutePath() + "'.", e); } catch (IllegalArgumentException e) { throw new ConfigurationException( "Cannot parse the properties file '" + propertiesFile.getAbsolutePath() + "'.", e); } catch (IOException e) { throw new ConfigurationException( "Cannot load the properties file '" + propertiesFile.getAbsolutePath() + "'.", e); } return properties; }  static Properties parse(FileReference propertiesFile);  }
@Test public void testCannotReadFile() { FileReference propertiesFile = mock(FileReference.class); when(propertiesFile.getContent()).thenThrow(FileOperationException.class); Assert.assertThrows(ConfigurationException.class, () -> PropertyFileParser.parse(propertiesFile)); }
@Test public void testInvalidFile() { FileReference propertiesFile = mock(FileReference.class); when(propertiesFile.getContent()).thenReturn("# testing\n" + "pets-store.all=See all our amazing pets\\u\n"); Assert.assertThrows(ConfigurationException.class, () -> PropertyFileParser.parse(propertiesFile)); }
@Test public void test() { FileReference propertiesFile = mock(FileReference.class); when(propertiesFile.getContent()).thenReturn("# testing\n" + "pets-store.all=See all our amazing pets\n" + "pets-store.add=Ajouter un nouvel animal de compagnie\n" + "pets-store.petOfTheMonth=මාසයේ සුරතලා\n"); Properties properties = PropertyFileParser.parse(propertiesFile); Assert.assertEquals(properties.size(), 3); Assert.assertEquals(properties.get("pets-store.all"), "See all our amazing pets"); Assert.assertEquals(properties.get("pets-store.add"), "Ajouter un nouvel animal de compagnie"); Assert.assertEquals(properties.get("pets-store.petOfTheMonth"), "මාසයේ සුරතලා"); }