DefaultSessionUtil extends SessionUtil { @Override public boolean validateMessage( byte[] sessionToken, ByteBuf message, int requestToken, long count) { int generatedToken = generateRequestToken(sessionToken, message, count); return requestToken == generatedToken; } DefaultSessionUtil(Clock clock);   DefaultSessionUtil(); @Override byte[] generateSessionToken(byte[] key, ByteBuf data, long count); @Override int generateRequestToken(byte[] sessionToken, ByteBuf message, long count); @Override boolean validateMessage(
      byte[] sessionToken, ByteBuf message, int requestToken, long count); long getThirtySecondsStepsFromEpoch();  }
@Test public void testValidateMessage() { clock.setTime(0); byte[] key = "super secret password".getBytes(); String destination = "test"; long epoch = sessionUtil.getThirtySecondsStepsFromEpoch(); byte[] sessionToken = sessionUtil.generateSessionToken( key, Unpooled.wrappedBuffer(destination.getBytes()), epoch); byte[] message = "a request".getBytes(); int requestToken = sessionUtil.generateRequestToken(sessionToken, Unpooled.wrappedBuffer(message), epoch + 1); boolean valid = sessionUtil.validateMessage( sessionToken, Unpooled.wrappedBuffer(message), requestToken, epoch + 1); Assert.assertTrue(valid); clock.setTime(40000); valid = sessionUtil.validateMessage( sessionToken, Unpooled.wrappedBuffer(message), requestToken, epoch + 2); Assert.assertFalse(valid); }