### Question:
AssociatedManagedConnectionFactoryImpl extends ManagedConnectionFactoryImpl implements ResourceAdapterAssociation { public void setResourceAdapter(ResourceAdapter aRA) throws ResourceException { LOG.info("Associate Resource Adapter with ManagedConnectionFactory by appserver. ra = " + ra); if (!(aRA instanceof ResourceAdapterImpl)) { throw new ResourceAdapterInternalException( "ResourceAdapter is not correct, it should be instance of ResourceAdapterImpl"); } this.ra = aRA; mergeResourceAdapterProps(); } AssociatedManagedConnectionFactoryImpl();  AssociatedManagedConnectionFactoryImpl(Properties props); Object createConnectionFactory(ConnectionManager connMgr); void setResourceAdapter(ResourceAdapter aRA); ResourceAdapter getResourceAdapter(); int hashCode(); boolean equals(Object o);  }### Answer:
@Test public void testMergeNonDuplicateResourceAdapterProps() throws ResourceException { Properties props = new Properties(); props.setProperty("key1", "value1"); ResourceAdapterImpl rai = new ResourceAdapterImpl(props); TestableAssociatedManagedConnectionFactoryImpl mci = new TestableAssociatedManagedConnectionFactoryImpl(); assertEquals("before associate, one props", 0, mci.getPluginProps().size()); assertFalse("before associate, key1 not set", mci.getPluginProps().containsKey("key1")); mci.setResourceAdapter(rai); assertEquals("after associate, two props", 1, mci.getPluginProps().size()); assertTrue("after associate, key1 is set", mci.getPluginProps().containsKey("key1")); }
@Test public void testSetResourceAdapter() throws Exception { TestableAssociatedManagedConnectionFactoryImpl mci = new TestableAssociatedManagedConnectionFactoryImpl(); ResourceAdapterImpl rai = new ResourceAdapterImpl(); mci.setResourceAdapter(rai); assertEquals("ResourceAdapter is set", mci.getResourceAdapter(), rai); }
@Test public void testSetWrongResourceAdapterThrowException() throws Exception { TestableAssociatedManagedConnectionFactoryImpl mci = new TestableAssociatedManagedConnectionFactoryImpl(); ResourceAdapter rai = EasyMock.createMock(ResourceAdapter.class); try { mci.setResourceAdapter(rai); fail("exception expected"); } catch (ResourceException re) { assertTrue("wrong ResourceAdapter set", re.getMessage().indexOf("ResourceAdapterImpl") != -1); } }
@Test public void testMergeNonDuplicateResourceAdapterProps() throws ResourceException { Properties props = new Properties(); props.setProperty("key1", "value1"); ResourceAdapterImpl rai = new ResourceAdapterImpl(props); TestableAssociatedManagedConnectionFactoryImpl mci = new TestableAssociatedManagedConnectionFactoryImpl(); assertEquals("before associate, one props", 0, mci.getPluginProps().size()); assertTrue("before associate, key1 not set", !mci.getPluginProps().containsKey("key1")); mci.setResourceAdapter(rai); assertEquals("after associate, two props", 1, mci.getPluginProps().size()); assertTrue("after associate, key1 is set", mci.getPluginProps().containsKey("key1")); }