
package com.esotericsoftware.kryonetty;

import com.esotericsoftware.kryo.Kryo;

import java.net.InetSocketAddress;

import junit.framework.TestCase;

import org.jboss.netty.channel.ChannelHandlerContext;

public class SimpleTest extends TestCase {
	protected boolean testRequestReceived;

	public void testSimple () throws Exception {
		Server server = new Server(54321) {
			public void connected (ChannelHandlerContext ctx) {
				System.out.println("Server: Client connected: " + ctx.getChannel().getRemoteAddress());
				ctx.getChannel().write("make a programmer rich");
			}

			public void disconnected (ChannelHandlerContext ctx) {
				System.out.println("Server: Client disconnected: " + ctx.getChannel().getRemoteAddress());
			}

			public void received (ChannelHandlerContext ctx, Object object) {
				System.out.println("Server: Received: " + object);
				if(object instanceof TestRequest) {
					testRequestReceived = true;
				}
			}

			public Kryo getKryo () {
				return new Kryo();
			}
		};

		Client client = new Client(new InetSocketAddress("localhost", 54321)) {
			public void connected (ChannelHandlerContext ctx) {
				System.out.println("Client: Connected to server: " + ctx.getChannel().getRemoteAddress());
			}

			public void disconnected (ChannelHandlerContext ctx) {
				System.out.println("Client: Disconnected from server: " + ctx.getChannel().getRemoteAddress());
			}

			public void received (ChannelHandlerContext ctx, Object object) {
				System.out.println("Client: Received: " + object);
			}

			public Kryo getKryo () {
				return new Kryo();
			}
		};
		client.getKryo().register(TestRequest.class);
		server.getKryo().register(TestRequest.class);
		TestRequest request = new TestRequest();
		request.someText = "Bwuk!";
		client.send("i like the way you do it right thurrrr");
		client.send(request);
		Thread.sleep(1000);
		client.close();
		assertTrue(testRequestReceived);
	}
}

@@ -35,16 +35,60 @@
 netty;%0A%0A
+import static org.junit.Assert.assertTrue;%0A%0A
 import c
@@ -159,42 +159,8 @@
 s;%0A%0A
-import junit.framework.TestCase;%0A%0A
 impo
@@ -208,16 +208,64 @@
 Context;
+%0Aimport org.junit.Before;%0Aimport org.junit.Test;
 %0A%0Apublic
@@ -286,25 +286,8 @@
 est 
-extends TestCase 
 %7B%0A%09p
@@ -328,64 +328,91 @@
 ed;%0A
-%0A%09public void testSimple () throws Exception %7B%0A%09%09Server 
+%09private Server server;%0A%09private Client client;%0A%0A%09@Before%0A%09public void setup() %7B%0A%09%09
 serv
@@ -1076,18 +1076,10 @@
 %09%7D;%0A
-%0A
 %09%09
-Client 
 clie
@@ -1642,32 +1642,248 @@
 yo();%0A%09%09%09%7D%0A%09%09%7D;%0A
+%09%7D%0A%09%0A%09@Test%0A%09public void testSimple () throws Exception %7B%0A%09%09client.send(%22i like the way you do it right thurrrr%22);%0A%09%09client.close();%0A%09%09server.close();%0A%09%7D%0A%09%0A%09@Test%0A%09public void testRegisterClass() throws Exception %7B%0A%0A
 %09%09client.getKryo
@@ -2039,65 +2039,8 @@
 !%22;%0A
-%09%09client.send(%22i like the way you do it right thurrrr%22);%0A
 %09%09cl

Move to jUnit 4, split tests