Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 0b0b336

Browse files
authored
Upgrade to Spring REST Docs 2.0.3 (#306)
Spring REST Docs moved from Hamcrest to AssertJ: spring-projects/spring-restdocs@7431426
1 parent acbd561 commit 0b0b336

17 files changed

+391
-416
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ cache:
1313
- $HOME/.gradle/caches/
1414
- $HOME/.gradle/wrapper/
1515
before_install:
16-
- mvn install:install-file -Dfile=lib/spring-restdocs-core-2.0.2.RELEASE-test.jar
17-
-DgroupId=org.springframework.restdocs -DartifactId=spring-restdocs-core -Dversion=2.0.2.RELEASE
16+
- mvn install:install-file -Dfile=lib/spring-restdocs-core-2.0.3.RELEASE-test.jar
17+
-DgroupId=org.springframework.restdocs -DartifactId=spring-restdocs-core -Dversion=2.0.3.RELEASE
1818
-Dpackaging=jar -Dclassifier=test
1919
script:
2020
- mvn install -B -V
-213 KB
Binary file not shown.
212 KB
Binary file not shown.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<properties>
4949
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5050
<snippetsDirectory>${project.build.directory}/generated-snippets</snippetsDirectory>
51-
<spring-restdocs.version>2.0.2.RELEASE</spring-restdocs.version>
51+
<spring-restdocs.version>2.0.3.RELEASE</spring-restdocs.version>
5252
</properties>
5353

5454
<build>
@@ -273,7 +273,7 @@
273273
<dependency>
274274
<groupId>com.fasterxml.jackson.core</groupId>
275275
<artifactId>jackson-databind</artifactId>
276-
<version>2.9.7</version>
276+
<version>2.9.8</version>
277277
</dependency>
278278
<dependency>
279279
<groupId>org.springframework</groupId>

spring-auto-restdocs-core/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@
103103
<version>9.0.12</version>
104104
<scope>test</scope>
105105
</dependency>
106+
<dependency>
107+
<groupId>org.assertj</groupId>
108+
<artifactId>assertj-core</artifactId>
109+
<version>2.9.1</version>
110+
<scope>test</scope>
111+
</dependency>
106112
</dependencies>
107113

108114
<build>

spring-auto-restdocs-core/src/test/java/capital/scalable/restdocs/hypermedia/EmbeddedSnippetTest.java

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,10 +20,7 @@
2020
package capital.scalable.restdocs.hypermedia;
2121

2222
import static capital.scalable.restdocs.SnippetRegistry.AUTO_EMBEDDED;
23-
import static java.util.Collections.singletonList;
24-
import static org.hamcrest.CoreMatchers.equalTo;
25-
import static org.hamcrest.CoreMatchers.is;
26-
import static org.junit.Assert.assertThat;
23+
import static org.assertj.core.api.Assertions.assertThat;
2724
import static org.mockito.Mockito.mock;
2825
import static org.mockito.Mockito.when;
2926

@@ -69,26 +66,27 @@ public void embedded() throws Exception {
6966
mockFieldComment(EmbeddedDocs.class, "embedded1", "Resource 1");
7067
mockFieldComment(EmbeddedDocs.class, "embedded2", "Resource 2");
7168

72-
this.snippets.expect(AUTO_EMBEDDED).withContents(
73-
tableWithHeader("Path", "Type", "Optional", "Description")
74-
.row("embedded1", "Array[Object]", "true", "Resource 1.")
75-
.row("embedded2", "Object", "true", "Resource 2."));
76-
7769
new EmbeddedSnippet().documentationType(EmbeddedDocs.class).document(operationBuilder
7870
.attribute(HandlerMethod.class.getName(), handlerMethod)
7971
.attribute(ObjectMapper.class.getName(), mapper)
8072
.attribute(JavadocReader.class.getName(), javadocReader)
8173
.attribute(ConstraintReader.class.getName(), constraintReader)
8274
.build());
75+
76+
assertThat(this.generatedSnippets.snippet(AUTO_EMBEDDED)).is(
77+
tableWithHeader("Path", "Type", "Optional", "Description")
78+
.row("embedded1", "Array[Object]", "true", "Resource 1.")
79+
.row("embedded2", "Object", "true", "Resource 2."));
8380
}
8481

8582
@Test
8683
public void noHandlerMethod() throws Exception {
87-
this.snippets.expect(AUTO_EMBEDDED).withContents(equalTo("No embedded resources."));
88-
8984
new EmbeddedSnippet().document(operationBuilder
9085
.attribute(ObjectMapper.class.getName(), mapper)
9186
.build());
87+
88+
assertThat(this.generatedSnippets.snippet(AUTO_EMBEDDED))
89+
.isEqualTo("No embedded resources.");
9290
}
9391

9492
@Test
@@ -98,7 +96,7 @@ public void noContent() throws Exception {
9896
boolean hasContent = new EmbeddedSnippet().hasContent(operationBuilder
9997
.attribute(HandlerMethod.class.getName(), handlerMethod)
10098
.build());
101-
assertThat(hasContent, is(false));
99+
assertThat(hasContent).isFalse();
102100
}
103101

104102
@Test
@@ -117,11 +115,6 @@ public void failOnUndocumentedFields() throws Exception {
117115
.build());
118116
}
119117

