// Path: src/test/java/blue/lapis/common/CommonsTests.java
// public final class CommonsTests {
// 
//     public static void mockPlugin() {
//         Game game = mock(Game.class);
//         PluginContainer container = mock(PluginContainer.class);
// 
//         LapisCommonsPlugin plugin = new LapisCommonsPlugin(game, container);
//         plugin.logger = LoggerFactory.getLogger(LapisCommonsPlugin.class);
// 
//         PreInitializationEvent init = mock(PreInitializationEvent.class);
//         plugin.initialize(init);
//     }
// 
//     public static void mockPlayers(String... players) {
//         List<Player> playerList = Lists.newArrayListWithCapacity(players.length);
//         for (String name : players) {
//             Player player = mock(Player.class);
//             when(player.getName()).thenReturn(name);
//             playerList.add(player);
//         }
// 
//         Game game = LapisCommonsPlugin.getGame();
//         Server server = mock(Server.class);
//         when(server.getOnlinePlayers()).thenReturn(ImmutableList.copyOf(playerList));
//         when(game.getServer()).thenReturn(server);
//     }
// }
// 
// Path: src/main/java/blue/lapis/common/command/token/InvalidTokenException.java
// public class InvalidTokenException extends RuntimeException {
// 
//     private String token;
//     private Class<?> expectedType;
// 
//     public InvalidTokenException(String token, Class<?> expectedType) {
//         this.token = token;
//         this.expectedType = expectedType;
//     }
// 
//     /**
//      * @return the token that the TokenParser attempted to resolve
//      */
//     public String getToken() {
//         return token;
//     }
// 
//     /**
//      * @return the Class of the object which the TokenParser creates
//      */
//     public Class<?> getExpectedType() {
//         return expectedType;
//     }
// }
// 
// Path: src/main/java/blue/lapis/common/command/token/TokenParser.java
// public interface TokenParser<T> {
// 
//     /**
//      * Parse the provided parser and return a typesafe object for it.
//      *
//      * @param source the Player, console, or command block which initiated this object resolution
//      * @param token the token to be resolved into an object of type {@code T}
//      * @return an object of type T which corresponds to the String entered
//      *
//      * @throws InvalidTokenException if the String does not appear to match any object
//      */
//     T parse(CommandSource source, String token);
// 
//     /**
//      * Get tab-complete suggestions for this parser
//      *
//      * @param source The Player, CommandBlock, etc. responsible for this token
//      * @param token The token to generate tab-complete suggestions for
//      * @return a List of possible completions, or an empty List if none are available
//      */
//     List<String> suggest(CommandSource source, String token);
// }
// 
// Path: src/main/java/blue/lapis/common/command/token/TokenParserRegistry.java
// public class TokenParserRegistry {
// 
//     private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
//     private static final Map<Class<?>, TokenParser<?>> tokenParserMap = Maps.newHashMap();
// 
//     static {
//         register(Player.class, new PlayerTokenParser());
//         register(Integer.class, new IntegerTokenParser());
//         register(Boolean.class, new BooleanTokenParser());
//     }
// 
// 
//     @SuppressWarnings("unchecked")
//     @Nullable
//     public static <T> TokenParser<T> get(Class<T> clazz) {
//         TokenParser<T> t;
//         lock.readLock().lock();
//         {
//             t = (TokenParser<T>) tokenParserMap.get(clazz);
//         }
//         lock.readLock().unlock();
//         return t;
//     }
// 
//     public static <T> void register(Class<T> clazz, TokenParser<T> parser) {
//         lock.writeLock().lock();
//         {
//             tokenParserMap.put(clazz, parser);
//         }
//         lock.writeLock().unlock();
//     }
// }


