IdentityFactory { public static UserPasswordIdentity createFromUserPassword(String user, String password) { return new UserPasswordIdentity(user,password); } private  IdentityFactory(); static TokenIdentity createFromToken(String token); static UserPasswordIdentity createFromUserPassword(String user, String password);  }
@Test public void testUserPasswordIdentity() { UserPasswordIdentity identity = IdentityFactory.createFromUserPassword("USER", "PASS"); Assert.assertThat(identity.getUsername(), equalTo("USER")); Assert.assertThat(identity.getPassword(), equalTo("PASS")); }
@Test(expected = IllegalArgumentException.class) public void testNullUserPasswordIdentityNotSupported() { IdentityFactory.createFromUserPassword(null, "PASS"); }
@Test public void testUserNullPasswordIdentity() { UserPasswordIdentity identity = IdentityFactory.createFromUserPassword("USER", null); Assert.assertThat(identity.getUsername(), equalTo("USER")); Assert.assertThat(identity.getPassword(), nullValue()); }