### Question:
InterfaceMap { @SuppressWarnings("unchecked") public static <T> T createInstance(Class<T> interfaceClass, Map<String, Object> backingMap) { return (T) Proxy.newProxyInstance(interfaceClass.getClassLoader(), new Class[] { interfaceClass }, new BackingMapInvocationHandler(backingMap, interfaceClass)); } private  InterfaceMap(); @SuppressWarnings("unchecked") static T createInstance(Class<T> interfaceClass, Map<String, Object> backingMap); static T createInstance(Class<T> interfaceClass); static boolean isDynamicObject(Object object); static Class<?> getClass(Object dynamicObject); static Map<String, Object> getBackingMap(Object dynamicObject);  }### Answer:
@Test public void getListOfW_objects_ok() { JavaBeanProperties w1 = InterfaceMap.createInstance(JavaBeanProperties.class); setSomeValues(w1); JavaBeanProperties w2 = InterfaceMap.createInstance(JavaBeanProperties.class); setSomeOtherValues(w2); List<JavaBeanProperties> list = asList(w1, w2); map.put("listOfW", list); List<JavaBeanProperties> actual = q.getListOfW(); assertEquals(asList(w1, w2), actual); }
@Test(expected = ClassCastException.class) public void getListOfW_mixed_bad() { JavaBeanProperties w1 = InterfaceMap.createInstance(JavaBeanProperties.class); setSomeValues(w1); List<Object> list = asList(w1, "hello"); map.put("listOfW", list); List<JavaBeanProperties> listOfW = q.getListOfW(); for (JavaBeanProperties javaBeanProperties : listOfW) { } }
@Test public void equals_equal_returnsTrue() { setSomeValues(q); setSomeOtherValues(q); PossibleProperties other = InterfaceMap.createInstance(PossibleProperties.class, new HashMap<String, Object>(map)); assertEquals(q, other); assertEquals(other, q); }
@Test public void equals_notEqual_returnsFalse() { setSomeValues(q); PossibleProperties other = InterfaceMap.createInstance(PossibleProperties.class, new HashMap<String, Object>(map)); setSomeOtherValues(other); assertFalse(q.equals(other)); assertFalse(other.equals(q)); }
@Test public void equals_sameStateDifferentTypes_returnsFalse() { JavaBeanProperties other = InterfaceMap.createInstance(JavaBeanProperties.class, new HashMap<String, Object>(map)); assertFalse(q.equals(other)); assertFalse(other.equals(q)); setSomeValues(q); setSomeValues(other); assertFalse(q.equals(other)); assertFalse(other.equals(q)); }