diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/generate/RestDocumentationGenerator.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/generate/RestDocumentationGenerator.java index 0245d3df..06cb7ba5 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/generate/RestDocumentationGenerator.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/generate/RestDocumentationGenerator.java @@ -227,12 +227,13 @@ public final class RestDocumentationGenerator { @SuppressWarnings("unchecked") private List getSnippets(Map configuration) { - List combinedSnippets = new ArrayList<>(this.snippets); + List combinedSnippets = new ArrayList<>(); List defaultSnippets = (List) configuration .get(ATTRIBUTE_NAME_DEFAULT_SNIPPETS); if (defaultSnippets != null) { combinedSnippets.addAll(defaultSnippets); } + combinedSnippets.addAll(this.snippets); return combinedSnippets; } diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/RestDocumentationGeneratorTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/RestDocumentationGeneratorTests.java index 103a7960..7843d3d0 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/RestDocumentationGeneratorTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/RestDocumentationGeneratorTests.java @@ -24,6 +24,7 @@ import java.util.Map; import org.junit.Test; import org.mockito.ArgumentCaptor; +import org.mockito.InOrder; import org.mockito.Mockito; import org.springframework.http.HttpHeaders; @@ -111,9 +112,10 @@ public class RestDocumentationGeneratorTests { new RestDocumentationGenerator<>("id", this.requestConverter, this.responseConverter, this.snippet).handle(this.request, this.response, configuration); - verifySnippetInvocation(this.snippet, configuration); - verifySnippetInvocation(defaultSnippet1, configuration); - verifySnippetInvocation(defaultSnippet2, configuration); + InOrder inOrder = Mockito.inOrder(defaultSnippet1, defaultSnippet2, this.snippet); + verifySnippetInvocation(inOrder, defaultSnippet1, configuration); + verifySnippetInvocation(inOrder, defaultSnippet2, configuration); + verifySnippetInvocation(inOrder, this.snippet, configuration); } @Test @@ -202,13 +204,12 @@ public class RestDocumentationGeneratorTests { private void verifySnippetInvocation(Snippet snippet, Map attributes) throws IOException { - verifySnippetInvocation(snippet, attributes, 1); - } - - private void verifySnippetInvocation(Snippet snippet, Map attributes, - int times) throws IOException { - verifySnippetInvocation(snippet, this.operationRequest, this.operationResponse, - attributes, times); + ArgumentCaptor operation = ArgumentCaptor.forClass(Operation.class); + verify(snippet).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()))); } private void verifySnippetInvocation(Snippet snippet, @@ -218,6 +219,15 @@ public class RestDocumentationGeneratorTests { verify(snippet, Mockito.times(times)).document(operation.capture()); assertThat(operationRequest, is(equalTo(operation.getValue().getRequest()))); assertThat(operationResponse, is(equalTo(operation.getValue().getResponse()))); + } + + private void verifySnippetInvocation(InOrder inOrder, Snippet snippet, + Map attributes) throws IOException { + ArgumentCaptor operation = ArgumentCaptor.forClass(Operation.class); + inOrder.verify(snippet).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()))); }