### Question:
InMemoryConnectionServiceImpl implements IConnectionService { public IDatabaseConnection getConnectionByName( String name ) throws ConnectionServiceException { for ( IDatabaseConnection connection : connectionList ) { if ( connection.getName().equals( name ) ) { return connection; } } logger.error( Messages.getErrorString( "ConnectionServiceInMemoryDelegate.ERROR_0003_UNABLE_TO_GET_CONNECTION", name, null ) ); throw new ConnectionServiceException( Messages.getErrorString( "ConnectionServiceInMemoryDelegate.ERROR_0003_UNABLE_TO_GET_CONNECTION", name, null ) ); } InMemoryConnectionServiceImpl(); List<IDatabaseConnection> getConnections(); IDatabaseConnection getConnectionByName( String name ); boolean addConnection( IDatabaseConnection connection ); boolean updateConnection( IDatabaseConnection connection ); boolean deleteConnection( IDatabaseConnection connection ); boolean deleteConnection( String name ); boolean testConnection( IDatabaseConnection connection ); boolean isConnectionExist( String connectionName );  }### Answer:
@Test public void testGetConnectionByName() { try { InMemoryConnectionServiceImpl serv = new InMemoryConnectionServiceImpl(); List<IDatabaseConnection> conns = serv.getConnections(); assertTrue( conns != null && conns.size() == 0 ); IDatabaseConnection connection = new DatabaseConnection(); connection.setName( "Connection 1" ); serv.addConnection( connection ); connection = new DatabaseConnection(); connection.setName( "Connection 2" ); serv.addConnection( connection ); connection = serv.getConnectionByName( "Connection 2" ); assertTrue( connection != null && connection.getName().equals( "Connection 2" ) ); try { connection = serv.getConnectionByName( "Connection 5" ); fail(); } catch ( Exception ex ) { } } catch ( Exception ex ) { fail(); } }