ScenarioBeanUtil { public static String revertValue(Object cleanValue) { if (cleanValue == null) { return "null"; } Class<?> clazz = cleanValue.getClass(); if (clazz.isAssignableFrom(String.class)) { return String.valueOf(cleanValue); } else if (clazz.isAssignableFrom(Boolean.class) || clazz.isAssignableFrom(boolean.class)) { return Boolean.toString((Boolean) cleanValue); } else if (clazz.isAssignableFrom(Integer.class) || clazz.isAssignableFrom(int.class)) { return Integer.toString((Integer) cleanValue); } else if (clazz.isAssignableFrom(Long.class) || clazz.isAssignableFrom(long.class)) { return Long.toString((Long) cleanValue); } else if (clazz.isAssignableFrom(Double.class) || clazz.isAssignableFrom(double.class)) { return revertDouble((Double) cleanValue); } else if (clazz.isAssignableFrom(Float.class) || clazz.isAssignableFrom(float.class)) { return cleanValue + "f"; } else if (clazz.isAssignableFrom(Character.class) || clazz.isAssignableFrom(char.class)) { return String.valueOf(cleanValue); } else if (clazz.isAssignableFrom(Byte.class) || clazz.isAssignableFrom(byte.class)) { return String.valueOf(cleanValue); } else if (clazz.isAssignableFrom(Short.class) || clazz.isAssignableFrom(short.class)) { return String.valueOf(cleanValue); } else if (clazz.isAssignableFrom(LocalDate.class)) { LocalDate localDate = (LocalDate) cleanValue; return String.format("%04d-%02d-%02d", localDate.getYear(), localDate.getMonthValue(), localDate.getDayOfMonth()); } else if (Enum.class.isAssignableFrom(clazz)) { return String.valueOf(cleanValue); } else { return String.valueOf(cleanValue); } } 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 revertValueTest() { assertEquals("Test", revertValue("Test")); assertEquals("false", revertValue(false)); assertEquals("true", revertValue(Boolean.TRUE)); assertEquals("1", revertValue(1)); assertEquals("1", revertValue(1L)); assertEquals("1.0d", revertValue(1.0d)); assertEquals("NaN", revertValue(Double.NaN)); assertEquals("Infinity", revertValue(Double.POSITIVE_INFINITY)); assertEquals("-Infinity", revertValue(Double.NEGATIVE_INFINITY)); assertEquals("1.0f", revertValue(1.0f)); assertEquals("a", revertValue('a')); assertEquals("1", revertValue((short) 1)); assertEquals(String.valueOf("0".getBytes()[0]), revertValue("0".getBytes()[0])); assertEquals("null", revertValue(null)); assertEquals("2018-10-20", revertValue(LocalDate.of(2018, 10, 20))); assertEquals("FIRST", revertValue(EnumTest.FIRST)); }