RuleScenarioRunnerHelper extends AbstractRunnerHelper { @Override protected Object createObject(ValueWrapper<Object> initialInstance, String className, Map<List<String>, Object> params, ClassLoader classLoader) { return fillBean(initialInstance, className, params, classLoader); }    }
@Test public void createObject() { Map<List<String>, Object> params = new HashMap<>(); params.put(singletonList("firstName"), "TestName"); params.put(singletonList("age"), 10); ValueWrapper<Object> initialInstance = runnerHelper.getDirectMapping(params); Object objectRaw = runnerHelper.createObject( initialInstance, Person.class.getCanonicalName(), params, this.getClass().getClassLoader()); assertTrue(objectRaw instanceof Person); Person object = (Person) objectRaw; assertEquals(10, object.getAge()); assertEquals("TestName", object.getFirstName()); }
@Test public void createObjectDirectMappingSimpleType() { Map<List<String>, Object> params = new HashMap<>(); String directMappingSimpleTypeValue = "TestName"; params.put(Collections.emptyList(), directMappingSimpleTypeValue); ValueWrapper<Object> initialInstance = runnerHelper.getDirectMapping(params); Object objectRaw = runnerHelper.createObject( initialInstance, String.class.getCanonicalName(), params, this.getClass().getClassLoader()); assertTrue(objectRaw instanceof String); assertEquals(directMappingSimpleTypeValue, objectRaw); }
@Test public void createObjectDirectMappingSimpleTypeNull() { Map<List<String>, Object> params = new HashMap<>(); params.put(emptyList(), null); ValueWrapper<Object> initialInstance = runnerHelper.getDirectMapping(params); Object objectRaw = runnerHelper.createObject( initialInstance, String.class.getCanonicalName(), params, this.getClass().getClassLoader()); assertNull(objectRaw); }
@SuppressWarnings("unchecked") @Test public void createObjectDirectMappingComplexType() { Map<List<String>, Object> params = new HashMap<>(); Person directMappingComplexTypeValue = new Person(); directMappingComplexTypeValue.setFirstName("TestName"); params.put(emptyList(), directMappingComplexTypeValue); params.put(singletonList("age"), 10); ValueWrapper<Object> initialInstance = runnerHelper.getDirectMapping(params); Object objectRaw = runnerHelper.createObject( initialInstance, Map.class.getCanonicalName(), params, this.getClass().getClassLoader()); assertTrue(objectRaw instanceof Person); Person object = (Person) objectRaw; assertEquals(10, object.getAge()); assertEquals("TestName", object.getFirstName()); }