Skip to content

Commit d05f6cd

Browse files
izeyewilkinsona
authored andcommitted
Consistently use ID-based equality check for TemplateFormat
Closes gh-530
1 parent 93cb08a commit d05f6cd

File tree

10 files changed

+16
-18
lines changed

10 files changed

+16
-18
lines changed

spring-restdocs-core/src/main/java/org/springframework/restdocs/templates/TemplateFormats.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.restdocs.templates;
1818

1919
/**
20-
* An enumeration of the built-in formats for which templates are provuded.
20+
* An enumeration of the built-in formats for which templates are provided.
2121
*
2222
* @author Andy Wilkinson
2323
* @since 1.1.0

spring-restdocs-core/src/test/java/org/springframework/restdocs/config/RestDocumentationConfigurerTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ public void defaultConfiguration() {
8686
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
8787
.get(SnippetConfiguration.class.getName());
8888
assertThat(snippetConfiguration.getEncoding(), is(equalTo("UTF-8")));
89-
assertThat(snippetConfiguration.getTemplateFormat(),
90-
is(equalTo(TemplateFormats.asciidoctor())));
89+
assertThat(snippetConfiguration.getTemplateFormat().getId(),
90+
is(equalTo(TemplateFormats.asciidoctor().getId())));
9191
}
9292

9393
@Test
@@ -168,8 +168,8 @@ public void customTemplateFormat() {
168168
instanceOf(SnippetConfiguration.class)));
169169
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
170170
.get(SnippetConfiguration.class.getName());
171-
assertThat(snippetConfiguration.getTemplateFormat(),
172-
is(equalTo(TemplateFormats.markdown())));
171+
assertThat(snippetConfiguration.getTemplateFormat().getId(),
172+
is(equalTo(TemplateFormats.markdown().getId())));
173173
}
174174

175175
@SuppressWarnings("unchecked")

spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/RequestHeadersSnippetTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public void tableCellContentIsEscapedWhenNecessary() throws IOException {
173173
}
174174

175175
private String escapeIfNecessary(String input) {
176-
if (this.templateFormat.equals(TemplateFormats.markdown())) {
176+
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
177177
return input;
178178
}
179179
return input.replace("|", "\\|");

spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/ResponseHeadersSnippetTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public void tableCellContentIsEscapedWhenNecessary() throws IOException {
164164
}
165165

166166
private String escapeIfNecessary(String input) {
167-
if (this.templateFormat.equals(TemplateFormats.markdown())) {
167+
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
168168
return input;
169169
}
170170
return input.replace("|", "\\|");

spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void tableCellContentIsEscapedWhenNecessary() throws IOException {
178178
}
179179

180180
private String escapeIfNecessary(String input) {
181-
if (this.templateFormat.equals(TemplateFormats.markdown())) {
181+
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
182182
return input;
183183
}
184184
return input.replace("|", "\\|");

spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestFieldsSnippetTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ public void typeDeterminationDoesNotSetTypeOnDescriptor() throws IOException {
461461
}
462462

463463
private String escapeIfNecessary(String input) {
464-
if (this.templateFormat.equals(TemplateFormats.markdown())) {
464+
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
465465
return input;
466466
}
467467
return input.replace("|", "\\|");

spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ public void typeDeterminationDoesNotSetTypeOnDescriptor() throws IOException {
472472
}
473473

474474
private String escapeIfNecessary(String input) {
475-
if (this.templateFormat.equals(TemplateFormats.markdown())) {
475+
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
476476
return input;
477477
}
478478
return input.replace("|", "\\|");

spring-restdocs-core/src/test/java/org/springframework/restdocs/request/PathParametersSnippetTests.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ public void allUndocumentedPathParametersCanBeIgnored() throws IOException {
8787
public void missingOptionalPathParameter() throws IOException {
8888
this.snippets.expectPathParameters()
8989
.withContents(tableWithTitleAndHeader(
90-
this.templateFormat == TemplateFormats.asciidoctor() ? "+/{a}+"
91-
: "`/{a}`",
90+
getTitle("/{a}"),
9291
"Parameter", "Description").row("`a`", "one").row("`b`", "two"));
9392
new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"),
9493
parameterWithName("b").description("two").optional()))
@@ -101,8 +100,7 @@ public void missingOptionalPathParameter() throws IOException {
101100
public void presentOptionalPathParameter() throws IOException {
102101
this.snippets.expectPathParameters()
103102
.withContents(tableWithTitleAndHeader(
104-
this.templateFormat == TemplateFormats.asciidoctor() ? "+/{a}+"
105-
: "`/{a}`",
103+
getTitle("/{a}"),
106104
"Parameter", "Description").row("`a`", "one"));
107105
new PathParametersSnippet(
108106
Arrays.asList(parameterWithName("a").description("one").optional()))
@@ -208,7 +206,7 @@ public void pathParametersWithEscapedContent() throws IOException {
208206
}
209207

210208
private String escapeIfNecessary(String input) {
211-
if (this.templateFormat.equals(TemplateFormats.markdown())) {
209+
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
212210
return input;
213211
}
214212
return input.replace("|", "\\|");
@@ -219,7 +217,7 @@ private String getTitle() {
219217
}
220218

221219
private String getTitle(String title) {
222-
if (this.templateFormat.equals(TemplateFormats.asciidoctor())) {
220+
if (this.templateFormat.getId().equals(TemplateFormats.asciidoctor().getId())) {
223221
return "+" + title + "+";
224222
}
225223
return "`" + title + "`";

spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestParametersSnippetTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public void requestParametersWithEscapedContent() throws IOException {
200200
}
201201

202202
private String escapeIfNecessary(String input) {
203-
if (this.templateFormat.equals(TemplateFormats.markdown())) {
203+
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
204204
return input;
205205
}
206206
return input.replace("|", "\\|");

spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestPartsSnippetTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void requestPartsWithEscapedContent() throws IOException {
191191
}
192192

193193
private String escapeIfNecessary(String input) {
194-
if (this.templateFormat.equals(TemplateFormats.markdown())) {
194+
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
195195
return input;
196196
}
197197
return input.replace("|", "\\|");

0 commit comments

Comments
 (0)