Skip to content

Commit ef8863d

Browse files
committed
test: Use test config
1 parent f794f9b commit ef8863d

File tree

11 files changed

+133
-106
lines changed

11 files changed

+133
-106
lines changed

src/test/java/org/monora/coolsocket/core/ClientManagementTest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import org.monora.coolsocket.core.session.ActiveConnection;
1313
import org.monora.coolsocket.core.session.CancelledException;
1414
import org.monora.coolsocket.core.session.ClosedException;
15+
import org.monora.coolsocket.core.variant.Connections;
16+
import org.monora.coolsocket.core.variant.DefaultCoolSocket;
17+
import org.monora.coolsocket.core.variant.factory.TestConfigFactory;
1518

1619
import java.io.IOException;
1720
import java.net.InetAddress;
@@ -20,11 +23,9 @@
2023

2124
public class ClientManagementTest
2225
{
23-
public static final int PORT = 58433;
24-
2526
public static final String MSG = "HEY!";
2627

27-
private final CoolSocket coolSocket = new CoolSocket(PORT);
28+
private final CoolSocket coolSocket = new DefaultCoolSocket();
2829

2930
void startDelayedShutdown(CoolSocket coolSocket)
3031
{
@@ -57,7 +58,7 @@ public void closingSafelyContractTest() throws IOException, InterruptedException
5758

5859
startDelayedShutdown(coolSocket);
5960

60-
try (ActiveConnection activeConnection = ActiveConnection.connect(new InetSocketAddress(PORT))) {
61+
try (ActiveConnection activeConnection = Connections.connect()) {
6162
while (activeConnection.getSocket().isConnected())
6263
activeConnection.receive();
6364
}
@@ -72,7 +73,7 @@ public void cancelContractTest() throws IOException, InterruptedException
7273

7374
startDelayedShutdown(coolSocket);
7475

75-
try (ActiveConnection activeConnection = ActiveConnection.connect(new InetSocketAddress(PORT))) {
76+
try (ActiveConnection activeConnection = Connections.connect()) {
7677
while (activeConnection.getSocket().isConnected())
7778
activeConnection.receive();
7879
}
@@ -87,7 +88,7 @@ public void closeImmediatelyContractTest() throws IOException, InterruptedExcept
8788

8889
startDelayedShutdown(coolSocket);
8990

90-
try (ActiveConnection activeConnection = ActiveConnection.connect(new InetSocketAddress(PORT))) {
91+
try (ActiveConnection activeConnection = Connections.connect()) {
9192
while (activeConnection.getSocket().isConnected())
9293
activeConnection.receive();
9394
}
@@ -97,9 +98,8 @@ public void closeImmediatelyContractTest() throws IOException, InterruptedExcept
9798
public void countClientConnectionsTest() throws IOException, InterruptedException
9899
{
99100
final String message = "Hey!";
100-
final InetAddress localhost = InetAddress.getLoopbackAddress();
101101

102-
CoolSocket coolSocket = new CoolSocket(PORT)
102+
CoolSocket coolSocket = new DefaultCoolSocket()
103103
{
104104
@Override
105105
public void onConnected(@NotNull ActiveConnection activeConnection)
@@ -122,7 +122,7 @@ public void onConnected(@NotNull ActiveConnection activeConnection)
122122
Assert.assertNotNull(session);
123123

124124
for (int i = 0; i < connections.length; i++) {
125-
ActiveConnection activeConnection = ActiveConnection.connect(new InetSocketAddress(localhost, PORT));
125+
ActiveConnection activeConnection = Connections.connect();
126126
connections[i] = activeConnection;
127127

128128
activeConnection.reply(message);
@@ -132,7 +132,7 @@ public void onConnected(@NotNull ActiveConnection activeConnection)
132132
session.getConnectionManager().getActiveConnectionList().size());
133133

134134
Assert.assertEquals("Number of connections should be same.", connections.length,
135-
session.getConnectionManager().getConnectionCountByAddress(localhost));
135+
session.getConnectionManager().getConnectionCountByAddress(InetAddress.getLocalHost()));
136136

137137
for (ActiveConnection activeConnection : connections) {
138138
try {

src/test/java/org/monora/coolsocket/core/CommandExecutionTest.java

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@
77
import org.monora.coolsocket.core.session.ActiveConnection;
88
import org.monora.coolsocket.core.session.CancelledException;
99
import org.monora.coolsocket.core.session.ClosedException;
10+
import org.monora.coolsocket.core.variant.Connections;
11+
import org.monora.coolsocket.core.variant.DefaultCoolSocket;
1012
import org.monora.coolsocket.core.variant.StaticMessageCoolSocket;
13+
import org.monora.coolsocket.core.variant.factory.TestConfigFactory;
1114

1215
import java.io.IOException;
1316
import java.net.InetSocketAddress;
1417
import java.net.SocketException;
1518

1619
public 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);

src/test/java/org/monora/coolsocket/core/ConfigTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.junit.Assert;
44
import org.junit.Test;
5-
import org.monora.coolsocket.core.variant.DummyCoolSocket;
65

76
import java.io.IOException;
87

@@ -11,7 +10,7 @@ public class ConfigTest
1110
@Test
1211
public void randomPortTest() throws IOException, InterruptedException
1312
{
14-
CoolSocket coolSocket = new DummyCoolSocket(0);
13+
CoolSocket coolSocket = new CoolSocket(0);
1514

1615
Assert.assertEquals("The random port should be 0 when not started.", 0,
1716
coolSocket.getLocalPort());

0 commit comments

Comments
 (0)