Skip to content

Commit 1d52ba8

Browse files
committed
Merge pull request #530 from Johnny Lim
* gh-530: Polish "Consistently use ID-based equality check for TemplateFormat" Consistently use ID-based equality check for TemplateFormat
2 parents 93cb08a + d57fa02 commit 1d52ba8

File tree

10 files changed

+21
-25
lines changed

10 files changed

+21
-25
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2016 the original author or authors.
2+
* Copyright 2014-2018 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.
@@ -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: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,9 @@ public void allUndocumentedPathParametersCanBeIgnored() throws IOException {
8585

8686
@Test
8787
public void missingOptionalPathParameter() throws IOException {
88-
this.snippets.expectPathParameters()
89-
.withContents(tableWithTitleAndHeader(
90-
this.templateFormat == TemplateFormats.asciidoctor() ? "+/{a}+"
91-
: "`/{a}`",
92-
"Parameter", "Description").row("`a`", "one").row("`b`", "two"));
88+
this.snippets.expectPathParameters().withContents(
89+
tableWithTitleAndHeader(getTitle("/{a}"), "Parameter", "Description")
90+
.row("`a`", "one").row("`b`", "two"));
9391
new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"),
9492
parameterWithName("b").description("two").optional()))
9593
.document(this.operationBuilder.attribute(
@@ -99,11 +97,9 @@ public void missingOptionalPathParameter() throws IOException {
9997

10098
@Test
10199
public void presentOptionalPathParameter() throws IOException {
102-
this.snippets.expectPathParameters()
103-
.withContents(tableWithTitleAndHeader(
104-
this.templateFormat == TemplateFormats.asciidoctor() ? "+/{a}+"
105-
: "`/{a}`",
106-
"Parameter", "Description").row("`a`", "one"));
100+
this.snippets.expectPathParameters().withContents(
101+
tableWithTitleAndHeader(getTitle("/{a}"), "Parameter", "Description")
102+
.row("`a`", "one"));
107103
new PathParametersSnippet(
108104
Arrays.asList(parameterWithName("a").description("one").optional()))
109105
.document(this.operationBuilder.attribute(
@@ -208,7 +204,7 @@ public void pathParametersWithEscapedContent() throws IOException {
208204
}
209205

210206
private String escapeIfNecessary(String input) {
211-
if (this.templateFormat.equals(TemplateFormats.markdown())) {
207+
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
212208
return input;
213209
}
214210
return input.replace("|", "\\|");
@@ -219,7 +215,7 @@ private String getTitle() {
219215
}
220216

221217
private String getTitle(String title) {
222-
if (this.templateFormat.equals(TemplateFormats.asciidoctor())) {
218+
if (this.templateFormat.getId().equals(TemplateFormats.asciidoctor().getId())) {
223219
return "+" + title + "+";
224220
}
225221
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)