@Test public void testComplexArrayValuesMixed() throws Exception { TestInterface[] variants = new TestInterface[10]; for (int i = 0; i < variants.length; ++i) { if (i % 2 == 0) { variants[i] = TestVariantCreate.create("create-variant-" + i, i + 5, "vary-" + i); } else { variants[i] = TestVariantBuilder.builder().testEnum(TestEnum.values()[i % TestEnum.values().length]) .intClass(i).variantBuilderName("builder-variant-" + i).build(); } } ComplexArrayClassVariant expected = ComplexArrayClassVariant.builder().variantName("large-complex") .tests(variants).build(); BuilderDynaBean builderDynaBean = new BuilderDynaBean(ComplexArrayClassVariant.class, convertUtilsBean); utilsBean.setProperty(builderDynaBean, "variantName", expected.variantName); for (int i = 0; i < variants.length; ++i) { String prefix = "tests[" + i + "]."; TestInterface variant = variants[i]; if (variant instanceof TestVariantCreate) { TestVariantCreate create = (TestVariantCreate) variant; utilsBean.setProperty(builderDynaBean, prefix + "class", create.getClass().getName()); utilsBean.setProperty(builderDynaBean, prefix + "[0]", create.variantCreateName); utilsBean.setProperty(builderDynaBean, prefix + "[1]", create.longClass); utilsBean.setProperty(builderDynaBean, prefix + "[2]", create.varyString); } else if (variant instanceof TestVariantBuilder) { TestVariantBuilder builder = (TestVariantBuilder) variant; utilsBean.setProperty(builderDynaBean, prefix + "class", builder.getClass().getName()); utilsBean.setProperty(builderDynaBean, prefix + "variantBuilderName", builder.variantBuilderName); utilsBean.setProperty(builderDynaBean, prefix + "intClass", builder.intClass); utilsBean.setProperty(builderDynaBean, prefix + "testEnum", builder.testEnum); } else { fail("Unknown variant " + variants[i].getClass().getName()); } } ComplexArrayClassVariant actual = builderDynaBean.build(ComplexArrayClassVariant.class); assertThat(actual, equalTo(expected)); }
@SafeVarargs public final <T> T build(Class<T> expected, Function<Object, Object>... additionalMutators) { if (emptyPropertyResolved != null) { validatedExpectedClass(emptyPropertyResolved.getClass(), expected); return expected.cast(emptyPropertyResolved); } if (dynaBeanBuilderSupport == null && dynaBeanCreateSupport == null) { return null; } validatedExpectedClass(destinedClass, expected); if (dynaBeanBuilderSupport.isValid()) { return expected.cast(dynaBeanBuilderSupport.build(additionalMutators)); } else { return expected.cast(dynaBeanCreateSupport.build()); } }
BuilderDynaBean implements DynaBean { @SafeVarargs public final <T> T build(Class<T> expected, Function<Object, Object>... additionalMutators) { if (emptyPropertyResolved != null) { validatedExpectedClass(emptyPropertyResolved.getClass(), expected); return expected.cast(emptyPropertyResolved); } if (dynaBeanBuilderSupport == null && dynaBeanCreateSupport == null) { return null; } validatedExpectedClass(destinedClass, expected); if (dynaBeanBuilderSupport.isValid()) { return expected.cast(dynaBeanBuilderSupport.build(additionalMutators)); } else { return expected.cast(dynaBeanCreateSupport.build()); } } }
BuilderDynaBean implements DynaBean { @SafeVarargs public final <T> T build(Class<T> expected, Function<Object, Object>... additionalMutators) { if (emptyPropertyResolved != null) { validatedExpectedClass(emptyPropertyResolved.getClass(), expected); return expected.cast(emptyPropertyResolved); } if (dynaBeanBuilderSupport == null && dynaBeanCreateSupport == null) { return null; } validatedExpectedClass(destinedClass, expected); if (dynaBeanBuilderSupport.isValid()) { return expected.cast(dynaBeanBuilderSupport.build(additionalMutators)); } else { return expected.cast(dynaBeanCreateSupport.build()); } } BuilderDynaBean(Class<?> destinedClass, ConvertUtilsBean convertUtilsBean, String... classPrefixSearchList);  BuilderDynaBean(Class<?> destinedClass, ConvertUtilsBean convertUtilsBean,
            Function<String, ?> emptyPropertyHandler, String... classPrefixSearchList);  BuilderDynaBean(Class<?> destinedClass, ConvertUtilsBean convertUtilsBean,
            Function<String, ?> emtpyPropertyHandler, List<String> classPrefixSearchList); }
