### Question:
ValueConverterRegistry { @SuppressWarnings("unchecked") public static <K, V> Object convert(Class<V> valueClazz, Class<K> keyClazz, CValue value) throws ConstrettoException { if (value instanceof CPrimitive) { return convertPrimitive(valueClazz, (CPrimitive) value); } else if (value instanceof CArray) { return convertList(valueClazz, (CArray) value); } else if (value instanceof CObject) { return convertMap(keyClazz, valueClazz, (CObject) value); } else { throw new ConstrettoException("invalid datatype, parsing haz failed"); } }  static void registerCustomConverter(Class<?> converterFor, ValueConverter<?> converter); @SuppressWarnings("unchecked") static Object convert(Class<V> valueClazz, Class<K> keyClazz, CValue value); @SuppressWarnings("unchecked") static List<T> convertList(Class<T> clazz, CArray list); @SuppressWarnings("unchecked") static T convertPrimitive(Class<T> clazz, CPrimitive value); @SuppressWarnings("unchecked") static Map<K, V> convertMap(Class<K> keyClazz, Class<V> valueClazz, CObject value); static T convertEnum(Class<T> clazz, String value);  }### Answer:
@SuppressWarnings("unchecked") @Test public void simpleListConversion() { final List<CValue> list = new ArrayList<CValue>(); list.add(new CPrimitive("hei")); final List<String> convertedList = (List<String>) ValueConverterRegistry.convert(String.class, String.class, new CArray(list)); Assert.assertNotNull(convertedList); Assert.assertTrue(convertedList.size() == 1); }
@SuppressWarnings("unchecked") @Test public void simpleMapConversion() { final Map<String, CValue> map = new HashMap<String, CValue>(); map.put("hei", new CPrimitive("hallo")); final Map<String,String> convertedMap = (Map<String,String>) ValueConverterRegistry.convert(String.class, String.class, new CObject(map)); Assert.assertNotNull(convertedMap); Assert.assertTrue(convertedMap.size() == 1); }
@Test public void mapListConversion() { final List<CValue> list = new ArrayList<CValue>(); final Map<String, CValue> data = new HashMap<String, CValue>(); data.put("key", new CPrimitive("value")); list.add(new CObject(data)); final List<Map<String, String>> convertedList = (List<Map<String, String>>) ValueConverterRegistry.convert(String.class, String.class, new CArray(list)); Assert.assertNotNull(convertedList); Assert.assertTrue(convertedList.size() == 1); final Map<String, String> element = convertedList.get(0); Assert.assertTrue(element.size() == 1); Assert.assertEquals("value", element.get("key")); }
@Test(expected = ConstrettoException.class) public void testIllegalDataTypeConversion() throws Exception { ValueConverterRegistry.convert(String.class, String.class, new CValue() { @Override public Set<String> referencedKeys() { return null; } @Override public void replace(final String key, final String resolvedValue) { } }); }
@Test(expected = ConstrettoException.class) public void testConvertUnsopportedClassConversion() { final Map<String, CValue> map = new HashMap<String, CValue>(); map.put("hei", new CPrimitive("hallo")); ValueConverterRegistry.convert(getClass(), getClass(), new CObject(map)); }