ConfigInstanceUtil { public static <T extends ConfigInstance> T getNewInstance(Class<T> type, String configId, ConfigPayload payload) { T instance; try { ConfigTransformer<?> transformer = new ConfigTransformer<>(type); ConfigInstance.Builder instanceBuilder = transformer.toConfigBuilder(payload); Constructor<T> constructor = type.getConstructor(instanceBuilder.getClass()); instance = constructor.newInstance(instanceBuilder); ConfigInstance i = instance; i.postInitialize(configId); setConfigId(i, configId); } catch (InstantiationException | InvocationTargetException | NoSuchMethodException | NoSuchFieldException | IllegalAccessException e) { throw new IllegalArgumentException("Failed creating new instance of '" + type.getCanonicalName() + "' for config id '" + configId + "'", e); } return instance; }  static void setValues(BUILDER destination, BUILDER source); static T getNewInstance(Class<T> type, String configId, ConfigPayload payload); static Object getField(ConfigBuilder builder, String fieldName);  }
@Test public void testGetNewInstanceErrorMessage() { ConfigPayloadBuilder payloadBuilder = new ConfigPayloadBuilder(); try { ConfigInstanceUtil.getNewInstance(TestNodefsConfig.class, "id0", ConfigPayload.fromBuilder(payloadBuilder)); assert(false); } catch (IllegalArgumentException e) { assertEquals("Failed creating new instance of 'com.yahoo.foo.TestNodefsConfig' for config id 'id0'", e.getMessage()); } }