package cloud.swiftnode.kspam;

import cloud.swiftnode.kspam.abstraction.MockPlayer;
import cloud.swiftnode.kspam.abstraction.MockPlugin;
import cloud.swiftnode.kspam.abstraction.MockServer;
import cloud.swiftnode.kspam.listener.PlayerListener;
import cloud.swiftnode.kspam.listener.ServerListener;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.server.ServerListPingEvent;
import org.junit.Test;

import java.lang.reflect.Field;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * Created by Junhyeong Lim on 2017-01-11.
 */
public class KSpamTest {
    @Test
    public void prcsTest() throws UnknownHostException {
        // Injection
        try {
            Field serverField = Bukkit.class.getDeclaredField("server");
            Field instField = KSpam.class.getDeclaredField("INSTANCE");

            serverField.setAccessible(true);
            instField.setAccessible(true);

            serverField.set(null, new MockServer());
            instField.set(null, new MockPlugin());
        } catch (Exception ex) {
            ex.printStackTrace();
        }

        // Element
        Player player = new MockPlayer();
        InetAddress addr = InetAddress.getByAddress(new byte[]{12, 32, 12, 32});

        // PlayerEvent
        PlayerLoginEvent loginEvent = new PlayerLoginEvent(player, "12.32.12.32", addr);
        PlayerJoinEvent joinEvent = new PlayerJoinEvent(player, "Test join");
        PlayerQuitEvent quitEvent = new PlayerQuitEvent(player, "Test quit");

        // ServerEvent
        ServerListPingEvent pingEvent = new ServerListPingEvent(addr, "test motd", 1, 10);

        // PlayerListener
        PlayerListener playerListener = new PlayerListener();
        playerListener.onLogin(loginEvent);
        playerListener.onJoin(joinEvent);
        playerListener.onQuit(quitEvent);

        // ServerListener
        ServerListener serverListener = new ServerListener();
        serverListener.onPing(pingEvent);
    }
}

@@ -812,16 +812,62 @@
 xception
+, IllegalAccessException, NoSuchFieldException
  %7B%0A     
@@ -886,26 +886,8 @@
 ion%0A
-        try %7B%0A    
     
@@ -955,28 +955,24 @@
 %22);%0A        
-  
-  
 Field instFi
@@ -1020,36 +1020,32 @@
 NCE%22);%0A%0A        
-   
- 
 serverField.setA
@@ -1061,20 +1061,16 @@
 (true);%0A
-    
         
@@ -1105,28 +1105,24 @@
 );%0A%0A        
-    
 serverField.
@@ -1154,28 +1154,24 @@
 ));%0A        
- 
-   
 instField.se
@@ -1200,85 +1200,8 @@
 ());
-%0A        %7D catch (Exception ex) %7B%0A            ex.printStackTrace();%0A        %7D
 %0A%0A  

Test code Cleanup