CassandraClientJndiResourceFactory implements ObjectFactory { public Object getObjectInstance(Object object, Name jndiName, Context context, Hashtable<?, ?> environment) throws Exception { Reference resourceRef = null; if (object instanceof Reference) { resourceRef = (Reference) object; } else { throw new Exception("Object provided is not a javax.naming.Reference type"); } if ( cluster == null ) { configure(resourceRef); } return keyspace; }  Object getObjectInstance(Object object, Name jndiName, Context context,
      Hashtable<?, ?> environment);  }
@Test public void getObjectInstance() throws Exception { Reference resource = new Reference("CassandraClientFactory"); resource.add(new StringRefAddr("hosts", cassandraUrl)); resource.add(new StringRefAddr("clusterName", clusterName)); resource.add(new StringRefAddr("keyspace", "Keyspace1")); resource.add(new StringRefAddr("autoDiscoverHosts", "true")); Name jndiName = mock(Name.class); Context context = new InitialContext(); Hashtable<String, String> environment = new Hashtable<String, String>(); Keyspace keyspace = (Keyspace) factory.getObjectInstance(resource, jndiName, context, environment); assertNotNull(keyspace); assertEquals("Keyspace1",keyspace.getKeyspaceName()); }