SimpleCredentialsFactoryBean implements FactoryBean<SimpleCredentials> { @Override public SimpleCredentials getObject() throws Exception { if (simpleCredentials == null) { simpleCredentials = new SimpleCredentials(userID, password.toCharArray()); } return simpleCredentials; }  @Override SimpleCredentials getObject(); @Override Class<?> getObjectType(); @Override boolean isSingleton(); void setUserID(String userID); void setPassword(String password);  }
@Test public void testGetObject() throws Exception { SimpleCredentialsFactoryBean factoryBean = new SimpleCredentialsFactoryBean(); factoryBean.setUserID("testuser"); factoryBean.setPassword("secret"); SimpleCredentials sc = factoryBean.getObject(); assertNotNull(sc); assertEquals(factoryBean.getObjectType(), sc.getClass()); assertEquals("testuser", sc.getUserID()); assertEquals("secret", new String(sc.getPassword())); }