### Question:
DBCPConnectionPoolLookup extends AbstractControllerService implements DBCPService { @Override public Connection getConnection() throws ProcessException { throw new UnsupportedOperationException("Cannot lookup DBCPConnectionPool without attributes"); }  @OnEnabled void onEnabled(final ConfigurationContext context); @OnDisabled void onDisabled(); @Override Connection getConnection(); @Override Connection getConnection(Map<String, String> attributes); static final String DATABASE_NAME_ATTRIBUTE; }### Answer:
@Test public void testLookupServiceA() { final Map<String,String> attributes = new HashMap<>(); attributes.put(DBCPConnectionPoolLookup.DATABASE_NAME_ATTRIBUTE, "a"); final Connection connection = dbcpLookupService.getConnection(attributes); assertNotNull(connection); assertTrue(connection instanceof MockConnection); final MockConnection mockConnection = (MockConnection)connection; assertEquals(connectionA.getName(), mockConnection.getName()); }
@Test public void testLookupServiceB() { final Map<String,String> attributes = new HashMap<>(); attributes.put(DBCPConnectionPoolLookup.DATABASE_NAME_ATTRIBUTE, "b"); final Connection connection = dbcpLookupService.getConnection(attributes); assertNotNull(connection); assertTrue(connection instanceof MockConnection); final MockConnection mockConnection = (MockConnection)connection; assertEquals(connectionB.getName(), mockConnection.getName()); }
@Test(expected = UnsupportedOperationException.class) public void testLookupWithoutAttributes() { dbcpLookupService.getConnection(); }
@Test(expected = ProcessException.class) public void testLookupMissingDatabaseNameAttribute() { final Map<String,String> attributes = new HashMap<>(); dbcpLookupService.getConnection(attributes); }
@Test(expected = ProcessException.class) public void testLookupWithDatabaseNameThatDoesNotExist() { final Map<String,String> attributes = new HashMap<>(); attributes.put(DBCPConnectionPoolLookup.DATABASE_NAME_ATTRIBUTE, "DOES-NOT-EXIST"); dbcpLookupService.getConnection(attributes); }