Deserializer { public Resource createObjectFromString(String resourceName) throws InstantiationException, IllegalAccessException, NotExtendingResourceException { Class objectClass = registeredClasses.get(resourceName); try { return (Resource) objectClass.newInstance(); } catch (InstantiationException e) { throw e; } catch(IllegalAccessException e) { throw e; } catch (ClassCastException e) { throw new NotExtendingResourceException(objectClass + " is not inheriting Resource"); } }  static void registerResourceClass(String typeName, Class resourceClass); Resource createObjectFromString(String resourceName); Resource setField(Resource resourceObject, String fieldName, Object data); Resource setIdField(Resource resourceObject, Object data); static HashMap<String, Class> getRegisteredClasses(); static void setRegisteredClasses(HashMap<String, Class> registeredClasses);  }
@Test public void testCreateObjectFromString() throws Exception { HashMap<String, Class> mockMap = mock(HashMap.class); when(mockMap.get("articles")).thenReturn(Article.class); Deserializer.setRegisteredClasses(mockMap); Deserializer deserializer = new Deserializer(); Resource resource = deserializer.createObjectFromString("articles"); assertNotNull(resource); assertEquals(resource.getClass(), Article.class); }