77import org .monora .coolsocket .core .session .ActiveConnection ;
88import org .monora .coolsocket .core .session .CancelledException ;
99import org .monora .coolsocket .core .session .ClosedException ;
10+ import org .monora .coolsocket .core .variant .Connections ;
11+ import org .monora .coolsocket .core .variant .DefaultCoolSocket ;
1012import org .monora .coolsocket .core .variant .StaticMessageCoolSocket ;
13+ import org .monora .coolsocket .core .variant .factory .TestConfigFactory ;
1114
1215import java .io .IOException ;
1316import java .net .InetSocketAddress ;
1417import java .net .SocketException ;
1518
1619public class CommandExecutionTest
1720{
18- private static final int PORT = 3547 ;
19-
2021 @ Test (expected = CancelledException .class )
2122 public void cancellationDuringWriteBeginTest () throws IOException , InterruptedException
2223 {
23- CoolSocket coolSocket = new CoolSocket ( PORT )
24+ CoolSocket coolSocket = new DefaultCoolSocket ( )
2425 {
2526 @ Override
2627 public void onConnected (@ NotNull ActiveConnection activeConnection )
@@ -37,7 +38,7 @@ public void onConnected(@NotNull ActiveConnection activeConnection)
3738
3839 coolSocket .start ();
3940
40- try (ActiveConnection activeConnection = ActiveConnection .connect (new InetSocketAddress ( PORT ) )) {
41+ try (ActiveConnection activeConnection = Connections .connect ()) {
4142 activeConnection .readBegin ();
4243 } finally {
4344 coolSocket .stop ();
@@ -47,7 +48,7 @@ public void onConnected(@NotNull ActiveConnection activeConnection)
4748 @ Test (expected = CancelledException .class )
4849 public void cancellationDuringReadBeginTest () throws IOException , InterruptedException
4950 {
50- CoolSocket coolSocket = new CoolSocket ( PORT )
51+ CoolSocket coolSocket = new DefaultCoolSocket ()
5152 {
5253 @ Override
5354 public void onConnected (@ NotNull ActiveConnection activeConnection )
@@ -64,7 +65,7 @@ public void onConnected(@NotNull ActiveConnection activeConnection)
6465
6566 coolSocket .start ();
6667
67- try (ActiveConnection activeConnection = ActiveConnection .connect (new InetSocketAddress ( PORT ) )) {
68+ try (ActiveConnection activeConnection = Connections .connect ()) {
6869 activeConnection .writeBegin (0 );
6970 } finally {
7071 coolSocket .stop ();
@@ -76,7 +77,7 @@ public void communicationAfterCancellationTest() throws IOException, Interrupted
7677 {
7778 final String message = "Where we are from there is no sun." ;
7879
79- CoolSocket coolSocket = new CoolSocket ( PORT )
80+ CoolSocket coolSocket = new DefaultCoolSocket ( )
8081 {
8182 @ Override
8283 public void onConnected (@ NotNull ActiveConnection activeConnection )
@@ -99,7 +100,7 @@ public void onConnected(@NotNull ActiveConnection activeConnection)
99100
100101 coolSocket .start ();
101102
102- ActiveConnection activeConnection = ActiveConnection .connect (new InetSocketAddress ( PORT ) );
103+ ActiveConnection activeConnection = Connections .connect ();
103104
104105 try {
105106 activeConnection .writeBegin (0 );
@@ -120,7 +121,7 @@ public void cancellationDuringReadTest() throws IOException, InterruptedExceptio
120121 {
121122 final String message = "The stars and moon are there! And we are going to climb it!" ;
122123
123- CoolSocket coolSocket = new CoolSocket ( PORT )
124+ CoolSocket coolSocket = new DefaultCoolSocket ( )
124125 {
125126 @ Override
126127 public void onConnected (@ NotNull ActiveConnection activeConnection )
@@ -141,7 +142,7 @@ public void onConnected(@NotNull ActiveConnection activeConnection)
141142
142143 coolSocket .start ();
143144
144- try (ActiveConnection activeConnection = ActiveConnection .connect (new InetSocketAddress ( PORT ) )) {
145+ try (ActiveConnection activeConnection = Connections .connect ()) {
145146 ActiveConnection .Description description = activeConnection .writeBegin (0 );
146147
147148 try {
@@ -159,11 +160,11 @@ public void onConnected(@NotNull ActiveConnection activeConnection)
159160 public void exchangeProtocolVersionTest () throws IOException , InterruptedException
160161 {
161162 final String message = "It is a long way home but a fun one." ;
162- StaticMessageCoolSocket coolSocket = new StaticMessageCoolSocket (PORT );
163+ StaticMessageCoolSocket coolSocket = new StaticMessageCoolSocket ();
163164 coolSocket .setStaticMessage (message );
164165 coolSocket .start ();
165166
166- try (ActiveConnection activeConnection = ActiveConnection .connect (new InetSocketAddress ( PORT ) )) {
167+ try (ActiveConnection activeConnection = Connections .connect ()) {
167168 activeConnection .receive ();
168169
169170 Assert .assertEquals ("The protocol version should be the same." ,
@@ -179,7 +180,7 @@ public void exchangeProtocolVersionTest() throws IOException, InterruptedExcepti
179180 public void closeSafelyTest () throws IOException , InterruptedException
180181 {
181182 final String message = "It is a long way home but a fun one." ;
182- CoolSocket coolSocket = new CoolSocket ( PORT )
183+ CoolSocket coolSocket = new DefaultCoolSocket ( )
183184 {
184185 @ Override
185186 public void onConnected (@ NotNull ActiveConnection activeConnection )
@@ -196,7 +197,7 @@ public void onConnected(@NotNull ActiveConnection activeConnection)
196197
197198 coolSocket .start ();
198199
199- try (ActiveConnection activeConnection = ActiveConnection .connect (new InetSocketAddress ( PORT ) )) {
200+ try (ActiveConnection activeConnection = Connections .connect ()) {
200201 activeConnection .receive ();
201202 } finally {
202203 coolSocket .stop ();
@@ -207,7 +208,7 @@ public void onConnected(@NotNull ActiveConnection activeConnection)
207208 public void closeSafelyRemoteCloseProcessedTest () throws IOException , InterruptedException
208209 {
209210 final String message = "It is a long way home but a fun one." ;
210- CoolSocket coolSocket = new CoolSocket ( PORT )
211+ CoolSocket coolSocket = new DefaultCoolSocket ( )
211212 {
212213 @ Override
213214 public void onConnected (@ NotNull ActiveConnection activeConnection )
@@ -224,7 +225,7 @@ public void onConnected(@NotNull ActiveConnection activeConnection)
224225
225226 coolSocket .start ();
226227
227- try (ActiveConnection activeConnection = ActiveConnection .connect (new InetSocketAddress ( PORT ) )) {
228+ try (ActiveConnection activeConnection = Connections .connect ()) {
228229 activeConnection .receive ();
229230 } catch (ClosedException e ) {
230231 Assert .assertTrue ("The close operation should be requested by the remote." , e .remoteRequested );
@@ -237,7 +238,7 @@ public void onConnected(@NotNull ActiveConnection activeConnection)
237238 public void closeSafelyClosesConnectionTest () throws IOException , InterruptedException
238239 {
239240 final String message = "It is a long way home but a fun one." ;
240- CoolSocket coolSocket = new CoolSocket ( PORT )
241+ CoolSocket coolSocket = new DefaultCoolSocket ( )
241242 {
242243 @ Override
243244 public void onConnected (@ NotNull ActiveConnection activeConnection )
@@ -261,7 +262,7 @@ public void onConnected(@NotNull ActiveConnection activeConnection)
261262
262263 coolSocket .start ();
263264
264- try (ActiveConnection activeConnection = ActiveConnection .connect (new InetSocketAddress ( PORT ) )) {
265+ try (ActiveConnection activeConnection = Connections .connect ()) {
265266 try {
266267 activeConnection .receive ();
267268 } catch (ClosedException e ) {
@@ -276,7 +277,7 @@ public void onConnected(@NotNull ActiveConnection activeConnection)
276277 public void readerCancelsWhenReadingLargeChunksTest () throws InterruptedException , IOException
277278 {
278279 final byte [] data = new byte [8192 ];
279- final CoolSocket coolSocket = new CoolSocket ( PORT )
280+ final CoolSocket coolSocket = new DefaultCoolSocket ( )
280281 {
281282 @ Override
282283 public void onConnected (@ NotNull ActiveConnection activeConnection )
@@ -297,7 +298,7 @@ public void onConnected(@NotNull ActiveConnection activeConnection)
297298
298299 coolSocket .start ();
299300
300- try (ActiveConnection activeConnection = ActiveConnection .connect (new InetSocketAddress ( PORT ) )) {
301+ try (ActiveConnection activeConnection = Connections .connect ()) {
301302 ActiveConnection .Description description = activeConnection .writeBegin (0 );
302303 while (activeConnection .getSocket ().isConnected ()) {
303304 activeConnection .write (description , data );
0 commit comments