### Question:
ConnectionServiceHelper { public static String getConnectionPassword( String connectionName, String password ) throws ConnectionServiceException { try { IDatabaseConnection datasource = datasourceMgmtSvc.getDatasourceByName( connectionName ); if ( datasource != null && !hasPasswordChanged( password ) ) { return datasource.getPassword(); } else { return password; } } catch ( Exception e ) { logger.error( Messages.getErrorString( "ConnectionServiceHelper.ERROR_0001_UNABLE_TO_GET_CONNECTION_PASSWORD", connectionName, e.getLocalizedMessage() ) ); throw new ConnectionServiceException( Messages.getErrorString( "ConnectionServiceHelper.ERROR_0001_UNABLE_TO_GET_CONNECTION_PASSWORD", connectionName, e.getLocalizedMessage() ), e ); } }  static String getConnectionPassword( String connectionName, String password ); static String encodePassword( String password );  }### Answer:
@Test public void testGetConnectionPassword() throws Exception { String password = ConnectionServiceHelper.getConnectionPassword( VALID_CONNECTION, "password" ); assertEquals( "password", password ); verify( connection, never() ).getPassword(); }
@Test public void testGetConnectionPassword_nullPassword() throws Exception { String password = ConnectionServiceHelper.getConnectionPassword( VALID_CONNECTION, null ); assertNull( password ); }
@Test public void testGetConnectionPassword_replacePassword() throws Exception { String password = ConnectionServiceHelper.getConnectionPassword( VALID_CONNECTION, "*" ); assertNull( password ); }
@Test public void testGetConnectionPassword_emptyPassword() throws Exception { String password = ConnectionServiceHelper.getConnectionPassword( VALID_CONNECTION, "" ); assertEquals( "", password ); }
@Test public void testGetConnectionPassword_nullConnection() throws Exception { String password = ConnectionServiceHelper.getConnectionPassword( INVALID_CONNECTION, "password" ); assertEquals( "password", password ); }
@Test public void testGetConnectionPassword_nullConnectionNullPass() throws Exception { String password = ConnectionServiceHelper.getConnectionPassword( INVALID_CONNECTION, null ); assertNull( password ); }
@Test( expected = ConnectionServiceException.class ) public void testGetConnectionPassword_getErrorFromService() throws Exception { ConnectionServiceHelper.getConnectionPassword( EXCEPTION_CONNECTION, "password" ); }