Merge branch '1.0.x'
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -62,6 +62,8 @@ public final class RestDocumentationGenerator<REQ, RESP> {
|
||||
|
||||
private final List<Snippet> snippets;
|
||||
|
||||
private final List<Snippet> additionalSnippets;
|
||||
|
||||
private final RequestConverter<REQ> requestConverter;
|
||||
|
||||
private final ResponseConverter<RESP> responseConverter;
|
||||
@@ -167,6 +169,7 @@ public final class RestDocumentationGenerator<REQ, RESP> {
|
||||
this.requestPreprocessor = requestPreprocessor;
|
||||
this.responsePreprocessor = responsePreprocessor;
|
||||
this.snippets = new ArrayList<>(Arrays.asList(snippets));
|
||||
this.additionalSnippets = new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -204,7 +207,7 @@ public final class RestDocumentationGenerator<REQ, RESP> {
|
||||
* @param snippets the snippets to add
|
||||
*/
|
||||
public void addSnippets(Snippet... snippets) {
|
||||
this.snippets.addAll(Arrays.asList(snippets));
|
||||
this.additionalSnippets.addAll(Arrays.asList(snippets));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -215,6 +218,8 @@ public final class RestDocumentationGenerator<REQ, RESP> {
|
||||
if (defaultSnippets != null) {
|
||||
combinedSnippets.addAll(defaultSnippets);
|
||||
}
|
||||
combinedSnippets.addAll(this.additionalSnippets);
|
||||
this.additionalSnippets.clear();
|
||||
return combinedSnippets;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.restdocs.generate.RestDocumentationGenerator;
|
||||
@@ -116,18 +117,25 @@ public class RestDocumentationGeneratorTests {
|
||||
generator.addSnippets(additionalSnippet1, additionalSnippet2);
|
||||
HashMap<String, Object> configuration = new HashMap<>();
|
||||
generator.handle(this.request, this.response, configuration);
|
||||
verifySnippetInvocation(this.snippet, configuration);
|
||||
generator.handle(this.request, this.response, configuration);
|
||||
verifySnippetInvocation(this.snippet, configuration, 2);
|
||||
verifySnippetInvocation(additionalSnippet1, configuration);
|
||||
verifySnippetInvocation(additionalSnippet2, configuration);
|
||||
}
|
||||
|
||||
private void verifySnippetInvocation(Snippet snippet, Map<String, Object> attributes)
|
||||
throws IOException {
|
||||
verifySnippetInvocation(snippet, attributes, 1);
|
||||
}
|
||||
|
||||
private void verifySnippetInvocation(Snippet snippet, Map<String, Object> attributes,
|
||||
int times) throws IOException {
|
||||
ArgumentCaptor<Operation> operation = ArgumentCaptor.forClass(Operation.class);
|
||||
verify(snippet).document(operation.capture());
|
||||
verify(snippet, Mockito.times(times)).document(operation.capture());
|
||||
assertThat(this.operationRequest, is(equalTo(operation.getValue().getRequest())));
|
||||
assertThat(this.operationResponse,
|
||||
is(equalTo(operation.getValue().getResponse())));
|
||||
assertThat(attributes, is(equalTo(operation.getValue().getAttributes())));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user