ConfigInitializer { public static void initialize(Properties properties, Class<?> rootConfigType) throws IllegalAccessException { initNextLevel(properties, rootConfigType, new ConfigDesc()); }  static void initialize(Properties properties, Class<?> rootConfigType);  }
@Test public void testInitialize() throws IllegalAccessException { Properties properties = new Properties(); properties.put("Level1Object.STR_ATTR".toLowerCase(), "stringValue"); properties.put("Level1Object.Level2Object.INT_ATTR".toLowerCase(), "1000"); properties.put("Level1Object.Level2Object.LONG_ATTR".toLowerCase(), "1000"); properties.put("Level1Object.Level2Object.BOOLEAN_ATTR".toLowerCase(), "true"); properties.put("Level1Object.LIST_ATTR".toLowerCase(), "1,2,3"); properties.put("Level1Object.LIST_EMPTY_ATTR".toLowerCase(), ""); properties.put("Level1Object.Level2Object.ENUM_ATTR".toLowerCase(), "RED"); ConfigInitializer.initialize(properties, TestPropertiesObject.class); Assert.assertEquals("stringValue", TestPropertiesObject.Level1Object.STR_ATTR); Assert.assertEquals(1000, TestPropertiesObject.Level1Object.Level2Object.INT_ATTR); Assert.assertEquals(1000L, TestPropertiesObject.Level1Object.Level2Object.LONG_ATTR); Assert.assertEquals(true, TestPropertiesObject.Level1Object.Level2Object.BOOLEAN_ATTR); Assert.assertArrayEquals(new String[] {}, TestPropertiesObject.Level1Object.LIST_EMPTY_ATTR.toArray()); Assert.assertEquals(TestColorEnum.RED, TestPropertiesObject.Level1Object.Level2Object.ENUM_ATTR); Assert.assertEquals(new ConfigDesc().toString(), ""); }
@Test public void testInitializeWithUnsupportedConfig() throws IllegalAccessException { Properties properties = new Properties(); properties.put("Level1Object.noExistAttr".toLowerCase(), "stringValue"); ConfigInitializer.initialize(properties, TestPropertiesObject.class); Assert.assertNull(TestPropertiesObject.Level1Object.STR_ATTR); }