### Question:
InMemoryRealm extends RealmBase { @Override public Principal authenticate(String username, String credentials) { GenericPrincipal principal = principals.get(username); boolean validated = principal != null && getCredentialHandler().matches(credentials, principal.getPassword()); return validated ? principal : null; }  @Override Principal authenticate(String username, String credentials);  }### Answer:
@Test public void testAuthenticate() throws Exception { InMemoryRealm realm = new InMemoryRealm(); StandardContext ctx = new StandardContext(); ctx.setName("OryxTest"); realm.setContainer(ctx); realm.start(); realm.addUser("foo", "bar"); Principal authPrincipal = realm.authenticate("foo", "bar"); assertNotNull(authPrincipal); assertEquals("foo", authPrincipal.getName()); assertNull(realm.authenticate("foo", "baz")); assertNull(realm.authenticate("bar", "foo")); assertEquals("bar", realm.getPassword("foo")); assertEquals("foo", realm.getPrincipal("foo").getName()); }