YAMLUtils { public void loadSettings(String resourcePath, String defaultResourcePath, Object bean) { try { Map properties = loadSettings(resourcePath, defaultResourcePath); BeanUtils.populate(bean, properties); } catch (IllegalAccessException | InvocationTargetException | IOException e) { throw new IllegalStateException(e); } }  void loadSettings(String resourcePath, String defaultResourcePath, Object bean); void loadSettings(String resourcePath, Object bean); @SuppressWarnings("unchecked") Map loadSettings(String resourcePath, String defaultResourcePath); @SuppressWarnings("unchecked") Map loadAsMap(String path); @SuppressWarnings("unchecked") Map loadStringAsMap(String content);  }
@Test(timeOut = 10_000) public void testLoadDefaultSettings_setToBean() throws Exception { Map map = new HashMap(); new YAMLUtils().loadSettings("test.yml", "default-test.yml", map); Assert.assertNotNull(map); Assert.assertEquals(map.get("prop1"), 11); Assert.assertEquals(map.get("prop2"), "22"); Assert.assertEquals(map.get("prop3"), 3); }
@Test(timeOut = 10_000) public void testLoadDefaultSettings_setToBean2() throws Exception { Map map = new HashMap(); new YAMLUtils().loadSettings("test.yml", map); Assert.assertNotNull(map); Assert.assertEquals(map.get("prop1"), 11); Assert.assertEquals(map.get("prop2"), "22"); Assert.assertEquals(map.size(), 2); }