BuilderDynaBean implements DynaBean { @SafeVarargs public final <T> T build(Class<T> expected, Function<Object, Object>... additionalMutators) { if (emptyPropertyResolved != null) { validatedExpectedClass(emptyPropertyResolved.getClass(), expected); return expected.cast(emptyPropertyResolved); } if (dynaBeanBuilderSupport == null && dynaBeanCreateSupport == null) { return null; } validatedExpectedClass(destinedClass, expected); if (dynaBeanBuilderSupport.isValid()) { return expected.cast(dynaBeanBuilderSupport.build(additionalMutators)); } else { return expected.cast(dynaBeanCreateSupport.build()); } } BuilderDynaBean(Class<?> destinedClass, ConvertUtilsBean convertUtilsBean, String... classPrefixSearchList);  BuilderDynaBean(Class<?> destinedClass, ConvertUtilsBean convertUtilsBean,
            Function<String, ?> emptyPropertyHandler, String... classPrefixSearchList);  BuilderDynaBean(Class<?> destinedClass, ConvertUtilsBean convertUtilsBean,
            Function<String, ?> emtpyPropertyHandler, List<String> classPrefixSearchList); boolean canBuildOrCreate(); @SafeVarargs final T build(Class<T> expected, Function<Object, Object>... additionalMutators); @Override boolean contains(String name, String key); @Override Object get(String name); @Override Object get(String name, int index); @Override Object get(String name, String key); @Override DynaClass getDynaClass(); @Override void remove(String name, String key); @Override void set(String name, Object value); @Override void set(String name, int index, Object value); @Override void set(String name, String key, Object value); }
BuilderDynaBean implements DynaBean { @SafeVarargs public final <T> T build(Class<T> expected, Function<Object, Object>... additionalMutators) { if (emptyPropertyResolved != null) { validatedExpectedClass(emptyPropertyResolved.getClass(), expected); return expected.cast(emptyPropertyResolved); } if (dynaBeanBuilderSupport == null && dynaBeanCreateSupport == null) { return null; } validatedExpectedClass(destinedClass, expected); if (dynaBeanBuilderSupport.isValid()) { return expected.cast(dynaBeanBuilderSupport.build(additionalMutators)); } else { return expected.cast(dynaBeanCreateSupport.build()); } } BuilderDynaBean(Class<?> destinedClass, ConvertUtilsBean convertUtilsBean, String... classPrefixSearchList);  BuilderDynaBean(Class<?> destinedClass, ConvertUtilsBean convertUtilsBean,
            Function<String, ?> emptyPropertyHandler, String... classPrefixSearchList);  BuilderDynaBean(Class<?> destinedClass, ConvertUtilsBean convertUtilsBean,
            Function<String, ?> emtpyPropertyHandler, List<String> classPrefixSearchList); boolean canBuildOrCreate(); @SafeVarargs final T build(Class<T> expected, Function<Object, Object>... additionalMutators); @Override boolean contains(String name, String key); @Override Object get(String name); @Override Object get(String name, int index); @Override Object get(String name, String key); @Override DynaClass getDynaClass(); @Override void remove(String name, String key); @Override void set(String name, Object value); @Override void set(String name, int index, Object value); @Override void set(String name, String key, Object value);  }