|
| 1 | +package org.mockserver.lifecycle; |
| 2 | + |
| 3 | +import org.hamcrest.Matchers; |
| 4 | +import org.junit.Rule; |
| 5 | +import org.junit.Test; |
| 6 | +import org.junit.rules.ExpectedException; |
| 7 | +import org.mockserver.client.MockServerClient; |
| 8 | +import org.mockserver.integration.ClientAndServer; |
| 9 | +import org.mockserver.mockserver.MockServer; |
| 10 | +import org.mockserver.socket.PortFactory; |
| 11 | + |
| 12 | +import java.io.IOException; |
| 13 | +import java.net.ServerSocket; |
| 14 | +import java.net.Socket; |
| 15 | +import java.util.concurrent.TimeUnit; |
| 16 | + |
| 17 | +import static org.hamcrest.CoreMatchers.containsString; |
| 18 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 19 | +import static org.hamcrest.core.Is.is; |
| 20 | +import static org.junit.Assert.*; |
| 21 | +import static org.mockserver.model.HttpRequest.request; |
| 22 | + |
| 23 | +/** |
| 24 | + * @author jamesdbloom |
| 25 | + */ |
| 26 | +public class PortBindingIntegrationTest { |
| 27 | + |
| 28 | + private final static int MOCK_SERVER_PORT = PortFactory.findFreePort(); |
| 29 | + |
| 30 | + @Rule |
| 31 | + public ExpectedException exception = ExpectedException.none(); |
| 32 | + |
| 33 | + @Test |
| 34 | + 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); |
| 44 | + } |
| 45 | +} |
0 commit comments