### Question:
BasicAuthenticationService extends StatelessService { protected long getExpirationTime(AuthenticationRequest authRequest) { long expirationTimeSeconds = authRequest.sessionExpirationSeconds != null ? authRequest.sessionExpirationSeconds : AUTH_TOKEN_EXPIRATION_SECONDS; if (this.UPPER_SESSION_LIMIT_SECONDS != null && expirationTimeSeconds > this.UPPER_SESSION_LIMIT_SECONDS) { expirationTimeSeconds = this.UPPER_SESSION_LIMIT_SECONDS; } return Utils.fromNowMicrosUtc(TimeUnit.SECONDS.toMicros(expirationTimeSeconds)); } BasicAuthenticationService(); @Override void authorizeRequest(Operation op); @Override boolean queueRequest(Operation op); @Override void handlePost(Operation op); static final String SELF_LINK; static final String AUTH_TOKEN_EXPIRATION_MICROS_PROPERTY; static final String UPPER_SESSION_LIMIT_SECONDS_PROPERTY; }### Answer:
@Test public void testGetExpirationTime() throws Throwable { BasicAuthenticationService basicAuthenticationService = new BasicAuthenticationService(); AuthenticationRequest authRequest = new AuthenticationRequest(); authRequest.sessionExpirationSeconds = null; long expectedSec = Instant.now().getEpochSecond() + BasicAuthenticationService.AUTH_TOKEN_EXPIRATION_SECONDS; long result = basicAuthenticationService.getExpirationTime(authRequest); assertEquals(expectedSec, TimeUnit.MICROSECONDS.toSeconds(result)); authRequest.sessionExpirationSeconds = (long) 0; result = basicAuthenticationService.getExpirationTime(authRequest); expectedSec = Instant.now().getEpochSecond(); assertEquals(expectedSec, TimeUnit.MICROSECONDS.toSeconds(result)); authRequest.sessionExpirationSeconds = (long) -1; result = basicAuthenticationService.getExpirationTime(authRequest); expectedSec = Instant.now().getEpochSecond() - 1; assertEquals(expectedSec, TimeUnit.MICROSECONDS.toSeconds(result)); authRequest.sessionExpirationSeconds = UPPER_SESSION_LIMIT - 1; result = basicAuthenticationService.getExpirationTime(authRequest); expectedSec = Instant.now().getEpochSecond() + UPPER_SESSION_LIMIT - 1; assertEquals(expectedSec, TimeUnit.MICROSECONDS.toSeconds(result)); authRequest.sessionExpirationSeconds = UPPER_SESSION_LIMIT; result = basicAuthenticationService.getExpirationTime(authRequest); expectedSec = Instant.now().getEpochSecond() + UPPER_SESSION_LIMIT; assertEquals(expectedSec, TimeUnit.MICROSECONDS.toSeconds(result)); authRequest.sessionExpirationSeconds = UPPER_SESSION_LIMIT + 1; result = basicAuthenticationService.getExpirationTime(authRequest); expectedSec = Instant.now().getEpochSecond() + UPPER_SESSION_LIMIT; assertEquals(expectedSec, TimeUnit.MICROSECONDS.toSeconds(result)); }