File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88import org .springframework .context .annotation .Bean ;
99import org .springframework .context .annotation .Primary ;
1010import org .springframework .test .context .DynamicPropertyRegistrar ;
11- import org .springframework .test .util .TestSocketUtils ;
1211
1312@ TestConfiguration (proxyBeanMethods = false )
1413public class MockConfig {
@@ -24,8 +23,7 @@ InstantSource testClock() {
2423
2524 @ Bean
2625 MockServer mockServer () {
27- int availableTcpPort = TestSocketUtils .findAvailableTcpPort ();
28- MockServer mockServer = new MockServer (availableTcpPort );
26+ MockServer mockServer = new MockServer (0 );
2927 mockServer .run ();
3028 return mockServer ;
3129 }
Original file line number Diff line number Diff line change @@ -23,8 +23,6 @@ public class MockServer implements AutoCloseable {
2323
2424 private final List <Rule > rules = new ArrayList <>();
2525
26- private final int port ;
27-
2826 private final HttpContext context ;
2927
3028 private Response fallbackResponse = Response .notFound ();
@@ -36,7 +34,6 @@ public MockServer(int port) {
3634 catch (IOException e ) {
3735 throw new UncheckedIOException (e );
3836 }
39- this .port = port ;
4037 this .context = this .server .createContext ("/" , new MockHandler ());
4138 this .server .setExecutor (Executors .newSingleThreadExecutor ());
4239 }
@@ -46,7 +43,7 @@ public void addFilter(Filter filter) {
4643 }
4744
4845 public int port () {
49- return port ;
46+ return this . server . getAddress (). getPort () ;
5047 }
5148
5249 public MockServer GET (String path , Function <Request , Response > responseFunction ) {
You can’t perform that action at this time.
0 commit comments