### Question:
JNDIReferenceFactory implements ObjectFactory { @Override public Object getObjectInstance(Object object, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception { Object result = null; if (object instanceof Reference) { Reference reference = (Reference) object; Class<?> theClass = loadClass(this, reference.getClassName()); if (JNDIStorable.class.isAssignableFrom(theClass)) { JNDIStorable store = (JNDIStorable) theClass.getDeclaredConstructor().newInstance(); Map<String, String> properties = new HashMap<String, String>(); for (Enumeration<RefAddr> iter = reference.getAll(); iter.hasMoreElements();) { StringRefAddr addr = (StringRefAddr) iter.nextElement(); properties.put(addr.getType(), (addr.getContent() == null) ? "" : addr.getContent().toString()); } store.setProperties(properties); result = store; } } else { throw new RuntimeException("Object " + object + " is not a reference"); } return result; }  @Override Object getObjectInstance(Object object, Name name, Context nameCtx, Hashtable<?, ?> environment); static Reference createReference(String instanceClassName, JNDIStorable po); static Class<?> loadClass(Object thisObj, String className);  }### Answer:
@Test public void testGetObjectInstanceCreatesJmsConnectionFactory() throws Exception { Reference reference = createTestReference(JmsConnectionFactory.class.getName(), REMOTE_URI_NAME_PROP, TEST_CONNECTION_URL); Object connFactory = referenceFactory.getObjectInstance(reference, mockName, mockContext, testEnvironment); assertNotNull("Expected object to be created", connFactory); assertEquals("Unexpected object type created", JmsConnectionFactory.class, connFactory.getClass()); assertEquals("Unexpected URI", TEST_CONNECTION_URL, ((JmsConnectionFactory) connFactory).getRemoteURI()); }
@Test public void testGetObjectInstanceWithUnknownClassName() throws Exception { Reference reference = createTestReference(Object.class.getName(), "redundant", "redundant"); Object factory = referenceFactory.getObjectInstance(reference, mockName, mockContext, testEnvironment); assertNull("Expected null when given unknown class name", factory); }