mirror of
https://gitee.com/dcren/initializr.git
synced 2025-09-20 10:38:12 +08:00
Adopt Spring Java Format's JUnit 5 check
Closes gh-941
This commit is contained in:
@@ -31,15 +31,14 @@ A convenient way to consume the stubs in your project is to add a test dependenc
|
||||
|
||||
and then pull the stubs from the classpath. In a Spring Boot application, using
|
||||
Spring Cloud Contract, you can start a WireMock server and register all the stubs
|
||||
with it like this:
|
||||
with it, as shown in the following JUnit 5-based example:
|
||||
|
||||
[source,java,indent=0,subs="attributes"]
|
||||
----
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@AutoConfigureWireMock(port = 0,
|
||||
stubs="classpath:META-INF/io.spring.initializr/initializr-web/{spring-initializr-version}")
|
||||
public class ClientApplicationTests {
|
||||
class ClientApplicationTests {
|
||||
|
||||
@Value("${wiremock.server.port}")
|
||||
private int port;
|
||||
@@ -80,16 +79,16 @@ stubs declared as a dependency):
|
||||
</dependency>
|
||||
----
|
||||
|
||||
The test should use `@AutoConfigureStubRunner` instead:
|
||||
The test should use `@AutoConfigureStubRunner` instead, as shown in the following JUnit
|
||||
5-based example:
|
||||
|
||||
[source,java,indent=0,,subs="attributes,specialchars"]
|
||||
----
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
|
||||
@AutoConfigureStubRunner(
|
||||
ids = "io.spring.initializr:initializr-web:{spring-initializr-version}",
|
||||
repositoryRoot = "https://repo.spring.io/{initializr-repo}")
|
||||
public class ClientApplicationTests {
|
||||
class ClientApplicationTests {
|
||||
|
||||
@Autowired
|
||||
private StubFinder stubFinder;
|
||||
@@ -100,9 +99,9 @@ The test should use `@AutoConfigureStubRunner` instead:
|
||||
}
|
||||
----
|
||||
|
||||
Here is an example of a test that retrieves the metadata of the service. The assertions
|
||||
do not matter much here but it illustrates how you could integrate that in the test suite
|
||||
of a custom client:
|
||||
Here is JUnit 5-based example of a test that retrieves the metadata of the service. The
|
||||
assertions do not matter much here but it illustrates how you could integrate that in the
|
||||
test suite of a custom client:
|
||||
|
||||
[source,java,indent=0,subs="verbatim,quotes,attributes"]
|
||||
----
|
||||
|
@@ -18,8 +18,7 @@ package io.spring.initializr.stub;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -34,16 +33,14 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
// tag::test[]
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.NONE)
|
||||
@AutoConfigureStubRunner(ids = "io.spring.initializr:initializr-web:${project.version}", stubsMode = StubsMode.LOCAL)
|
||||
// tag::test[]
|
||||
public class ClientApplicationTests {
|
||||
class ClientApplicationTests {
|
||||
|
||||
@Autowired
|
||||
private StubFinder stubFinder;
|
||||
@@ -52,7 +49,7 @@ public class ClientApplicationTests {
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
@Test
|
||||
public void testCurrentMetadata() {
|
||||
void testCurrentMetadata() {
|
||||
RequestEntity<Void> request = RequestEntity.get(createUri("/"))
|
||||
.accept(MediaType.valueOf("application/vnd.initializr.v2.1+json")).build();
|
||||
|
||||
|
Reference in New Issue
Block a user