YamlParser { public Properties yamlToProperties(String yamlContent) { Yaml yaml = createYaml(); final Properties result = propertiesFactory.getPropertiesInstance(); process(new MatchCallback() { @Override public void process(Properties properties, Map<String, Object> map) { result.putAll(properties); } }, yaml, yamlContent); return result; }  Properties yamlToProperties(String yamlContent);  }
@Test public void testOrderProperties() throws IOException { String yamlContent = loadYaml("orderedcase.yaml"); Properties nonOrderedProperties = parser.yamlToProperties(yamlContent); PropertiesFactory propertiesFactory = mock(PropertiesFactory.class); when(propertiesFactory.getPropertiesInstance()).thenAnswer(new Answer<Properties>() { @Override public Properties answer(InvocationOnMock invocation) { return new OrderedProperties(); } }); MockInjector.setInstance(PropertiesFactory.class, propertiesFactory); parser = new YamlParser(); Properties orderedProperties = parser.yamlToProperties(yamlContent); assertTrue(orderedProperties instanceof OrderedProperties); checkPropertiesEquals(nonOrderedProperties, orderedProperties); String[] propertyNames = orderedProperties.stringPropertyNames().toArray(new String[0]); assertEquals("k2", propertyNames[0]); assertEquals("k4", propertyNames[1]); assertEquals("k1", propertyNames[2]); }