ScenarioBeanUtil { public static <T> T fillBean(String className, Map<List<String>, Object> params, ClassLoader classLoader) { return fillBean(errorEmptyMessage(), className, params, classLoader); } private  ScenarioBeanUtil(); static T fillBean(String className, Map<List<String>, Object> params, ClassLoader classLoader); @SuppressWarnings("unchecked") static T fillBean(ValueWrapper<Object> initialInstance, String className, Map<List<String>, Object> params, ClassLoader classLoader); static ScenarioBeanWrapper<?> navigateToObject(Object rootObject, List<String> steps); static ScenarioBeanWrapper<?> navigateToObject(Object rootObject, List<String> steps, boolean createIfNull); static Object convertValue(String className, Object cleanValue, ClassLoader classLoader); static String revertValue(Object cleanValue); @SuppressWarnings("unchecked") static Class<T> loadClass(String className, ClassLoader classLoader); static Field getField(Class<?> clazz, String fieldName);  }
@Test public void fillBeanTest() { Map<List<String>, Object> paramsToSet = new HashMap<>(); paramsToSet.put(Arrays.asList("creator", "firstName"), FIRST_NAME); paramsToSet.put(Arrays.asList("creator", "age"), AGE); Object result = ScenarioBeanUtil.fillBean(errorEmptyMessage(), Dispute.class.getCanonicalName(), paramsToSet, classLoader); assertTrue(result instanceof Dispute); Dispute dispute = (Dispute) result; assertEquals(dispute.getCreator().getFirstName(), FIRST_NAME); assertEquals(dispute.getCreator().getAge(), AGE); }
@Test public void fillBeanTestWithInitialInstanceTest() { Dispute dispute = new Dispute(); Map<List<String>, Object> paramsToSet = new HashMap<>(); paramsToSet.put(Arrays.asList("creator", "firstName"), FIRST_NAME); paramsToSet.put(Arrays.asList("creator", "age"), AGE); Object result = ScenarioBeanUtil.fillBean(of(dispute), Dispute.class.getCanonicalName(), paramsToSet, classLoader); assertTrue(result instanceof Dispute); assertSame(dispute, result); assertEquals(dispute.getCreator().getFirstName(), FIRST_NAME); assertEquals(dispute.getCreator().getAge(), AGE); }
@Test(expected = ScenarioException.class) public void fillBeanLoadClassTest() { ScenarioBeanUtil.fillBean(errorEmptyMessage(), "FakeCanonicalName", new HashMap<>(), classLoader); }
@Test(expected = ScenarioException.class) public void fillBeanFailNotEmptyConstructorTest() { Map<List<String>, Object> paramsToSet = new HashMap<>(); paramsToSet.put(singletonList("name"), null); ScenarioBeanUtil.fillBean(errorEmptyMessage(), NotEmptyConstructor.class.getCanonicalName(), paramsToSet, classLoader); }
@Test(expected = ScenarioException.class) public void fillBeanFailTest() { Map<List<String>, Object> paramsToSet = new HashMap<>(); paramsToSet.put(singletonList("fakeField"), null); ScenarioBeanUtil.fillBean(errorEmptyMessage(), Dispute.class.getCanonicalName(), paramsToSet, classLoader); }
@Test(expected = ScenarioException.class) public void fillBeanFailNullClassTest() { Map<List<String>, Object> paramsToSet = new HashMap<>(); paramsToSet.put(singletonList("fakeField"), null); ScenarioBeanUtil.fillBean(errorEmptyMessage(), null, paramsToSet, classLoader); }
@Test(expected = ScenarioException.class) public void fillBeanFailWrongTypeTest() { Map<List<String>, Object> paramsToSet = new HashMap<>(); paramsToSet.put(singletonList("description"), new ArrayList<>()); ScenarioBeanUtil.fillBean(errorEmptyMessage(), Dispute.class.getCanonicalName(), paramsToSet, classLoader); }
@Test public void fillBeanEmptyValueTest() { Map<List<String>, Object> paramsToSet = new HashMap<>(); paramsToSet.put(emptyList(), null); assertNull(ScenarioBeanUtil.fillBean(of(null), String.class.getCanonicalName(), paramsToSet, classLoader)); }