/*
 * LapisCommons
 * Copyright (c) 2014, LapisDev <https://github.com/LapisDev>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package blue.lapis.commons.test;

import blue.lapis.common.LapisCommonsPlugin;
import blue.lapis.common.command.impl.PlayerTokenParser;
import blue.lapis.common.command.impl.StandardTokenizer;
import org.apache.logging.log4j.LogManager;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.spongepowered.api.Game;
import org.spongepowered.api.entity.Player;
import org.spongepowered.api.event.state.PreInitializationEvent;

import java.util.ArrayList;
import java.util.List;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
 *
 */
public class TokenizerTest {
    LapisCommonsPlugin plugin = new LapisCommonsPlugin();
    public StandardTokenizer tokenizer = new StandardTokenizer();
    public PlayerTokenParser playerParser = new PlayerTokenParser();
    public Game gameProxy;

    public String identifiers = "one two three four 81 {} six [ ]";
    public String quotes = "one \"two three\" four 81 {} [ ]";

    @Before
    public void initTests() {
        List<Player> playerList = new ArrayList<Player>();
        for (String name : new String[]{"Foo", "Bar", "Baz", "Lorem", "Ipsum", "Marco", "Polo", "Foot"}) {
            Player p = mock(Player.class);
            when(p.getName()).thenReturn(name);
            playerList.add(p);
        }
        gameProxy = mock(Game.class);
        when(gameProxy.getOnlinePlayers()).thenReturn(playerList);

        PreInitializationEvent init = mock(PreInitializationEvent.class);
        when(init.getGame()).thenReturn(gameProxy);
        when(init.getPluginLog()).thenReturn(LogManager.getLogger(LapisCommonsPlugin.class));
        plugin.initialize(init);
    }

    @Test
    public void identifiers() {
        String[] tokens = tokenizer.getTokens(identifiers);
        Assert.assertArrayEquals(new String[]{"one", "two", "three", "four", "81.0", "six"}, tokens);
    }

    @Test
    public void quotes() {
        String[] tokens = tokenizer.getTokens(quotes);
        Assert.assertArrayEquals(new String[]{"one", "two three", "four", "81.0"}, tokens);
    }

    @Test
    public void resolvePlayer() {
        String resolution = playerParser.parse(null, "Lo").getName();
        Assert.assertEquals("Lorem", resolution);
        resolution = playerParser.parse(null, "Foo").getName();
        Assert.assertEquals("Foo", resolution);
    }

}

@@ -1342,24 +1342,64 @@
 dTokenizer;%0A
+import com.google.common.collect.Lists;%0A
 import org.a
@@ -1652,36 +1652,8 @@
 t;%0A%0A
-import java.util.ArrayList;%0A
 impo
@@ -1757,19 +1757,8 @@
 n;%0A%0A
-/**%0A *%0A */%0A
 publ
@@ -1790,802 +1790,156 @@
     
-LapisCommonsPlugin plugin = new LapisCommonsPlugin();%0A    public StandardTokenizer tokenizer = new StandardTokenizer();%0A    public PlayerTokenParser playerParser = new PlayerTokenParser();%0A    public Game gameProxy;%0A%0A    public String identifiers = %22one two three four 81 %7B%7D six %5B %5D%22;%0A    public String quotes = %22one %5C%22two three%5C%22 four 81 %7B%7D %5B %5D%22;%0A%0A    @Before%0A    public void initTests() %7B%0A        List%3CPlayer%3E playerList = new ArrayList%3CPlayer%3E();%0A        for (String name : new String%5B%5D%7B%22Foo%22, %22Bar%22, %22Baz%22, %22Lorem%22, %22Ipsum%22, %22Marco%22, %22Polo%22, %22Foot%22%7D) %7B%0A            Player p = mock(Player.class);%0A            when(p.getName()).thenReturn(name);%0A            playerList.add(p);%0A        %7D%0A        gameProxy = mock(Game.class);%0A        when(gameProxy.getOnlinePlayers()).thenReturn(playerList);%0A
+private StandardTokenizer tokenizer = new StandardTokenizer();%0A%0A    @Before%0A    public void initTests() %7B%0A        Game gameProxy = mock(Game.class);
 %0A   
@@ -2167,14 +2167,32 @@
     
-p
+new LapisCommonsP
 lugin
+()
 .ini
@@ -2301,27 +2301,50 @@
 tTokens(
-identifiers
+%22one two three four 81 %7B%7D six %5B %5D%22
 );%0A     
@@ -2530,22 +2530,50 @@
 tTokens(
-quotes
+%22one %5C%22two three%5C%22 four 81 %7B%7D %5B %5D%22
 );%0A     
@@ -2706,24 +2706,467 @@
 ePlayer() %7B%0A
+        List%3CPlayer%3E playerList = Lists.newArrayList();%0A        for (String name : new String%5B%5D%7B%22Foo%22, %22Bar%22, %22Baz%22, %22Lorem%22, %22Ipsum%22, %22Marco%22, %22Polo%22, %22Foot%22%7D) %7B%0A            Player p = mock(Player.class);%0A            when(p.getName()).thenReturn(name);%0A            playerList.add(p);%0A        %7D%0A%0A        when(LapisCommonsPlugin.getGame().getOnlinePlayers()).thenReturn(playerList);%0A%0A        PlayerTokenParser parser = new PlayerTokenParser();%0A
         Stri
@@ -3174,38 +3174,32 @@
 g resolution = p
-layerP
 arser.parse(null
@@ -3293,14 +3293,8 @@
  = p
-layerP
 arse

Clean up the test class.