Skip to content

Commit f1664db

Browse files
eddumelendezsnicoll
authored andcommitted
Add JUnit Jupiter sample application
See spring-projectsgh-8048
1 parent 1c05afb commit f1664db

File tree

6 files changed

+183
-0
lines changed

6 files changed

+183
-0
lines changed

spring-boot-samples/README.adoc

+3
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ The following sample applications are provided:
132132
| link:spring-boot-sample-jta-narayana[spring-boot-sample-jta-narayana]
133133
| JTA transactions with Narayana
134134

135+
| link:spring-boot-sample-junit-jupiter[spring-boot-sample-junit-jupiter]
136+
| Demonstrates JUnit Jupiter-based testing
137+
135138
| link:spring-boot-sample-liquibase[spring-boot-sample-liquibase]
136139
| Database migrations with Liquibase
137140

spring-boot-samples/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
<module>spring-boot-sample-jta-bitronix</module>
6464
<module>spring-boot-sample-jta-narayana</module>
6565
<module>spring-boot-sample-jta-jndi</module>
66+
<module>spring-boot-sample-junit-jupiter</module>
6667
<module>spring-boot-sample-liquibase</module>
6768
<module>spring-boot-sample-logback</module>
6869
<module>spring-boot-sample-metrics-dropwizard</module>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<!-- Your own application should inherit from spring-boot-starter-parent -->
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-samples</artifactId>
8+
<version>2.0.0.BUILD-SNAPSHOT</version>
9+
</parent>
10+
<artifactId>spring-boot-sample-junit-jupiter</artifactId>
11+
<name>Spring Boot JUnit Jupiter Sample</name>
12+
<description>Spring Boot JUnit Jupiter Sample</description>
13+
<url>http://projects.spring.io/spring-boot/</url>
14+
<organization>
15+
<name>Pivotal Software, Inc.</name>
16+
<url>http://www.spring.io</url>
17+
</organization>
18+
<properties>
19+
<main.basedir>${basedir}/../..</main.basedir>
20+
<junit.jupiter.version>5.0.0-M5</junit.jupiter.version>
21+
<junit.platform.version>1.0.0-M5</junit.platform.version>
22+
</properties>
23+
24+
<dependencies>
25+
<!-- Compile -->
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-web</artifactId>
29+
</dependency>
30+
<!-- Test -->
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-test</artifactId>
34+
<scope>test</scope>
35+
<exclusions>
36+
<exclusion>
37+
<groupId>junit</groupId>
38+
<artifactId>junit</artifactId>
39+
</exclusion>
40+
</exclusions>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.junit.jupiter</groupId>
44+
<artifactId>junit-jupiter-api</artifactId>
45+
<version>${junit.jupiter.version}</version>
46+
<scope>test</scope>
47+
</dependency>
48+
</dependencies>
49+
50+
<build>
51+
<plugins>
52+
<plugin>
53+
<groupId>org.springframework.boot</groupId>
54+
<artifactId>spring-boot-maven-plugin</artifactId>
55+
</plugin>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-surefire-plugin</artifactId>
59+
<dependencies>
60+
<dependency>
61+
<groupId>org.junit.platform</groupId>
62+
<artifactId>junit-platform-surefire-provider</artifactId>
63+
<version>${junit.platform.version}</version>
64+
</dependency>
65+
<dependency>
66+
<groupId>org.junit.jupiter</groupId>
67+
<artifactId>junit-jupiter-engine</artifactId>
68+
<version>${junit.jupiter.version}</version>
69+
</dependency>
70+
</dependencies>
71+
</plugin>
72+
</plugins>
73+
</build>
74+
75+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2012-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package sample;
18+
19+
import org.springframework.web.bind.annotation.GetMapping;
20+
import org.springframework.web.bind.annotation.RestController;
21+
22+
/**
23+
* @author Eddú Meléndez
24+
*/
25+
@RestController
26+
public class MessageController {
27+
28+
@GetMapping("/hi")
29+
public String hello() {
30+
return "Hello World";
31+
}
32+
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2012-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package sample;
18+
19+
import org.springframework.boot.SpringApplication;
20+
import org.springframework.boot.autoconfigure.SpringBootApplication;
21+
22+
@SpringBootApplication
23+
public class SampleJunitJupiterApplication {
24+
25+
public static void main(String[] args) {
26+
SpringApplication.run(SampleJunitJupiterApplication.class, args);
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2012-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package sample;
18+
19+
import org.junit.jupiter.api.Test;
20+
import org.junit.jupiter.api.extension.ExtendWith;
21+
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.boot.test.context.SpringBootTest;
24+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
25+
import org.springframework.boot.test.web.client.TestRestTemplate;
26+
import org.springframework.test.context.junit.jupiter.SpringExtension;
27+
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
30+
@ExtendWith(SpringExtension.class)
31+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
32+
class SampleJunitJupiterApplicationTests {
33+
34+
@Autowired
35+
private TestRestTemplate restTemplate;
36+
37+
@Test
38+
void testMessage() {
39+
String message = this.restTemplate.getForObject("/hi", String.class);
40+
assertThat(message).isEqualTo("Hello World");
41+
}
42+
43+
}

0 commit comments

Comments
 (0)