// Path: fernet-java8/src/main/java/com/macasaet/fernet/TokenValidationException.java
// public class TokenValidationException extends RuntimeException {
// 
//     private static final long serialVersionUID = 5175834607547919885L;
// 
//     public TokenValidationException(final String message) {
//         super(message);
//     }
// 
//     public TokenValidationException(final Throwable cause) {
//         this(cause.getMessage(), cause);
//     }
// 
//     public TokenValidationException(final String message, final Throwable cause) {
//         super(message, cause);
//     }
// 
// }


import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.embedded.RedisServer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.mockito.MockitoAnnotations.openMocks;
import java.io.IOException;
import java.security.SecureRandom;
import javax.servlet.http.HttpServletResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import com.macasaet.fernet.TokenValidationException;

    @After
    public void tearDown() throws Exception {
        try {
            try {
                clearData();
            } finally {
                redisServer.stop();
            }
        } finally {
            mockContext.close();
        }
    }

    protected void clearData() {
        try (final Jedis jedis = pool.getResource()) {
            jedis.del("fernet_keys");
        }
    }

    @Test
    public final void demonstrateKeyRotation() {
        final String initialToken = resource.issueToken("username", "password"); 

        manager.rotate();

        String result = resource.getSecret(initialToken);
        assertEquals("secret", result);

        manager.rotate();
// Path: fernet-java8/src/main/java/com/macasaet/fernet/TokenValidationException.java
// public class TokenValidationException extends RuntimeException {
// 
//     private static final long serialVersionUID = 5175834607547919885L;
// 
//     public TokenValidationException(final String message) {
//         super(message);
//     }
// 
//     public TokenValidationException(final Throwable cause) {
//         this(cause.getMessage(), cause);
//     }
// 
//     public TokenValidationException(final String message, final Throwable cause) {
//         super(message, cause);
//     }
// 
// }


// Path: fernet-java8/src/test/java/com/macasaet/fernet/example/rotation/KeyRotationExampleIT.java
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.embedded.RedisServer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.mockito.MockitoAnnotations.openMocks;
import java.io.IOException;
import java.security.SecureRandom;
import javax.servlet.http.HttpServletResponse;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import com.macasaet.fernet.TokenValidationException;


    @After
    public void tearDown() throws Exception {
        try {
            try {
                clearData();
            } finally {
                redisServer.stop();
            }
        } finally {
            mockContext.close();
        }
    }

    protected void clearData() {
        try (final Jedis jedis = pool.getResource()) {
            jedis.del("fernet_keys");
        }
    }

    @Test
    public final void demonstrateKeyRotation() {
        final String initialToken = resource.issueToken("username", "password"); 

        manager.rotate();

        String result = resource.getSecret(initialToken);
        assertEquals("secret", result);

        manager.rotate();
        assertThrows(TokenValidationException.class, () -> resource.getSecret(initialToken));