All pastes #762049 Raw Edit

Etwas

public java v1 · immutable
·published 2007-11-05 09:17 UTC
rendered paste body
import org.junit.*;import static org.junit.Assert.*;import java.net.*;import java.io.*;import java.util.*;  public class testclient {		Socket testsock=null;		String host="localhost";		int port=10000+359*10;		BufferedWriter out=null;		BufferedReader in=null;						@Test 		public void connecttest(){				connect();				assertTrue(testsock.getInetAddress().toString().equals("localhost/127.0.0.1"));				assertTrue(testsock.getPort() == 10000+359*10);				/*try{				testsock.close();				testsock=null;				} catch (IOException e) {}*/			}						public void connect(){		System.out.println("Connect entered");			try{				testsock=new Socket(host, port);			} catch (IOException e){			}		}						@Test		public void createRWtest(){			createRW();			assertTrue(out.toString()!=null);			assertTrue(in.toString()!=null);			/*try{				testsock.close();				testsock=null;				out=null;				in=null;			} catch (IOException e) {}	*/		}				public void createRW(){			connect();					try{				out=new BufferedWriter(new OutputStreamWriter(testsock.getOutputStream()));				in=new BufferedReader(new InputStreamReader(testsock.getInputStream()));			} catch (IOException e) {}		}						@Test		public void sendNick(){			createRW();				try{					String nick="testclient";					String port="6000";					System.out.println("Tryin to send nick @"+out.toString());					out.write(nick);					out.newLine();					out.flush();					System.out.println("Tryin to send port @"+out.toString());					out.write(port);					out.newLine();					out.flush();										System.out.println("Waiting for testanwer from server @"+in.toString());					String msg=in.readLine();					assertTrue(msg.equals("Test successful."));										msg="!getConnectedClients";					System.out.println("Tryin to receive Userlist @"+out.toString());					out.write(msg);					out.newLine();					out.flush();										System.out.println("Waiting for anwer @"+in.toString());					msg=in.readLine();					msg=in.readLine();					msg=in.readLine();					msg=msg.substring(0, 10);					System.out.println(msg);					assertTrue(msg.equals("testclient"));									} catch (IOException e) {}		}			public static void main(String args[]) {				      org.junit.runner.JUnitCore.main("testclient");	      }    }