1818import static com .github .tomakehurst .wiremock .client .WireMock .aResponse ;
1919import static com .github .tomakehurst .wiremock .client .WireMock .any ;
2020import static com .github .tomakehurst .wiremock .client .WireMock .urlMatching ;
21+ import static com .github .tomakehurst .wiremock .core .WireMockConfiguration .wireMockConfig ;
2122import static org .assertj .core .api .Assertions .assertThat ;
2223import static software .amazon .awssdk .http .HttpMetric .CONCURRENCY_ACQUIRE_DURATION ;
2324
24- import com .github .tomakehurst .wiremock .WireMockServer ;
25+ import com .github .tomakehurst .wiremock .junit5 .WireMockExtension ;
26+ import com .github .tomakehurst .wiremock .junit5 .WireMockTest ;
2527import java .io .IOException ;
26- import org .junit .After ;
27- import org .junit .AfterClass ;
28- import org .junit .Before ;
29- import org .junit .BeforeClass ;
30- import org .junit .Rule ;
31- import org .junit .Test ;
32- import org .junit .rules .ExpectedException ;
28+ import org .junit .jupiter .api .AfterEach ;
29+ import org .junit .jupiter .api .BeforeEach ;
30+ import org .junit .jupiter .api .Test ;
31+ import org .junit .jupiter .api .extension .RegisterExtension ;
3332import software .amazon .awssdk .http .HttpExecuteRequest ;
3433import software .amazon .awssdk .http .HttpExecuteResponse ;
3534import software .amazon .awssdk .http .SdkHttpClient ;
4039import software .amazon .awssdk .metrics .MetricCollector ;
4140
4241
42+ @ WireMockTest
4343public class ApacheMetricsTest {
44- private static WireMockServer wireMockServer ;
4544 private SdkHttpClient client ;
4645
47- @ Rule
48- public ExpectedException thrown = ExpectedException .none ();
46+ @ RegisterExtension
47+ static WireMockExtension wireMockServer = WireMockExtension .newInstance ()
48+ .options (wireMockConfig ().dynamicPort ().dynamicPort ())
49+ .build ();
4950
50- @ BeforeClass
51- public static void setUp () throws IOException {
52- wireMockServer = new WireMockServer ();
53- wireMockServer .start ();
54- }
55-
56- @ Before
51+ @ BeforeEach
5752 public void methodSetup () {
5853 wireMockServer .stubFor (any (urlMatching (".*" )).willReturn (aResponse ().withStatus (200 ).withBody ("{}" )));
5954 }
6055
61- @ AfterClass
62- public static void teardown () throws IOException {
63- wireMockServer .stop ();
64- }
65-
66- @ After
56+ @ AfterEach
6757 public void methodTeardown () {
6858 if (client != null ) {
6959 client .close ();
@@ -86,7 +76,7 @@ private HttpExecuteResponse makeRequestWithMetrics(SdkHttpClient httpClient, Met
8676 SdkHttpRequest httpRequest = SdkHttpFullRequest .builder ()
8777 .method (SdkHttpMethod .GET )
8878 .protocol ("http" )
89- .host ("localhost:" + wireMockServer .port ())
79+ .host ("localhost:" + wireMockServer .getPort ())
9080 .build ();
9181
9282 HttpExecuteRequest request = HttpExecuteRequest .builder ()
0 commit comments