Skip to content

Use ID-based equality check for TemplateFormat consistently #530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package org.springframework.restdocs.templates;

/**
* An enumeration of the built-in formats for which templates are provuded.
* An enumeration of the built-in formats for which templates are provided.
*
* @author Andy Wilkinson
* @since 1.1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ public void defaultConfiguration() {
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
.get(SnippetConfiguration.class.getName());
assertThat(snippetConfiguration.getEncoding(), is(equalTo("UTF-8")));
assertThat(snippetConfiguration.getTemplateFormat(),
is(equalTo(TemplateFormats.asciidoctor())));
assertThat(snippetConfiguration.getTemplateFormat().getId(),
is(equalTo(TemplateFormats.asciidoctor().getId())));

OperationRequestPreprocessor defaultOperationRequestPreprocessor = (OperationRequestPreprocessor) configuration
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_REQUEST_PREPROCESSOR);
Expand Down Expand Up @@ -190,8 +190,8 @@ public void customTemplateFormat() {
instanceOf(SnippetConfiguration.class)));
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
.get(SnippetConfiguration.class.getName());
assertThat(snippetConfiguration.getTemplateFormat(),
is(equalTo(TemplateFormats.markdown())));
assertThat(snippetConfiguration.getTemplateFormat().getId(),
is(equalTo(TemplateFormats.markdown().getId())));
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void tableCellContentIsEscapedWhenNecessary() throws IOException {
}

private String escapeIfNecessary(String input) {
if (this.templateFormat.equals(TemplateFormats.markdown())) {
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
return input;
}
return input.replace("|", "\\|");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void tableCellContentIsEscapedWhenNecessary() throws IOException {
}

private String escapeIfNecessary(String input) {
if (this.templateFormat.equals(TemplateFormats.markdown())) {
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
return input;
}
return input.replace("|", "\\|");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void tableCellContentIsEscapedWhenNecessary() throws IOException {
}

private String escapeIfNecessary(String input) {
if (this.templateFormat.equals(TemplateFormats.markdown())) {
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
return input;
}
return input.replace("|", "\\|");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public void typeDeterminationDoesNotSetTypeOnDescriptor() throws IOException {
}

private String escapeIfNecessary(String input) {
if (this.templateFormat.equals(TemplateFormats.markdown())) {
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
return input;
}
return input.replace("|", "\\|");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public void typeDeterminationDoesNotSetTypeOnDescriptor() throws IOException {
}

private String escapeIfNecessary(String input) {
if (this.templateFormat.equals(TemplateFormats.markdown())) {
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
return input;
}
return input.replace("|", "\\|");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ public void allUndocumentedPathParametersCanBeIgnored() throws IOException {
public void missingOptionalPathParameter() throws IOException {
this.snippets.expectPathParameters()
.withContents(tableWithTitleAndHeader(
this.templateFormat == TemplateFormats.asciidoctor() ? "+/{a}+"
: "`/{a}`",
getTitle("/{a}"),
"Parameter", "Description").row("`a`", "one").row("`b`", "two"));
new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"),
parameterWithName("b").description("two").optional()))
Expand All @@ -101,8 +100,7 @@ public void missingOptionalPathParameter() throws IOException {
public void presentOptionalPathParameter() throws IOException {
this.snippets.expectPathParameters()
.withContents(tableWithTitleAndHeader(
this.templateFormat == TemplateFormats.asciidoctor() ? "+/{a}+"
: "`/{a}`",
getTitle("/{a}"),
"Parameter", "Description").row("`a`", "one"));
new PathParametersSnippet(
Arrays.asList(parameterWithName("a").description("one").optional()))
Expand Down Expand Up @@ -208,7 +206,7 @@ public void pathParametersWithEscapedContent() throws IOException {
}

private String escapeIfNecessary(String input) {
if (this.templateFormat.equals(TemplateFormats.markdown())) {
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
return input;
}
return input.replace("|", "\\|");
Expand All @@ -219,7 +217,7 @@ private String getTitle() {
}

private String getTitle(String title) {
if (this.templateFormat.equals(TemplateFormats.asciidoctor())) {
if (this.templateFormat.getId().equals(TemplateFormats.asciidoctor().getId())) {
return "+" + title + "+";
}
return "`" + title + "`";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public void requestParametersWithEscapedContent() throws IOException {
}

private String escapeIfNecessary(String input) {
if (this.templateFormat.equals(TemplateFormats.markdown())) {
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
return input;
}
return input.replace("|", "\\|");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public void requestPartsWithEscapedContent() throws IOException {
}

private String escapeIfNecessary(String input) {
if (this.templateFormat.equals(TemplateFormats.markdown())) {
if (this.templateFormat.getId().equals(TemplateFormats.markdown().getId())) {
return input;
}
return input.replace("|", "\\|");
Expand Down