package server1; import static org.junit.Assert.*; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.ServerSocket; import java.net.Socket; import org.junit.Before; import org.junit.Test; public class Proovitestid{ ServerSocket ss; Socket sc1, sc2; ChatServer server; InputStream is1, is2; OutputStream os1, os2; static final int PORT=3001; @Before public void setUp() throws Exception { } @Test public void test() { assertEquals(5, 3+2); } public void yhenduseLoomine() throws IOException{ ss=new ServerSocket(PORT); ss.setSoTimeout(4000); server=new ChatServer(ss); sc1=new Socket("localhost", PORT); sc1.setSoTimeout(2000); is1=sc1.getInputStream(); sc2=new Socket("localhost", PORT); sc2.setSoTimeout(2000); os2=sc2.getOutputStream(); } @Test public void viieBaidiKirjutamine() throws IOException{ yhenduseLoomine(); for(int i=0; i<5; i++){ os2.write(37+i); } os2.close(); for(int i=0; i<5; i++){ assertEquals(37+i, is1.read()); } sc1.close(); sc2.close(); } }