packageorg.mikeneck.multithreads;importorg.junit.*;importorg.junit.experimental.runners.Enclosed;importorg.junit.rules.TestName;importorg.junit.runner.RunWith;importjava.io.IOException;importjava.util.ArrayList;importjava.util.Arrays;importjava.util.List;importjava.util.concurrent.*;importstaticorg.hamcrest.Matchers.is;importstaticorg.junit.Assert.assertThat;/** * @author mike */@RunWith(Enclosed.class)publicclassSimpleSocketTest{publicstaticclassSingleClient{privatestaticfinalExecutorServiceSERVICE=Executors.newFixedThreadPool(1);privatestaticfinalintPORT=12521;privatestaticfinalStringLOCALHOST="localhost";privateSimpleClientclient;@RulepublicTestNametestName=newTestName();@BeforeClasspublicstaticvoidstart()throwsIOException{SERVICE.execute(newSimpleServer(PORT));}@Beforepublicvoidsetup()throwsIOException{client=newSimpleClient(LOCALHOST,PORT);}@AfterpublicvoidtearDown()throwsException{System.out.println(testName.getMethodName()+" is closing");client.close();}@AfterClasspublicstaticvoidend()throwsIOException{newSimpleClient(LOCALHOST,PORT).open().bye();}@TestpublicvoidsocketProcessing()throwsIOException{client.open();Stringmessage=client.sendMessage("Hello");System.out.println("Message from Server ["+message+"]");assertThat(message,is("Hello"));System.out.println("Assertion ends.");}}}