### Question:
AbstractAuthenticator implements Authenticator<Principal> { @Override public Principal authenticate(Credentials credentials) { if (!validateTimestamp(credentials.getTimestamp())) { LOG.info("Invalid timestamp"); return null; } Principal principal = getPrincipal(credentials); if (principal == null) { LOG.info("Could not get principal"); return null; } String secretKey = getSecretKeyFromPrincipal(principal); if (!validateSignature(credentials, secretKey)) { LOG.info("Invalid signature"); return null; } return principal; } protected  AbstractAuthenticator(); protected  AbstractAuthenticator(long allowedTimestampSlop, TimeUnit timeUnit); @Override Principal authenticate(Credentials credentials); @Override String getApiKeyName();  }### Answer:
@Test public void respondsToExpiredFutureTimestampWithNull() { DateTime requestTime = nowInUTC().plusMinutes(1); Credentials credentials = createCredentials(API_KEY, SECRET_KEY, requestTime); String principal = authenticator.authenticate(credentials); assertNull(principal); }
@Test public void respondsToInvalidSignatureWithNull() { Credentials credentials = createCredentials(API_KEY, SECRET_KEY + "-invalid"); String principal = authenticator.authenticate(credentials); assertNull(principal); }
@Test public void respondsToValidCredentialsWithPrincipal() { Credentials credentials = createCredentials(API_KEY, SECRET_KEY); String principal = authenticator.authenticate(credentials); assertNotNull(principal); assertEquals(PRINCIPAL, principal); }
@Test public void respondsToExpiredPastTimestampWithNull() { DateTime requestTime = nowInUTC().minusMinutes(1); Credentials credentials = createCredentials(API_KEY, SECRET_KEY, requestTime); String principal = authenticator.authenticate(credentials); assertNull(principal); }