Skip to content

Commit c25d49a

Browse files
authored
Merge pull request TooTallNate#807 from marci4/UnittestParameter
Uses parameters
2 parents b227a3a + 2ce6e61 commit c25d49a

File tree

2 files changed

+38
-166
lines changed

2 files changed

+38
-166
lines changed

src/test/java/org/java_websocket/issues/Issue256Test.java

Lines changed: 18 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,34 @@
3434
import org.java_websocket.util.SocketUtil;
3535
import org.java_websocket.util.ThreadCheck;
3636
import org.junit.*;
37+
import org.junit.runner.RunWith;
38+
import org.junit.runners.Parameterized;
3739

3840
import java.io.IOException;
3941
import java.net.InetSocketAddress;
4042
import java.net.URI;
43+
import java.util.ArrayList;
44+
import java.util.Collection;
45+
import java.util.List;
4146
import java.util.concurrent.CountDownLatch;
4247

4348
import static org.hamcrest.core.Is.is;
4449
import static org.junit.Assume.assumeThat;
4550

51+
@RunWith(Parameterized.class)
4652
public class Issue256Test {
4753

54+
private static final int NUMBER_OF_TESTS = 10;
4855
private static WebSocketServer ws;
4956

5057
private static int port;
5158
static CountDownLatch countServerDownLatch = new CountDownLatch( 1 );
5259
@Rule
5360
public ThreadCheck zombies = new ThreadCheck();
5461

62+
@Parameterized.Parameter
63+
public int count;
64+
5565
@BeforeClass
5666
public static void startServer() throws Exception {
5767
port = SocketUtil.getAvailablePort();
@@ -130,104 +140,21 @@ public static void successTests() throws InterruptedException, IOException {
130140
ws.stop();
131141
}
132142

133-
@Test(timeout = 5000)
134-
public void runReconnectBlockingScenario0() throws Exception {
135-
runTestScenarioReconnect( true );
136-
}
137-
138-
@Test(timeout = 5000)
139-
public void runReconnectBlockingScenario1() throws Exception {
140-
runTestScenarioReconnect( true );
141-
}
142-
143-
@Test(timeout = 5000)
144-
public void runReconnectBlockingScenario2() throws Exception {
145-
runTestScenarioReconnect( true );
146-
}
147-
148-
@Test(timeout = 5000)
149-
public void runReconnectBlockingScenario3() throws Exception {
150-
runTestScenarioReconnect( true );
151-
}
152-
153-
@Test(timeout = 5000)
154-
public void runReconnectBlockingScenario4() throws Exception {
155-
runTestScenarioReconnect( true );
143+
@Parameterized.Parameters
144+
public static Collection<Integer[]> data() {
145+
List<Integer[]> ret = new ArrayList<Integer[]>(NUMBER_OF_TESTS);
146+
for (int i = 0; i < NUMBER_OF_TESTS; i++) ret.add(new Integer[]{i});
147+
return ret;
156148
}
157149

158150
@Test(timeout = 5000)
159-
public void runReconnectBlockingScenario5() throws Exception {
160-
runTestScenarioReconnect( true );
161-
}
162-
163-
@Test(timeout = 5000)
164-
public void runReconnectBlockingScenario6() throws Exception {
165-
runTestScenarioReconnect( true );
166-
}
167-
168-
@Test(timeout = 5000)
169-
public void runReconnectBlockingScenario7() throws Exception {
170-
runTestScenarioReconnect( true );
171-
}
172-
173-
@Test(timeout = 5000)
174-
public void runReconnectBlockingScenario8() throws Exception {
175-
runTestScenarioReconnect( true );
176-
}
177-
178-
@Test(timeout = 5000)
179-
public void runReconnectBlockingScenario9() throws Exception {
180-
runTestScenarioReconnect( true );
181-
}
182-
183-
@Test(timeout = 5000)
184-
public void runReconnectScenario0() throws Exception {
185-
runTestScenarioReconnect( false );
186-
}
187-
188-
@Test(timeout = 5000)
189-
public void runReconnectScenario1() throws Exception {
190-
runTestScenarioReconnect( false );
191-
}
192-
193-
@Test(timeout = 5000)
194-
public void runReconnectScenario2() throws Exception {
195-
runTestScenarioReconnect( false );
196-
}
197-
198-
@Test(timeout = 5000)
199-
public void runReconnectScenario3() throws Exception {
200-
runTestScenarioReconnect( false );
201-
}
202-
203-
@Test(timeout = 5000)
204-
public void runReconnectScenario4() throws Exception {
151+
public void runReconnectSocketClose() throws Exception {
205152
runTestScenarioReconnect( false );
206153
}
207154

208155
@Test(timeout = 5000)
209-
public void runReconnectScenario5() throws Exception {
210-
runTestScenarioReconnect( false );
211-
}
212-
213-
@Test(timeout = 5000)
214-
public void runReconnectScenario6() throws Exception {
215-
runTestScenarioReconnect( false );
216-
}
217-
218-
@Test(timeout = 5000)
219-
public void runReconnectScenario7() throws Exception {
220-
runTestScenarioReconnect( false );
221-
}
222-
223-
@Test(timeout = 5000)
224-
public void runReconnectScenario8() throws Exception {
225-
runTestScenarioReconnect( false );
226-
}
227-
228-
@Test(timeout = 5000)
229-
public void runReconnectScenario9() throws Exception {
230-
runTestScenarioReconnect( false );
156+
public void runReconnectCloseBlocking() throws Exception {
157+
runTestScenarioReconnect( true );
231158
}
232159

233160
}

src/test/java/org/java_websocket/issues/Issue580Test.java

Lines changed: 20 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,25 @@
3535
import org.java_websocket.util.ThreadCheck;
3636
import org.junit.Rule;
3737
import org.junit.Test;
38+
import org.junit.runner.RunWith;
39+
import org.junit.runners.Parameterized;
3840

3941
import java.net.InetSocketAddress;
4042
import java.net.URI;
43+
import java.util.ArrayList;
44+
import java.util.Collection;
45+
import java.util.List;
4146
import java.util.concurrent.CountDownLatch;
4247

48+
@RunWith(Parameterized.class)
4349
public class Issue580Test {
4450

51+
private static final int NUMBER_OF_TESTS = 10;
52+
53+
@Parameterized.Parameter
54+
public int count;
55+
56+
4557
@Rule
4658
public ThreadCheck zombies = new ThreadCheck();
4759

@@ -106,87 +118,20 @@ public void onError( Exception ex ) {
106118
Thread.sleep( 100 );
107119
}
108120

109-
@Test
110-
public void runNoCloseBlockingTestScenario0() throws Exception {
111-
runTestScenario(false);
112-
}
113-
@Test
114-
public void runNoCloseBlockingTestScenario1() throws Exception {
115-
runTestScenario(false);
116-
}
117-
@Test
118-
public void runNoCloseBlockingTestScenario2() throws Exception {
119-
runTestScenario(false);
120-
}
121-
@Test
122-
public void runNoCloseBlockingTestScenario3() throws Exception {
123-
runTestScenario(false);
124-
}
125-
@Test
126-
public void runNoCloseBlockingTestScenario4() throws Exception {
127-
runTestScenario(false);
128-
}
129-
@Test
130-
public void runNoCloseBlockingTestScenario5() throws Exception {
131-
runTestScenario(false);
132-
}
133-
@Test
134-
public void runNoCloseBlockingTestScenario6() throws Exception {
135-
runTestScenario(false);
136-
}
137-
@Test
138-
public void runNoCloseBlockingTestScenario7() throws Exception {
139-
runTestScenario(false);
140-
}
141-
@Test
142-
public void runNoCloseBlockingTestScenario8() throws Exception {
143-
runTestScenario(false);
144-
}
145-
@Test
146-
public void runNoCloseBlockingTestScenario9() throws Exception {
147-
runTestScenario(false);
121+
@Parameterized.Parameters
122+
public static Collection<Integer[]> data() {
123+
List<Integer[]> ret = new ArrayList<Integer[]>(NUMBER_OF_TESTS);
124+
for (int i = 0; i < NUMBER_OF_TESTS; i++) ret.add(new Integer[]{i});
125+
return ret;
148126
}
149127

150128
@Test
151-
public void runCloseBlockingTestScenario0() throws Exception {
152-
runTestScenario(true);
153-
}
154-
@Test
155-
public void runCloseBlockingTestScenario1() throws Exception {
156-
runTestScenario(true);
157-
}
158-
@Test
159-
public void runCloseBlockingTestScenario2() throws Exception {
160-
runTestScenario(true);
161-
}
162-
@Test
163-
public void runCloseBlockingTestScenario3() throws Exception {
164-
runTestScenario(true);
165-
}
166-
@Test
167-
public void runCloseBlockingTestScenario4() throws Exception {
168-
runTestScenario(true);
169-
}
170-
@Test
171-
public void runCloseBlockingTestScenario5() throws Exception {
172-
runTestScenario(true);
173-
}
174-
@Test
175-
public void runCloseBlockingTestScenario6() throws Exception {
176-
runTestScenario(true);
177-
}
178-
@Test
179-
public void runCloseBlockingTestScenario7() throws Exception {
180-
runTestScenario(true);
181-
}
182-
@Test
183-
public void runCloseBlockingTestScenario8() throws Exception {
184-
runTestScenario(true);
129+
public void runNoCloseBlockingTestScenario() throws Exception {
130+
runTestScenario(false);
185131
}
186132
@Test
187-
public void runCloseBlockingTestScenario9() throws Exception {
133+
public void runCloseBlockingTestScenario() throws Exception {
188134
runTestScenario(true);
189135
}
190-
191136
}
192137

0 commit comments

Comments
 (0)