PasswordServiceFactory { public static synchronized void init( String classname ) { try { currentService = (IPasswordService) Class.forName( classname ).newInstance(); } catch ( Throwable e ) { throw new RuntimeException( e ); } }  static synchronized void init( String classname ); static IPasswordService getPasswordService();  }
@Test public void testInit() throws Exception { PasswordServiceFactory.init( "org.pentaho.platform.util.Base64PasswordService" ); assertTrue( PasswordServiceFactory.getPasswordService() instanceof Base64PasswordService ); PasswordServiceFactory.init( "org.pentaho.platform.util.KettlePasswordService" ); assertTrue( PasswordServiceFactory.getPasswordService() instanceof KettlePasswordService ); PasswordServiceFactory.init( "org.pentaho.platform.engine.security.CipherEncryptionService" ); assertTrue( PasswordServiceFactory.getPasswordService() instanceof CipherEncryptionService ); PasswordServiceFactory hack = new PasswordServiceFactory(); }
@Test ( expected = RuntimeException.class ) public void testInit_withFailure() throws Exception { PasswordServiceFactory.init( "org.pentaho.platform.util.InvalidClass" ); }