120-
private void mockOptionalMessage(Class<?> type, String fieldName, String comment) {
121-
when(constraintReader.getOptionalMessages(type, fieldName))
122-
.thenReturn(singletonList(comment));
123-
}
124-
125118
private void mockFieldComment(Class<?> type, String fieldName, String comment) {
126119
when(javadocReader.resolveFieldComment(type, fieldName))
127120
.thenReturn(comment);

spring-auto-restdocs-core/src/test/java/capital/scalable/restdocs/hypermedia/LinksSnippetTest.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,10 +20,7 @@
2020
package capital.scalable.restdocs.hypermedia;
2121

2222
import static capital.scalable.restdocs.SnippetRegistry.AUTO_LINKS;
23-
import static java.util.Collections.singletonList;
24-
import static org.hamcrest.CoreMatchers.equalTo;
25-
import static org.hamcrest.CoreMatchers.is;
26-
import static org.junit.Assert.assertThat;
23+
import static org.assertj.core.api.Assertions.assertThat;
2724
import static org.mockito.Mockito.mock;
2825
import static org.mockito.Mockito.when;
2926

@@ -67,26 +64,26 @@ public void links() throws Exception {
6764
mockFieldComment(LinksDocs.class, "link1", "Link 1");
6865
mockFieldComment(LinksDocs.class, "link2", "Link 2");
6966

70-
this.snippets.expect(AUTO_LINKS).withContents(
71-
tableWithHeader("Path", "Optional", "Description")
72-
.row("link1", "true", "Link 1.")
73-
.row("link2", "true", "Link 2."));
74-
7567
new LinksSnippet().documentationType(LinksDocs.class).document(operationBuilder
7668
.attribute(HandlerMethod.class.getName(), handlerMethod)
7769
.attribute(ObjectMapper.class.getName(), mapper)
7870
.attribute(JavadocReader.class.getName(), javadocReader)
7971
.attribute(ConstraintReader.class.getName(), constraintReader)
8072
.build());
73+
74+
assertThat(this.generatedSnippets.snippet(AUTO_LINKS)).is(
75+
tableWithHeader("Path", "Optional", "Description")
76+
.row("link1", "true", "Link 1.")
77+
.row("link2", "true", "Link 2."));
8178
}
8279

8380
@Test
8481
public void noHandlerMethod() throws Exception {
85-
this.snippets.expect(AUTO_LINKS).withContents(equalTo("No links."));
86-
8782
new LinksSnippet().document(operationBuilder
8883
.attribute(ObjectMapper.class.getName(), mapper)
8984
.build());
85+
86+
assertThat(this.generatedSnippets.snippet(AUTO_LINKS)).isEqualTo("No links.");
9087
}
9188

9289
@Test
@@ -96,7 +93,7 @@ public void noContent() throws Exception {
9693
boolean hasContent = new LinksSnippet().hasContent(operationBuilder
9794
.attribute(HandlerMethod.class.getName(), handlerMethod)
9895
.build());
99-
assertThat(hasContent, is(false));
96+
assertThat(hasContent).isFalse();
10097
}
10198

10299
@Test
@@ -114,11 +111,6 @@ public void failOnUndocumentedFields() throws Exception {
114111
.build());
115112
}
116113

