Fix compiler warnings
This commit is contained in:
@@ -96,6 +96,7 @@ public final class StandardWriterResolver implements WriterResolver {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void setEncoding(String encoding) {
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Map;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.restdocs.ManualRestDocumentation;
|
||||
import org.springframework.restdocs.RestDocumentationContext;
|
||||
import org.springframework.restdocs.cli.CliDocumentation;
|
||||
import org.springframework.restdocs.cli.CurlRequestSnippet;
|
||||
@@ -57,9 +58,8 @@ public class RestDocumentationConfigurerTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void defaultConfiguration() {
|
||||
RestDocumentationContext context = new RestDocumentationContext(null, null, null);
|
||||
Map<String, Object> configuration = new HashMap<>();
|
||||
this.configurer.apply(configuration, context);
|
||||
this.configurer.apply(configuration, createContext());
|
||||
assertThat(configuration, hasEntry(equalTo(TemplateEngine.class.getName()),
|
||||
instanceOf(MustacheTemplateEngine.class)));
|
||||
assertThat(configuration, hasEntry(equalTo(WriterResolver.class.getName()),
|
||||
@@ -86,30 +86,29 @@ public class RestDocumentationConfigurerTests {
|
||||
|
||||
@Test
|
||||
public void customTemplateEngine() {
|
||||
RestDocumentationContext context = new RestDocumentationContext(null, null, null);
|
||||
Map<String, Object> configuration = new HashMap<>();
|
||||
TemplateEngine templateEngine = mock(TemplateEngine.class);
|
||||
this.configurer.templateEngine(templateEngine).apply(configuration, context);
|
||||
this.configurer.templateEngine(templateEngine).apply(configuration,
|
||||
createContext());
|
||||
assertThat(configuration, Matchers.<String, Object>hasEntry(
|
||||
TemplateEngine.class.getName(), templateEngine));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customWriterResolver() {
|
||||
RestDocumentationContext context = new RestDocumentationContext(null, null, null);
|
||||
Map<String, Object> configuration = new HashMap<>();
|
||||
WriterResolver writerResolver = mock(WriterResolver.class);
|
||||
this.configurer.writerResolver(writerResolver).apply(configuration, context);
|
||||
this.configurer.writerResolver(writerResolver).apply(configuration,
|
||||
createContext());
|
||||
assertThat(configuration, Matchers.<String, Object>hasEntry(
|
||||
WriterResolver.class.getName(), writerResolver));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customDefaultSnippets() {
|
||||
RestDocumentationContext context = new RestDocumentationContext(null, null, null);
|
||||
Map<String, Object> configuration = new HashMap<>();
|
||||
this.configurer.snippets().withDefaults(CliDocumentation.curlRequest())
|
||||
.apply(configuration, context);
|
||||
.apply(configuration, createContext());
|
||||
assertThat(configuration,
|
||||
hasEntry(
|
||||
equalTo(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS),
|
||||
@@ -122,10 +121,9 @@ public class RestDocumentationConfigurerTests {
|
||||
|
||||
@Test
|
||||
public void customSnippetEncoding() {
|
||||
RestDocumentationContext context = new RestDocumentationContext(null, null, null);
|
||||
Map<String, Object> configuration = new HashMap<>();
|
||||
this.configurer.snippets().withEncoding("ISO 8859-1").apply(configuration,
|
||||
context);
|
||||
createContext());
|
||||
assertThat(configuration, hasEntry(equalTo(SnippetConfiguration.class.getName()),
|
||||
instanceOf(SnippetConfiguration.class)));
|
||||
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
|
||||
@@ -135,10 +133,9 @@ public class RestDocumentationConfigurerTests {
|
||||
|
||||
@Test
|
||||
public void customTemplateFormat() {
|
||||
RestDocumentationContext context = new RestDocumentationContext(null, null, null);
|
||||
Map<String, Object> configuration = new HashMap<>();
|
||||
this.configurer.snippets().withTemplateFormat(TemplateFormats.markdown())
|
||||
.apply(configuration, context);
|
||||
.apply(configuration, createContext());
|
||||
assertThat(configuration, hasEntry(equalTo(SnippetConfiguration.class.getName()),
|
||||
instanceOf(SnippetConfiguration.class)));
|
||||
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
|
||||
@@ -147,6 +144,14 @@ public class RestDocumentationConfigurerTests {
|
||||
is(equalTo(TemplateFormats.markdown())));
|
||||
}
|
||||
|
||||
private RestDocumentationContext createContext() {
|
||||
ManualRestDocumentation manualRestDocumentation = new ManualRestDocumentation(
|
||||
"build");
|
||||
manualRestDocumentation.beforeTest(null, null);
|
||||
RestDocumentationContext context = manualRestDocumentation.beforeOperation();
|
||||
return context;
|
||||
}
|
||||
|
||||
private static final class TestRestDocumentationConfigurer extends
|
||||
RestDocumentationConfigurer<TestSnippetConfigurer, TestRestDocumentationConfigurer> {
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.restdocs.snippet;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.restdocs.ManualRestDocumentation;
|
||||
import org.springframework.restdocs.RestDocumentationContext;
|
||||
import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
|
||||
|
||||
@@ -70,17 +71,23 @@ public class RestDocumentationContextPlaceholderResolverTests {
|
||||
|
||||
@Test
|
||||
public void stepCount() throws Exception {
|
||||
assertThat(createResolver("stepCount").resolvePlaceholder("step"), equalTo("0"));
|
||||
assertThat(createResolver("stepCount").resolvePlaceholder("step"), equalTo("1"));
|
||||
}
|
||||
|
||||
private PlaceholderResolver createResolver() {
|
||||
return new RestDocumentationContextPlaceholderResolver(
|
||||
new RestDocumentationContext(getClass(), null, null));
|
||||
return createResolver(null);
|
||||
}
|
||||
|
||||
private PlaceholderResolver createResolver(String methodName) {
|
||||
return new RestDocumentationContextPlaceholderResolver(
|
||||
new RestDocumentationContext(getClass(), methodName, null));
|
||||
return new RestDocumentationContextPlaceholderResolver(createContext(methodName));
|
||||
}
|
||||
|
||||
private RestDocumentationContext createContext(String methodName) {
|
||||
ManualRestDocumentation manualRestDocumentation = new ManualRestDocumentation(
|
||||
"build");
|
||||
manualRestDocumentation.beforeTest(getClass(), methodName);
|
||||
RestDocumentationContext context = manualRestDocumentation.beforeOperation();
|
||||
return context;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,11 +20,11 @@ import java.io.File;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.restdocs.ManualRestDocumentation;
|
||||
import org.springframework.restdocs.RestDocumentationContext;
|
||||
import org.springframework.util.PropertyPlaceholderHelper.PlaceholderResolver;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
|
||||
@@ -42,18 +42,12 @@ public class StandardWriterResolverTests {
|
||||
private final StandardWriterResolver resolver = new StandardWriterResolver(
|
||||
this.placeholderResolver, "UTF-8", asciidoctor());
|
||||
|
||||
@Test
|
||||
public void noConfiguredOutputDirectoryAndRelativeInput() {
|
||||
assertThat(this.resolver.resolveFile("foo", "bar.txt",
|
||||
new RestDocumentationContext(null, null, null)), is(nullValue()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void absoluteInput() {
|
||||
String absolutePath = new File("foo").getAbsolutePath();
|
||||
assertThat(
|
||||
this.resolver.resolveFile(absolutePath, "bar.txt",
|
||||
new RestDocumentationContext(null, null, null)),
|
||||
createContext(absolutePath)),
|
||||
is(new File(absolutePath, "bar.txt")));
|
||||
}
|
||||
|
||||
@@ -62,7 +56,7 @@ public class StandardWriterResolverTests {
|
||||
File outputDir = new File("foo").getAbsoluteFile();
|
||||
assertThat(
|
||||
this.resolver.resolveFile("bar", "baz.txt",
|
||||
new RestDocumentationContext(null, null, outputDir)),
|
||||
createContext(outputDir.getAbsolutePath())),
|
||||
is(new File(outputDir, "bar/baz.txt")));
|
||||
}
|
||||
|
||||
@@ -72,8 +66,16 @@ public class StandardWriterResolverTests {
|
||||
String absolutePath = new File("bar").getAbsolutePath();
|
||||
assertThat(
|
||||
this.resolver.resolveFile(absolutePath, "baz.txt",
|
||||
new RestDocumentationContext(null, null, outputDir)),
|
||||
createContext(outputDir.getAbsolutePath())),
|
||||
is(new File(absolutePath, "baz.txt")));
|
||||
}
|
||||
|
||||
private RestDocumentationContext createContext(String outputDir) {
|
||||
ManualRestDocumentation manualRestDocumentation = new ManualRestDocumentation(
|
||||
outputDir);
|
||||
manualRestDocumentation.beforeTest(getClass(), null);
|
||||
RestDocumentationContext context = manualRestDocumentation.beforeOperation();
|
||||
return context;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.Map;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.restdocs.ManualRestDocumentation;
|
||||
import org.springframework.restdocs.RestDocumentationContext;
|
||||
import org.springframework.restdocs.operation.Operation;
|
||||
import org.springframework.restdocs.operation.OperationRequest;
|
||||
@@ -96,8 +97,7 @@ public class OperationBuilder {
|
||||
new MustacheTemplateEngine(
|
||||
new StandardTemplateResourceResolver(this.templateFormat)));
|
||||
}
|
||||
RestDocumentationContext context = new RestDocumentationContext(null, null,
|
||||
this.outputDirectory);
|
||||
RestDocumentationContext context = createContext();
|
||||
this.attributes.put(RestDocumentationContext.class.getName(), context);
|
||||
this.attributes.put(WriterResolver.class.getName(),
|
||||
new StandardWriterResolver(
|
||||
@@ -110,6 +110,14 @@ public class OperationBuilder {
|
||||
this.responseBuilder.buildResponse(), this.attributes);
|
||||
}
|
||||
|
||||
private RestDocumentationContext createContext() {
|
||||
ManualRestDocumentation manualRestDocumentation = new ManualRestDocumentation(
|
||||
this.outputDirectory.getAbsolutePath());
|
||||
manualRestDocumentation.beforeTest(null, null);
|
||||
RestDocumentationContext context = manualRestDocumentation.beforeOperation();
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic builder API for creating an {@link OperationRequest}.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user