Last active
January 31, 2018 18:22
-
-
Save alb-i986/f58756e4a34bc6e1ccea60b4846e62ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.github.tomakehurst.wiremock.client.WireMock; | |
import com.github.tomakehurst.wiremock.core.WireMockConfiguration; | |
import com.github.tomakehurst.wiremock.junit.WireMockClassRule; | |
import org.junit.AfterClass; | |
import org.junit.ClassRule; | |
import org.junit.Test; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
import static com.github.tomakehurst.wiremock.client.WireMock.*; | |
import static org.hamcrest.Matchers.*; | |
import static org.junit.Assert.*; | |
public class WiremockClassRule { | |
@ClassRule // this is enough | |
public static WireMockRule wireMockRule = new WireMockRule( | |
WireMockConfiguration.options() | |
.dynamicPort()); | |
@Test | |
public void test1() { | |
WireMock.givenThat( | |
get(urlEqualTo("/asd1")) | |
.willReturn( | |
ok("asd1"))); | |
} | |
@Test | |
public void test2() { | |
wireMockRule.givenThat( | |
get(urlEqualTo("/asd2")) | |
.willReturn( | |
ok("asd2"))); | |
} | |
@AfterClass | |
public static void assertWireMockClassRuleWorks() throws Exception { | |
List<String> urlPaths = wireMockRule.getStubMappings().stream() | |
.map(stub -> stub.getRequest().getUrl()) | |
.collect(Collectors.toList()); | |
assertThat(urlPaths, containsInAnyOrder("/asd1", "/asd2")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment