PasswordHelper { public String getPassword( String input ) { if ( input != null && input.startsWith( ENC ) ) { try { return passwordService.decrypt( input.substring( 4 ) ); } catch ( PasswordServiceException e ) { Logger.error( this, "Exception decrypting password", e ); throw new RuntimeException( e ); } } return input; } PasswordHelper();  PasswordHelper( IPasswordService passwordService ); String getPassword( String input ); String encrypt( String password );  }
@Test public void testDecryptsWhenPasswordIndicatesEncryption() throws Exception { PasswordHelper helper = new PasswordHelper( new KettlePasswordService() ); String contra = "uuddlrlrbas"; String druidia = "12345"; assertEquals( contra, helper.getPassword( "ENC:Encrypted 2be98afc86ad28780af15bc7ccc90aec9" ) ); assertEquals( druidia, helper.getPassword( druidia ) ); assertEquals( "", helper.getPassword( "" ) ); assertNull(helper.getPassword( null ) ); }