### Question:
ConfigDef { @SuppressWarnings("unchecked") public static ConfigDef of(Class configClass) { ConfigDef.Builder builder = ConfigDef.builder(); Field[] fields = configClass.getDeclaredFields(); for (Field field : fields) { if (Modifier.isStatic(field.getModifiers()) && field.getType().equals(ConfigKey.class)) { field.setAccessible(true); try { builder.withConfigKey((ConfigKey) field.get(null)); } catch (IllegalAccessException e) { log.error("Illegal to access {}#{}", configClass.getSimpleName(), field.getName(), e); } } } return builder.build(); } private  ConfigDef(Set<ConfigKeyGroup> groups,
                      Map<String, Set<ConfigKey>> settings); static Builder builder(); void validate(Configuration conf); @SuppressWarnings("unchecked") static ConfigDef of(Class configClass); void save(Path path); void save(OutputStream os);  }### Answer:
@Test public void testBuildConfigDef() { ConfigDef configDef = ConfigDef.of(TestConfig.class); assertEquals(2, configDef.getGroups().size()); Iterator<ConfigKeyGroup> grpIter = configDef.getGroups().iterator(); assertTrue(grpIter.hasNext()); ConfigKeyGroup group1 = grpIter.next(); assertSame(TestConfig.group1, group1); Set<ConfigKey> keys = configDef.getSettings().get(group1.name()); assertNotNull(keys); assertEquals(1, keys.size()); assertEquals(TestConfig.key11, keys.iterator().next()); assertTrue(grpIter.hasNext()); ConfigKeyGroup group2 = grpIter.next(); assertSame(TestConfig.group2, group2); keys = configDef.getSettings().get(group2.name()); assertNotNull(keys); assertEquals(2, keys.size()); Iterator<ConfigKey> keyIter = keys.iterator(); assertEquals(TestConfig.key22, keyIter.next()); assertEquals(TestConfig.key21, keyIter.next()); assertFalse(keyIter.hasNext()); assertFalse(grpIter.hasNext()); }