Skip to content

Commit 1c83f8a

Browse files
committed
added test for port binding
1 parent 463ce85 commit 1c83f8a

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

mockserver-netty/src/test/java/org/mockserver/lifecycle/PortBindingIntegrationTest.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,25 @@ public class PortBindingIntegrationTest {
3232

3333
@Test
3434
public void throwsExpectionOnPortAlreadyBound() {
35-
// then
36-
exception.expect(RuntimeException.class);
37-
exception.expectMessage(Matchers.containsString("Exception while binding MockServer to port"));
38-
39-
// when - server started
40-
new MockServer(MOCK_SERVER_PORT);
41-
42-
// and - server started again on same port
43-
new MockServer(MOCK_SERVER_PORT);
35+
MockServer mockServerOne = null, mockServerTwo = null;
36+
try {
37+
// then
38+
exception.expect(RuntimeException.class);
39+
exception.expectMessage(Matchers.containsString("Exception while binding MockServer to port"));
40+
41+
// when - server started
42+
mockServerOne = new MockServer(MOCK_SERVER_PORT);
43+
44+
// and - server started again on same port
45+
mockServerTwo = new MockServer(MOCK_SERVER_PORT);
46+
47+
} finally {
48+
if (mockServerOne != null) {
49+
mockServerOne.stop();
50+
}
51+
if (mockServerTwo != null) {
52+
mockServerTwo.stop();
53+
}
54+
}
4455
}
4556
}

0 commit comments

Comments
 (0)