Skip to content

Commit c7bde71

Browse files
committed
Migrate tests to JUnit 5
Closes gh-959
1 parent d0c224d commit c7bde71

File tree

105 files changed

+4297
-4150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+4297
-4150
lines changed

spring-restdocs-asciidoctor/build.gradle

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ dependencies {
1010

1111
internal(platform(project(":spring-restdocs-platform")))
1212

13-
testImplementation("junit:junit")
1413
testImplementation("org.apache.pdfbox:pdfbox")
1514
testImplementation("org.assertj:assertj-core")
15+
testImplementation("org.junit.jupiter:junit-jupiter")
1616
testImplementation("org.springframework:spring-core")
1717

1818
testRuntimeOnly("org.asciidoctor:asciidoctorj-pdf")
19+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
20+
}
21+
22+
tasks.named("test") {
23+
useJUnitPlatform()
1924
}

spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/AbstractOperationBlockMacroTests.java

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,11 +35,10 @@
3535
import org.asciidoctor.Attributes;
3636
import org.asciidoctor.Options;
3737
import org.asciidoctor.SafeMode;
38-
import org.junit.After;
39-
import org.junit.Before;
40-
import org.junit.Rule;
41-
import org.junit.Test;
42-
import org.junit.rules.TemporaryFolder;
38+
import org.junit.jupiter.api.AfterEach;
39+
import org.junit.jupiter.api.BeforeEach;
40+
import org.junit.jupiter.api.Test;
41+
import org.junit.jupiter.api.io.TempDir;
4342

4443
import org.springframework.util.FileSystemUtils;
4544

