### Question:
LoginWithPasswordCredentials extends CacheLoader<Credentials, LoginResponse> { @Override public LoginResponse load(Credentials input) { String username = input.identity; String domain = ""; if (username.indexOf('/') != -1) { domain = username.substring(0, username.lastIndexOf('/')); username = username.substring(username.lastIndexOf('/') + 1, username.length()); } String hashedPassword = base16().lowerCase().encode(md5().hashString(input.credential, UTF_8).asBytes()); return client.loginUserInDomainWithHashOfPassword(username, domain, hashedPassword); } @Inject  LoginWithPasswordCredentials(SessionApi client); @Override LoginResponse load(Credentials input); @Override String toString();  }### Answer:
@Test public void testWithDoubleDomainname() { LoginResponse response = createMock(LoginResponse.class); SessionApi client = createMock(SessionApi.class); expect(client.loginUserInDomainWithHashOfPassword(eq("User"), eq("Test/Domain"), (String) anyObject())).andReturn(response); replay(client); LoginWithPasswordCredentials obj = new LoginWithPasswordCredentials(client); Credentials cred = new Credentials("Test/Domain/User", "koffiedik"); obj.load(cred); }
@Test public void testWithSingleDomainname() { LoginResponse response = createMock(LoginResponse.class); SessionApi client = createMock(SessionApi.class); expect(client.loginUserInDomainWithHashOfPassword(eq("User"), eq("Domain"), (String) anyObject())).andReturn(response); replay(client); LoginWithPasswordCredentials obj = new LoginWithPasswordCredentials(client); Credentials cred = new Credentials("Domain/User", "koffiedik"); obj.load(cred); }
@Test public void testWithNoDomainname() { LoginResponse response = createMock(LoginResponse.class); SessionApi client = createMock(SessionApi.class); expect(client.loginUserInDomainWithHashOfPassword(eq("User"), eq(""), (String) anyObject())).andReturn(response); replay(client); LoginWithPasswordCredentials obj = new LoginWithPasswordCredentials(client); Credentials cred = new Credentials("User", "koffiedik"); obj.load(cred); }