ScenarioBeanUtil { public static ScenarioBeanWrapper<?> navigateToObject(Object rootObject, List<String> steps) { return navigateToObject(rootObject, steps, true); } 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 navigateToObjectNoStepCreationTest() { Dispute dispute = new Dispute(); List<String> pathToProperty = Arrays.asList("creator", "firstName"); String message = "Impossible to reach field firstName because a step is not instantiated"; assertThatThrownBy(() -> ScenarioBeanUtil.navigateToObject(dispute, pathToProperty, false)) .isInstanceOf(ScenarioException.class) .hasMessage(message); }
@Test public void navigateToObjectTest() { Dispute dispute = new Dispute(); Person creator = new Person(); creator.setFirstName(FIRST_NAME); dispute.setCreator(creator); List<String> pathToProperty = Arrays.asList("creator", "firstName"); ScenarioBeanWrapper<?> scenarioBeanWrapper = ScenarioBeanUtil.navigateToObject(dispute, pathToProperty, true); Object targetObject = scenarioBeanWrapper.getBean(); assertEquals(targetObject, FIRST_NAME); assertNull(ScenarioBeanUtil.navigateToObject(null, Collections.emptyList()).getBean()); }
@Test public void navigateToObjectFakeFieldTest() { Dispute dispute = new Dispute(); List<String> pathToProperty = singletonList("fakeField"); String message = "Impossible to find field with name 'fakeField' in class " + Dispute.class.getCanonicalName(); assertThatThrownBy(() -> ScenarioBeanUtil.navigateToObject(dispute, pathToProperty, true)) .isInstanceOf(ScenarioException.class) .hasMessage(message); }