DefaultAuthenticationService implements AuthenticationService { @Override public String anonymousToken() { final DateTime now = dateTimeService.now(); return Jwts.builder() .setSubject("anonymous") .setId("b5a2918e-bd3f-48f5-8437-daf40fd3f323") .setIssuedAt(now.toLocalDateTime().toDate()) .setExpiration(dateTimeService.plusDaysAsDate(now, TOKEN_INTERVAL_DAYS)) .signWith(SignatureAlgorithm.HS256, JwtFilter.SECRET_KEY) .compact(); } @Autowired  DefaultAuthenticationService(final UserService userService, final DateTimeService dateTimeService); @Override boolean userPasswordCheck(final String username, final String password); @Override String authenticationToken(final String username, final String password); @Override String anonymousToken();  }
@Ignore("Remove until difference in time on build machine is figured out.") @Test public void testAnonymousAuthenticationToken() { final DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"); final DateTime now = formatter.parseDateTime("1985-10-26 01:24:00").withZone(DateTimeZone.UTC); final Date expiry = new Date(1_000_000_000L); Mockito.when(mockDateTimeService.now()).thenReturn(now); Mockito.when(mockDateTimeService.plusDaysAsDate(now, 1)).thenReturn(expiry); final String response = defaultAuthenticationService.anonymousToken(); Assert.assertEquals( "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJhbm9ueW1vdXMiLCJpYXQiOjQ5OTE2NjY0MCwiZXhwIjoxMDAwMDAwfQ.c-kEHbZBxg4sTiweFgQrHtMJSSwiaavqHRsWhw0Uvwc", response); Mockito.verify(mockDateTimeService).now(); Mockito.verify(mockDateTimeService).plusDaysAsDate(now, 1); }