@@ -51,42 +50,42 @@
5150
* @author Gerrit Meier
5251
* @author Andy Wilkinson
5352
*/
54-
public abstract class AbstractOperationBlockMacroTests {
53+
abstract class AbstractOperationBlockMacroTests {
5554

56-
@Rule
57-
public TemporaryFolder temp = new TemporaryFolder();
55+
private final Asciidoctor asciidoctor = Asciidoctor.Factory.create();
5856

59-
private Options options;
57+
@TempDir
58+
protected File temp;
6059

61-
private final Asciidoctor asciidoctor = Asciidoctor.Factory.create();
60+
private Options options;
6261

63-
@Before
64-
public void setUp() throws IOException {
62+
@BeforeEach
63+
void setUp() throws IOException {
6564
prepareOperationSnippets(getBuildOutputLocation());
6665
this.options = Options.builder().safe(SafeMode.UNSAFE).baseDir(getSourceLocation()).build();
6766
this.options.setAttributes(getAttributes());
6867
CapturingLogHandler.clear();
6968
}
7069

71-
@After
72-
public void verifyLogging() {
70+
@AfterEach
71+
void verifyLogging() {
7372
assertThat(CapturingLogHandler.getLogRecords()).isEmpty();
7473
}
7574

76-
public void prepareOperationSnippets(File buildOutputLocation) throws IOException {
75+
private void prepareOperationSnippets(File buildOutputLocation) throws IOException {
7776
File destination = new File(buildOutputLocation, "generated-snippets/some-operation");
7877
destination.mkdirs();
7978
FileSystemUtils.copyRecursively(new File("src/test/resources/some-operation"), destination);
8079
}
8180

8281
@Test
83-
public void codeBlockSnippetInclude() throws Exception {
82+
void codeBlockSnippetInclude() throws Exception {
8483
String result = this.asciidoctor.convert("operation::some-operation[snippets='curl-request']", this.options);
8584
assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-simple"));
8685
}
8786

8887
@Test
89-
public void operationWithParameterizedName() throws Exception {
88+
void operationWithParameterizedName() throws Exception {
9089
Attributes attributes = getAttributes();
9190
attributes.setAttribute("name", "some");
9291
this.options.setAttributes(attributes);
@@ -95,78 +94,78 @@ public void operationWithParameterizedName() throws Exception {
9594
}
9695

9796
@Test
98-
public void codeBlockSnippetIncludeWithPdfBackend() throws Exception {
97+
void codeBlockSnippetIncludeWithPdfBackend() throws Exception {
9998
File output = configurePdfOutput();
10099
this.asciidoctor.convert("operation::some-operation[snippets='curl-request']", this.options);
101100
assertThat(extractStrings(output)).containsExactly("Curl request", "$ curl 'http://localhost:8080/' -i", "1");
102101
}
103102

104103
@Test
105-
public void tableSnippetInclude() throws Exception {
104+
void tableSnippetInclude() throws Exception {
106105
String result = this.asciidoctor.convert("operation::some-operation[snippets='response-fields']", this.options);
107106
assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-table"));
108107
}
109108

110109
@Test
111-
public void tableSnippetIncludeWithPdfBackend() throws Exception {
110+
void tableSnippetIncludeWithPdfBackend() throws Exception {
112111
File output = configurePdfOutput();
113112
this.asciidoctor.convert("operation::some-operation[snippets='response-fields']", this.options);
114113
assertThat(extractStrings(output)).containsExactly("Response fields", "Path", "Type", "Description", "a",
115114
"Object", "one", "a.b", "Number", "two", "a.c", "String", "three", "1");
116115
}
117116

118117
@Test
119-
public void includeSnippetInSection() throws Exception {
118+
void includeSnippetInSection() throws Exception {
120119
String result = this.asciidoctor.convert("= A\n:doctype: book\n:sectnums:\n\nAlpha\n\n== B\n\nBravo\n\n"
121120
+ "operation::some-operation[snippets='curl-request']\n\n== C\n", this.options);
122121
assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-in-section"));
123122
}
124123

125124
@Test
126-
public void includeSnippetInSectionWithAbsoluteLevelOffset() throws Exception {
125+
void includeSnippetInSectionWithAbsoluteLevelOffset() throws Exception {
127126
String result = this.asciidoctor
128127
.convert("= A\n:doctype: book\n:sectnums:\n:leveloffset: 1\n\nAlpha\n\n= B\n\nBravo\n\n"
129128
+ "operation::some-operation[snippets='curl-request']\n\n= C\n", this.options);
130129
assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-in-section"));
131130
}
132131

133132
@Test
134-
public void includeSnippetInSectionWithRelativeLevelOffset() throws Exception {
133+
void includeSnippetInSectionWithRelativeLevelOffset() throws Exception {
135134
String result = this.asciidoctor
136135
.convert("= A\n:doctype: book\n:sectnums:\n:leveloffset: +1\n\nAlpha\n\n= B\n\nBravo\n\n"
137136
+ "operation::some-operation[snippets='curl-request']\n\n= C\n", this.options);
138137
assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-in-section"));
139138
}
140139

141140
@Test
142-
public void includeSnippetInSectionWithPdfBackend() throws Exception {
141+
void includeSnippetInSectionWithPdfBackend() throws Exception {
143142
File output = configurePdfOutput();
144143
this.asciidoctor.convert("== Section\n" + "operation::some-operation[snippets='curl-request']", this.options);
145144
assertThat(extractStrings(output)).containsExactly("Section", "Curl request",
146145
"$ curl 'http://localhost:8080/' -i", "1");
147146
}
148147

149148
@Test
150-
public void includeMultipleSnippets() throws Exception {
149+
void includeMultipleSnippets() throws Exception {
151150
String result = this.asciidoctor.convert("operation::some-operation[snippets='curl-request,http-request']",
152151
this.options);
153152
assertThat(result).isEqualTo(getExpectedContentFromFile("multiple-snippets"));
154153
}
155154

156155
@Test
157-
public void useMacroWithoutSnippetAttributeAddsAllSnippets() throws Exception {
156+
void useMacroWithoutSnippetAttributeAddsAllSnippets() throws Exception {
158157
String result = this.asciidoctor.convert("operation::some-operation[]", this.options);
159158
assertThat(result).isEqualTo(getExpectedContentFromFile("all-snippets"));
160159
}
161160

162161
@Test
163-
public void useMacroWithEmptySnippetAttributeAddsAllSnippets() throws Exception {
162+
void useMacroWithEmptySnippetAttributeAddsAllSnippets() throws Exception {
164163
String result = this.asciidoctor.convert("operation::some-operation[snippets=]", this.options);
165164
assertThat(result).isEqualTo(getExpectedContentFromFile("all-snippets"));
166165
}
167166

168167
@Test
169-
public void includingMissingSnippetAddsWarning() throws Exception {
168+
void includingMissingSnippetAddsWarning() throws Exception {
170169
String result = this.asciidoctor.convert("operation::some-operation[snippets='missing-snippet']", this.options);
171170
assertThat(result).startsWith(getExpectedContentFromFile("missing-snippet"));
172171
assertThat(CapturingLogHandler.getLogRecords()).hasSize(1);
@@ -177,13 +176,13 @@ public void includingMissingSnippetAddsWarning() throws Exception {
177176
}
178177

179178
@Test
180-
public void defaultTitleIsProvidedForCustomSnippet() throws Exception {
179+
void defaultTitleIsProvidedForCustomSnippet() throws Exception {
181180
String result = this.asciidoctor.convert("operation::some-operation[snippets='custom-snippet']", this.options);
182181
assertThat(result).isEqualTo(getExpectedContentFromFile("custom-snippet-default-title"));
183182
}
184183

185184
@Test
186-
public void missingOperationIsHandledGracefully() throws Exception {
185+
void missingOperationIsHandledGracefully() throws Exception {
187186
String result = this.asciidoctor.convert("operation::missing-operation[]", this.options);
188187
assertThat(result).startsWith(getExpectedContentFromFile("missing-operation"));
189188
assertThat(CapturingLogHandler.getLogRecords()).hasSize(1);
@@ -194,14 +193,14 @@ public void missingOperationIsHandledGracefully() throws Exception {
194193
}
195194

196195
@Test
197-
public void titleOfBuiltInSnippetCanBeCustomizedUsingDocumentAttribute() throws URISyntaxException, IOException {
196+
void titleOfBuiltInSnippetCanBeCustomizedUsingDocumentAttribute() throws URISyntaxException, IOException {
198197
String result = this.asciidoctor.convert(":operation-curl-request-title: Example request\n"
199198
+ "operation::some-operation[snippets='curl-request']", this.options);
200199
assertThat(result).isEqualTo(getExpectedContentFromFile("built-in-snippet-custom-title"));
201200
}
202201

203202
@Test
204-
public void titleOfCustomSnippetCanBeCustomizedUsingDocumentAttribute() throws Exception {
203+
void titleOfCustomSnippetCanBeCustomizedUsingDocumentAttribute() throws Exception {
205204
String result = this.asciidoctor.convert(":operation-custom-snippet-title: Customized title\n"
206205
+ "operation::some-operation[snippets='custom-snippet']", this.options);
207206
assertThat(result).isEqualTo(getExpectedContentFromFile("custom-snippet-custom-title"));

spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesPreprocessorTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.asciidoctor.Asciidoctor;
2222
import org.asciidoctor.Attributes;
2323
import org.asciidoctor.Options;
24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525

2626
import static org.assertj.core.api.Assertions.assertThat;
2727

@@ -30,23 +30,23 @@
3030
*
3131
* @author Andy Wilkinson
3232
*/
33-
public class DefaultAttributesPreprocessorTests {
33+
class DefaultAttributesPreprocessorTests {
3434

3535
@Test
36-
public void snippetsAttributeIsSet() {
36+
void snippetsAttributeIsSet() {
3737
String converted = createAsciidoctor().convert("{snippets}", createOptions("projectdir=../../.."));
3838
assertThat(converted).contains("build" + File.separatorChar + "generated-snippets");
3939
}
4040

4141
@Test
42-
public void snippetsAttributeFromConvertArgumentIsNotOverridden() {
42+
void snippetsAttributeFromConvertArgumentIsNotOverridden() {
4343
String converted = createAsciidoctor().convert("{snippets}",
4444
createOptions("snippets=custom projectdir=../../.."));
4545
assertThat(converted).contains("custom");
4646
}
4747

4848
@Test
49-
public void snippetsAttributeFromDocumentPreambleIsNotOverridden() {
49+
void snippetsAttributeFromDocumentPreambleIsNotOverridden() {
5050
String converted = createAsciidoctor().convert(":snippets: custom\n{snippets}",
5151
createOptions("projectdir=../../.."));
5252
assertThat(converted).contains("custom");

spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/GradleOperationBlockMacroTests.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2023 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,47 +19,42 @@
1919
import java.io.File;
2020

2121
import org.asciidoctor.Attributes;
22-
import org.junit.runner.RunWith;
23-
import org.junit.runners.Parameterized;
24-
import org.junit.runners.Parameterized.Parameters;
22+
import org.junit.jupiter.params.ParameterizedClass;
23+
import org.junit.jupiter.params.provider.ValueSource;
2524

2625
/**
2726
* Tests for Ruby operation block macro when used in a Gradle build.
2827
*
2928
* @author Andy Wilkinson
3029
*/
31-
@RunWith(Parameterized.class)
32-
public class GradleOperationBlockMacroTests extends AbstractOperationBlockMacroTests {
30+
@ParameterizedClass
31+
@ValueSource(strings = { "projectdir", "gradle-projectdir" })
32+
class GradleOperationBlockMacroTests extends AbstractOperationBlockMacroTests {
3333

3434
private final String attributeName;
3535

36-
public GradleOperationBlockMacroTests(String attributeName) {
36+
GradleOperationBlockMacroTests(String attributeName) {
3737
this.attributeName = attributeName;
3838
}
3939

40-
@Parameters(name = "{0}")
41-
public static Object[] parameters() {
42-
return new Object[] { "projectdir", "gradle-projectdir" };
43-
}
44-
4540
@Override
4641
protected Attributes getAttributes() {
4742
Attributes attributes = Attributes.builder()
48-
.attribute(this.attributeName, new File(this.temp.getRoot(), "gradle-project").getAbsolutePath())
43+
.attribute(this.attributeName, new File(this.temp, "gradle-project").getAbsolutePath())
4944
.build();
5045
return attributes;
5146
}
5247

5348
@Override
5449
protected File getBuildOutputLocation() {
55-
File outputLocation = new File(this.temp.getRoot(), "gradle-project/build");
50+
File outputLocation = new File(this.temp, "gradle-project/build");
5651
outputLocation.mkdirs();
5752
return outputLocation;
5853
}
5954

6055
@Override
6156
protected File getSourceLocation() {
62-
File sourceLocation = new File(this.temp.getRoot(), "gradle-project/src/docs/asciidoc");
57+
File sourceLocation = new File(this.temp, "gradle-project/src/docs/asciidoc");
6358
if (!sourceLocation.exists()) {
6459
sourceLocation.mkdirs();
6560
}

spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/MavenOperationBlockMacroTests.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2021 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,23 +20,23 @@
2020
import java.io.IOException;
2121

2222
import org.asciidoctor.Attributes;
23-
import org.junit.After;
24-
import org.junit.Before;
23+
import org.junit.jupiter.api.AfterEach;
24+
import org.junit.jupiter.api.BeforeEach;
2525

2626
/**
2727
* Tests for Ruby operation block macro when used in a Maven build.
2828
*
2929
* @author Andy Wilkinson
3030
*/
31-
public class MavenOperationBlockMacroTests extends AbstractOperationBlockMacroTests {
31+
class MavenOperationBlockMacroTests extends AbstractOperationBlockMacroTests {
3232

33-
@Before
34-
public void setMavenHome() {
33+
@BeforeEach
34+
void setMavenHome() {
3535
System.setProperty("maven.home", "maven-home");
3636
}
3737

38-
@After
39-
public void clearMavenHome() {
38+
@AfterEach
39+
void clearMavenHome() {
4040
System.clearProperty("maven.home");
4141
}
4242

@@ -55,14 +55,14 @@ protected Attributes getAttributes() {
5555

5656
@Override
5757
protected File getBuildOutputLocation() {
58-
File outputLocation = new File(this.temp.getRoot(), "maven-project/target");
58+
File outputLocation = new File(this.temp, "maven-project/target");
5959
outputLocation.mkdirs();
6060
return outputLocation;
6161
}
6262

6363
@Override
6464
protected File getSourceLocation() {
65-
File sourceLocation = new File(this.temp.getRoot(), "maven-project/src/main/asciidoc");
65+
File sourceLocation = new File(this.temp, "maven-project/src/main/asciidoc");
6666
if (!sourceLocation.exists()) {
6767
sourceLocation.mkdirs();
6868
}

0 commit comments

Comments
 (0)