### Question:
ConnectionServiceImpl extends PentahoBase implements IConnectionService { public boolean addConnection( IDatabaseConnection connection ) throws ConnectionServiceException { ensureDataAccessPermission(); try { if ( connection.getAccessType() != null && connection.getAccessType().equals( DatabaseAccessType.JNDI ) ) { IPentahoConnection pentahoConnection = null; pentahoConnection = PentahoConnectionFactory .getConnection( IPentahoConnection.SQL_DATASOURCE, connection.getDatabaseName(), null, this ); try { connection.setUsername( ( ( (SQLConnection) pentahoConnection ).getNativeConnection().getMetaData().getUserName() ) ); } catch ( Exception e ) { logger.warn( "Unable to get username from datasource: " + connection.getName() ); } } datasourceMgmtSvc.createDatasource( connection ); return true; } catch ( DuplicateDatasourceException duplicateDatasourceException ) { String message = Messages.getErrorString( "ConnectionServiceImpl.ERROR_0004_UNABLE_TO_ADD_CONNECTION", connection.getName(), duplicateDatasourceException.getLocalizedMessage() ); logger.error( message ); throw new ConnectionServiceException( Response.SC_CONFLICT, message, duplicateDatasourceException ); } catch ( Exception e ) { String message = Messages.getErrorString( "ConnectionServiceImpl.ERROR_0004_UNABLE_TO_ADD_CONNECTION", connection.getName(), e.getLocalizedMessage() ); logger.error( message ); throw new ConnectionServiceException( message, e ); } } ConnectionServiceImpl(); Log getLogger(); boolean hasDataAccessPermission(); void ensureDataAccessPermission(); List<IDatabaseConnection> getConnections(); List<IDatabaseConnection> getConnections( boolean hidePassword ); IDatabaseConnection getConnectionByName( String name ); IDatabaseConnection getConnectionByName( String name, boolean doUnsanitize ); IDatabaseConnection getConnectionById( String id ); 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 testAddConnection() throws Exception { doNothing().when( connectionServiceImpl ).ensureDataAccessPermission(); doReturn( DatabaseAccessType.NATIVE ).when( mockDBConnection ).getAccessType(); assertTrue( connectionServiceImpl.addConnection( mockDBConnection ) ); doReturn( DatabaseAccessType.JNDI ).when( mockDBConnection ).getAccessType(); assertTrue( connectionServiceImpl.addConnection( mockDBConnection ) ); verify( mockDBConnection ).setUsername( anyString() ); }