Skip to content

Commit 71fad7e

Browse files
committed
added code examples for @SpringBootTest article
1 parent 93f8074 commit 71fad7e

36 files changed

+301
-34
lines changed

.idea/libraries/Gradle__org_projectlombok_lombok_1_16_20.xml

Lines changed: 0 additions & 11 deletions
This file was deleted.

.idea/modules/spring-boot-testing.iml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spring-boot/spring-boot-testing/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Blog Posts
44
* [Structuring and Testing Modules and Layers with Spring Boot](https://reflectoring.io/testing-verticals-and-layers-spring-boot/)
5-
* [All You Need To Know About Unit Testing with Spring Boot](https://reflectoring.io/unit-testing-spring-boot/)
6-
* [All You Need To Know About Testing Web Controllers with Spring Boot](https://reflectoring.io/spring-boot-web-controller-test/)
7-
* [All You Need To Know About Testing JPA Queries with Spring Boot](https://reflectoring.io/spring-boot-data-jpa-test/)
5+
* [Unit Testing with Spring Boot](https://reflectoring.io/unit-testing-spring-boot/)
6+
* [Testing Spring MVC Web Controllers with @WebMvcTest](https://reflectoring.io/spring-boot-web-controller-test/)
7+
* [Testing JPA Queries with @DataJpaTest](https://reflectoring.io/spring-boot-data-jpa-test/)
8+
* [Integration Tests with @SpringBoot](https://reflectoring.io/spring-boot-test/)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
spring.main.allow-bean-definition-overriding: true
2+
spring.jpa.hibernate.ddl-auto: create-drop
3+
spring.liquibase.enabled: false
4+
spring.flyway.enabled: false
5+
foo: bar
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
spring.main.allow-bean-definition-overriding: true
2+
spring.jpa.hibernate.ddl-auto: create-drop
3+
spring.liquibase.enabled: false
4+
spring.flyway.enabled: false
5+
io.reflectoring.scheduling.enabled: false

spring-boot/spring-boot-testing/build.gradle

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
buildscript {
22
ext {
3-
springBootVersion = '2.0.2.RELEASE'
3+
springBootVersion = '2.1.3.RELEASE'
44
}
55
repositories {
66
mavenCentral()
@@ -20,10 +20,10 @@ version = '0.0.1-SNAPSHOT'
2020
sourceCompatibility = 1.8
2121

2222
repositories {
23+
jcenter()
2324
mavenCentral()
2425
}
2526

26-
2727
dependencies {
2828
compile('org.springframework.boot:spring-boot-starter-data-jpa')
2929
compile('org.springframework.boot:spring-boot-starter-web')
@@ -34,6 +34,15 @@ dependencies {
3434
compileOnly('org.projectlombok:lombok')
3535
runtime('com.h2database:h2')
3636
testCompile('org.springframework.boot:spring-boot-starter-test')
37-
testCompile 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
37+
testCompile('org.junit.jupiter:junit-jupiter:5.4.0')
38+
testCompile('org.junit.platform:junit-platform-launcher:1.4.0')
3839
testCompile('org.mockito:mockito-junit-jupiter:2.23.0')
40+
testCompile('de.adesso:junit-insights:1.0.0')
41+
annotationProcessor 'org.projectlombok:lombok:1.18.6'
42+
}
43+
44+
test {
45+
systemProperty 'de.adesso.junitinsights.enabled', 'true'
46+
systemProperty 'junit.jupiter.extensions.autodetection.enabled', 'true'
47+
useJUnitPlatform()
3948
}
53.4 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Tue Feb 06 12:27:20 CET 2018
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.reflectoring;
2+
3+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.scheduling.annotation.EnableScheduling;
6+
7+
@Configuration
8+
@EnableScheduling
9+
@ConditionalOnProperty(
10+
name = "io.reflectoring.scheduling.enabled",
11+
havingValue = "true",
12+
matchIfMissing = true)
13+
public class SchedulingConfiguration {
14+
}

spring-boot/spring-boot-testing/src/main/java/io/reflectoring/testing/domain/RegisterUseCase.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,15 @@ public class RegisterUseCase {
1111

1212
private final SaveUserPort saveUserPort;
1313

14+
private final SendMailPort sendMailPort;
15+
1416
public Long registerUser(User user, boolean sendWelcomeMail) {
1517
user.setRegistrationDate(LocalDateTime.now());
18+
19+
if(sendWelcomeMail){
20+
sendMailPort.sendMail("Welcome!", "Thanks for registering.");
21+
}
22+
1623
return saveUserPort.saveUser(user);
1724
}
1825

0 commit comments

Comments
 (0)