import blue.lapis.common.command.token.TokenParser;
import blue.lapis.common.command.token.TokenParserRegistry;
import junit.framework.AssertionFailedError;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.util.command.CommandSource;
import javax.annotation.Nonnull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import blue.lapis.common.CommonsTests;
import blue.lapis.common.command.token.InvalidTokenException;
        assertTrue(parser.parse(source, "On"));
        assertTrue(parser.parse(source, "1"));

        assertFalse(parser.parse(source, "FalSE"));
        assertFalse(parser.parse(source, "no"));
        assertFalse(parser.parse(source, "oFF"));
        assertFalse(parser.parse(source, "0"));
    }

    @Test
    public void invalidBooleans() {
        TokenParser<Boolean> parser = getParser(Boolean.class);

        assertParseFail(parser, "96588");
        assertParseFail(parser, "hiho");
        assertParseFail(parser, "000001");
        assertParseFail(parser, "1.0");
    }

    @Nonnull
    private <T> TokenParser<T> getParser(Class<T> type) {
        TokenParser<T> parser = TokenParserRegistry.get(type);
        assertNotNull(parser);
        return parser;
    }

    private void assertParseFail(TokenParser t, String s) throws AssertionFailedError {
        try {
            t.parse(source, s);
            Assert.fail("No exception was thrown.");
// Path: src/test/java/blue/lapis/common/CommonsTests.java
// public final class CommonsTests {
// 
//     public static void mockPlugin() {
//         Game game = mock(Game.class);
//         PluginContainer container = mock(PluginContainer.class);
// 
//         LapisCommonsPlugin plugin = new LapisCommonsPlugin(game, container);
//         plugin.logger = LoggerFactory.getLogger(LapisCommonsPlugin.class);
// 
//         PreInitializationEvent init = mock(PreInitializationEvent.class);
//         plugin.initialize(init);
//     }
// 
//     public static void mockPlayers(String... players) {
//         List<Player> playerList = Lists.newArrayListWithCapacity(players.length);
//         for (String name : players) {
//             Player player = mock(Player.class);
//             when(player.getName()).thenReturn(name);
//             playerList.add(player);
//         }
// 
//         Game game = LapisCommonsPlugin.getGame();
//         Server server = mock(Server.class);
//         when(server.getOnlinePlayers()).thenReturn(ImmutableList.copyOf(playerList));
//         when(game.getServer()).thenReturn(server);
//     }
// }
// 
// Path: src/main/java/blue/lapis/common/command/token/InvalidTokenException.java
// public class InvalidTokenException extends RuntimeException {
// 
//     private String token;
//     private Class<?> expectedType;
// 
//     public InvalidTokenException(String token, Class<?> expectedType) {
//         this.token = token;
//         this.expectedType = expectedType;
//     }
// 
//     /**
//      * @return the token that the TokenParser attempted to resolve
//      */
//     public String getToken() {
//         return token;
//     }
// 
//     /**
//      * @return the Class of the object which the TokenParser creates
//      */
//     public Class<?> getExpectedType() {
//         return expectedType;
//     }
// }
// 
// Path: src/main/java/blue/lapis/common/command/token/TokenParser.java
// public interface TokenParser<T> {
// 
//     /**
//      * Parse the provided parser and return a typesafe object for it.
//      *
//      * @param source the Player, console, or command block which initiated this object resolution
//      * @param token the token to be resolved into an object of type {@code T}
//      * @return an object of type T which corresponds to the String entered
//      *
//      * @throws InvalidTokenException if the String does not appear to match any object
//      */
//     T parse(CommandSource source, String token);
// 
//     /**
//      * Get tab-complete suggestions for this parser
//      *
//      * @param source The Player, CommandBlock, etc. responsible for this token
//      * @param token The token to generate tab-complete suggestions for
//      * @return a List of possible completions, or an empty List if none are available
//      */
//     List<String> suggest(CommandSource source, String token);
// }
// 
// Path: src/main/java/blue/lapis/common/command/token/TokenParserRegistry.java
// public class TokenParserRegistry {
// 
//     private static final ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
//     private static final Map<Class<?>, TokenParser<?>> tokenParserMap = Maps.newHashMap();
// 
//     static {
//         register(Player.class, new PlayerTokenParser());
//         register(Integer.class, new IntegerTokenParser());
//         register(Boolean.class, new BooleanTokenParser());
//     }
// 
// 
//     @SuppressWarnings("unchecked")
//     @Nullable
//     public static <T> TokenParser<T> get(Class<T> clazz) {
//         TokenParser<T> t;
//         lock.readLock().lock();
//         {
//             t = (TokenParser<T>) tokenParserMap.get(clazz);
//         }
//         lock.readLock().unlock();
//         return t;
//     }
// 
//     public static <T> void register(Class<T> clazz, TokenParser<T> parser) {
//         lock.writeLock().lock();
//         {
//             tokenParserMap.put(clazz, parser);
//         }
//         lock.writeLock().unlock();
//     }
// }


// Path: src/test/java/blue/lapis/common/command/TokenParserTest.java
import blue.lapis.common.command.token.TokenParser;
import blue.lapis.common.command.token.TokenParserRegistry;
import junit.framework.AssertionFailedError;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.spongepowered.api.entity.player.Player;
import org.spongepowered.api.util.command.CommandSource;
import javax.annotation.Nonnull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import blue.lapis.common.CommonsTests;
import blue.lapis.common.command.token.InvalidTokenException;

        assertTrue(parser.parse(source, "On"));
        assertTrue(parser.parse(source, "1"));

        assertFalse(parser.parse(source, "FalSE"));
        assertFalse(parser.parse(source, "no"));
        assertFalse(parser.parse(source, "oFF"));
        assertFalse(parser.parse(source, "0"));
    }

    @Test
    public void invalidBooleans() {
        TokenParser<Boolean> parser = getParser(Boolean.class);

        assertParseFail(parser, "96588");
        assertParseFail(parser, "hiho");
        assertParseFail(parser, "000001");
        assertParseFail(parser, "1.0");
    }

    @Nonnull
    private <T> TokenParser<T> getParser(Class<T> type) {
        TokenParser<T> parser = TokenParserRegistry.get(type);
        assertNotNull(parser);
        return parser;
    }

    private void assertParseFail(TokenParser t, String s) throws AssertionFailedError {
        try {
            t.parse(source, s);
            Assert.fail("No exception was thrown.");
        } catch (InvalidTokenException ignored) {