117-
private void mockOptionalMessage(Class<?> type, String fieldName, String comment) {
118-
when(constraintReader.getOptionalMessages(type, fieldName))
119-
.thenReturn(singletonList(comment));
120-
}
121-
122114
private void mockFieldComment(Class<?> type, String fieldName, String comment) {
123115
when(javadocReader.resolveFieldComment(type, fieldName))
124116
.thenReturn(comment);

spring-auto-restdocs-core/src/test/java/capital/scalable/restdocs/misc/AuthorizationSnippetTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,7 +20,7 @@
2020
package capital.scalable.restdocs.misc;
2121

2222
import static capital.scalable.restdocs.SnippetRegistry.AUTO_AUTHORIZATION;
23-
import static org.hamcrest.CoreMatchers.equalTo;
23+
import static org.assertj.core.api.Assertions.assertThat;
2424

2525
import org.junit.Test;
2626
import org.springframework.restdocs.AbstractSnippetTests;
@@ -36,26 +36,25 @@ public AuthorizationSnippetTest(String name, TemplateFormat templateFormat) {
3636
public void authorization() throws Exception {
3737
String authorization = "User access token required.";
3838

39-
this.snippets.expect(AUTO_AUTHORIZATION)
40-
.withContents(equalTo(authorization));
41-
4239
new AuthorizationSnippet("Resource is public.")
4340
.document(operationBuilder
4441
.attribute(AuthorizationSnippet.class.getName(), authorization)
4542
.request("http://localhost/test")
4643
.build());
44+
45+
assertThat(this.generatedSnippets.snippet(AUTO_AUTHORIZATION)).isEqualTo(authorization);
4746
}
4847

4948
@Test
5049
public void defaultAuthorization() throws Exception {
5150
String defaultAuthorization = "Resource is public.";
5251

53-
this.snippets.expect(AUTO_AUTHORIZATION)
54-
.withContents(equalTo(defaultAuthorization));
55-
5652
new AuthorizationSnippet(defaultAuthorization)
5753
.document(operationBuilder
5854
.request("http://localhost/test")
5955
.build());
56+
57+
assertThat(this.generatedSnippets.snippet(AUTO_AUTHORIZATION))
58+
.isEqualTo(defaultAuthorization);
6059
}
6160
}

spring-auto-restdocs-core/src/test/java/capital/scalable/restdocs/misc/DescriptionSnippetTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,7 +20,7 @@
2020
package capital.scalable.restdocs.misc;
2121

2222
import static capital.scalable.restdocs.SnippetRegistry.AUTO_DESCRIPTION;
23-
import static org.hamcrest.CoreMatchers.equalTo;
23+
import static org.assertj.core.api.Assertions.assertThat;
2424
import static org.mockito.Mockito.mock;
2525
import static org.mockito.Mockito.when;
2626

@@ -43,13 +43,13 @@ public void description() throws Exception {
4343
mockMethodComment(TestResource.class, "testDescription", "sample method comment");
4444
mockMethodTag(TestResource.class, "testDescription", "deprecated", "");
4545

46-
this.snippets.expect(AUTO_DESCRIPTION).withContents(equalTo("Sample method comment."));
47-
4846
new DescriptionSnippet().document(operationBuilder
4947
.attribute(HandlerMethod.class.getName(), handlerMethod)
5048
.attribute(JavadocReader.class.getName(), javadocReader)
5149
.request("http://localhost/test")
5250
.build());
51+
52+
assertThat(this.generatedSnippets.snippet(AUTO_DESCRIPTION)).isEqualTo("Sample method comment.");
5353
}
5454

5555
@Test
@@ -58,14 +58,14 @@ public void descriptionWithDeprecated() throws Exception {
5858
mockMethodComment(TestResource.class, "testDescription", "sample method comment");
5959
mockMethodTag(TestResource.class, "testDescription", "deprecated", "use different one");
6060

61-
this.snippets.expect(AUTO_DESCRIPTION).withContents(equalTo(
62-
"**Deprecated.** Use different one.\n\nSample method comment."));
63-
6461
new DescriptionSnippet().document(operationBuilder
6562
.attribute(HandlerMethod.class.getName(), handlerMethod)
6663
.attribute(JavadocReader.class.getName(), javadocReader)
6764
.request("http://localhost/test")
6865
.build());
66+
67+
assertThat(this.generatedSnippets.snippet(AUTO_DESCRIPTION))
68+
.isEqualTo("**Deprecated.** Use different one.\n\nSample method comment.");
6969
}
7070

7171
@Test
@@ -74,23 +74,23 @@ public void descriptionWithSeeTag() throws Exception {
7474
mockMethodComment(TestResource.class, "testDescription", "sample method comment");
7575
mockMethodTag(TestResource.class, "testDescription", "see", "something");
7676

77-
this.snippets.expect(AUTO_DESCRIPTION).withContents(equalTo(
78-
"Sample method comment.\n\nSee something."));
79-
8077
new DescriptionSnippet().document(operationBuilder
8178
.attribute(HandlerMethod.class.getName(), handlerMethod)
8279
.attribute(JavadocReader.class.getName(), javadocReader)
8380
.request("http://localhost/test")
8481
.build());
82+
83+
assertThat(this.generatedSnippets.snippet(AUTO_DESCRIPTION))
84+
.isEqualTo("Sample method comment.\n\nSee something.");
8585
}
8686

8787
@Test
8888
public void noHandlerMethod() throws Exception {
89-
this.snippets.expect(AUTO_DESCRIPTION).withContents(equalTo(""));
90-
9189
new DescriptionSnippet().document(operationBuilder
9290
.request("http://localhost/test")
9391
.build());
92+
93+
assertThat(this.generatedSnippets.snippet(AUTO_DESCRIPTION)).isEqualTo("");
9494
}
9595

9696
private void mockMethodComment(Class<TestResource> javaBaseClass, String methodName,

spring-auto-restdocs-core/src/test/java/capital/scalable/restdocs/misc/MethodAndPathSnippetTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,7 +21,7 @@
2121

2222
import static capital.scalable.restdocs.OperationAttributeHelper.REQUEST_PATTERN;
2323
import static capital.scalable.restdocs.SnippetRegistry.AUTO_METHOD_PATH;
24-
import static org.hamcrest.CoreMatchers.equalTo;
24+
import static org.assertj.core.api.Assertions.assertThat;
2525

2626
import org.junit.Test;
2727
import org.springframework.restdocs.AbstractSnippetTests;
@@ -38,25 +38,25 @@ public MethodAndPathSnippetTest(String name, TemplateFormat templateFormat) {
3838
public void simpleRequest() throws Exception {
3939
HandlerMethod handlerMethod = new HandlerMethod(new TestResource(), "testMethod");
4040

41-
this.snippets.expect(AUTO_METHOD_PATH).withContents(equalTo("`POST /test`"));
42-
4341
new MethodAndPathSnippet().document(operationBuilder
4442
.attribute(HandlerMethod.class.getName(), handlerMethod)
4543
.attribute(REQUEST_PATTERN, "/test")
4644
.request("http://localhost/test")
4745
.method("POST")
4846
.build());
47+
48+
assertThat(this.generatedSnippets.snippet(AUTO_METHOD_PATH)).isEqualTo("`POST /test`");
4949
}
5050

5151
@Test
5252
public void noHandlerMethod() throws Exception {
53-
this.snippets.expect(AUTO_METHOD_PATH).withContents(equalTo("`POST /test`"));
54-
5553
new MethodAndPathSnippet().document(operationBuilder
5654
.attribute(REQUEST_PATTERN, "/test")
5755
.request("http://localhost/test")
5856
.method("POST")
5957
.build());
58+
59+
assertThat(this.generatedSnippets.snippet(AUTO_METHOD_PATH)).isEqualTo("`POST /test`");
6060
}
6161

6262
private static class TestResource {

0 commit comments

Comments
 (0)