diff --git a/build.gradle b/build.gradle
index 512fe344..abdd9e3a 100644
--- a/build.gradle
+++ b/build.gradle
@@ -70,6 +70,7 @@ subprojects {
dependency 'junit:junit:4.12'
dependency 'io.rest-assured:rest-assured:3.0.7'
dependency 'org.apache.pdfbox:pdfbox:2.0.7'
+ dependency 'org.assertj:assertj-core:2.9.1'
dependency 'org.asciidoctor:asciidoctorj:1.5.6'
dependency 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.16'
dependency 'org.hamcrest:hamcrest-core:1.3'
diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml
index 08722da0..0eab6766 100644
--- a/config/checkstyle/checkstyle.xml
+++ b/config/checkstyle/checkstyle.xml
@@ -73,7 +73,7 @@
+ value="io.restassured.RestAssured.*, org.assertj.core.api.Assertions.*, org.hamcrest.CoreMatchers.*, org.hamcrest.Matchers.*, org.mockito.Mockito.*, org.mockito.BDDMockito.*, org.mockito.Matchers.*, org.springframework.restdocs.cli.CliDocumentation.*, org.springframework.restdocs.headers.HeaderDocumentation.*, org.springframework.restdocs.hypermedia.HypermediaDocumentation.*, org.springframework.restdocs.mockmvc.IterableEnumeration.*, org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*, org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*, org.springframework.restdocs.payload.PayloadDocumentation.*, org.springframework.restdocs.operation.preprocess.Preprocessors.*, org.springframework.restdocs.request.RequestDocumentation.*, org.springframework.restdocs.restassured3.RestAssuredRestDocumentation.*, org.springframework.restdocs.restassured3.operation.preprocess.RestAssuredPreprocessors.*, org.springframework.restdocs.snippet.Attributes.*, org.springframework.restdocs.templates.TemplateFormats.*, org.springframework.restdocs.test.SnippetConditions.*, org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.*, org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*, org.springframework.test.web.servlet.result.MockMvcResultMatchers.*, org.springframework.web.reactive.function.BodyInserters.*, org.springframework.web.reactive.function.server.RequestPredicates.GET, org.springframework.web.reactive.function.server.RequestPredicates.POST" />
diff --git a/samples/rest-notes-spring-hateoas/build.gradle b/samples/rest-notes-spring-hateoas/build.gradle
index c6ebe136..112fb41e 100644
--- a/samples/rest-notes-spring-hateoas/build.gradle
+++ b/samples/rest-notes-spring-hateoas/build.gradle
@@ -43,6 +43,7 @@ dependencies {
runtime 'org.atteo:evo-inflector:1.2.1'
testCompile 'com.jayway.jsonpath:json-path'
+ testCompile 'org.assertj:assertj-core'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testCompile 'org.springframework.restdocs:spring-restdocs-mockmvc'
}
diff --git a/samples/rest-notes-spring-hateoas/src/test/java/com/example/notes/NullOrNotBlankTests.java b/samples/rest-notes-spring-hateoas/src/test/java/com/example/notes/NullOrNotBlankTests.java
index 24d9e85a..d7e9e309 100644
--- a/samples/rest-notes-spring-hateoas/src/test/java/com/example/notes/NullOrNotBlankTests.java
+++ b/samples/rest-notes-spring-hateoas/src/test/java/com/example/notes/NullOrNotBlankTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2015 the original author or authors.
+ * Copyright 2014-2018 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.
@@ -16,8 +16,7 @@
package com.example.notes;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import java.util.Set;
@@ -35,25 +34,25 @@ public class NullOrNotBlankTests {
@Test
public void nullValue() {
Set> violations = validator.validate(new Constrained(null));
- assertThat(violations.size(), is(0));
+ assertThat(violations).isEmpty();
}
@Test
public void zeroLengthValue() {
Set> violations = validator.validate(new Constrained(""));
- assertThat(violations.size(), is(2));
+ assertThat(violations).hasSize(2);
}
@Test
public void blankValue() {
Set> violations = validator.validate(new Constrained(" "));
- assertThat(violations.size(), is(2));
+ assertThat(violations).hasSize(2);
}
@Test
public void nonBlankValue() {
Set> violations = validator.validate(new Constrained("test"));
- assertThat(violations.size(), is(0));
+ assertThat(violations).isEmpty();
}
static class Constrained {
diff --git a/spring-restdocs-asciidoctor/build.gradle b/spring-restdocs-asciidoctor/build.gradle
index 51352428..dcb58c2f 100644
--- a/spring-restdocs-asciidoctor/build.gradle
+++ b/spring-restdocs-asciidoctor/build.gradle
@@ -5,6 +5,7 @@ dependencies {
testCompile 'junit:junit'
testCompile 'org.apache.pdfbox:pdfbox'
testCompile 'org.asciidoctor:asciidoctorj'
+ testCompile 'org.assertj:assertj-core'
testCompile 'org.springframework:spring-core'
testRuntime 'org.asciidoctor:asciidoctorj-pdf'
}
\ No newline at end of file
diff --git a/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesPreprocessorTests.java b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesPreprocessorTests.java
index 83ef4782..47f02134 100644
--- a/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesPreprocessorTests.java
+++ b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/DefaultAttributesPreprocessorTests.java
@@ -23,8 +23,7 @@ import org.asciidoctor.Attributes;
import org.asciidoctor.Options;
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link DefaultAttributesPreprocessor}.
@@ -38,8 +37,8 @@ public class DefaultAttributesPreprocessorTests {
Options options = new Options();
options.setAttributes(new Attributes("projectdir=../../.."));
String converted = Asciidoctor.Factory.create().convert("{snippets}", options);
- assertThat(converted,
- containsString("build" + File.separatorChar + "generated-snippets"));
+ assertThat(converted)
+ .contains("build" + File.separatorChar + "generated-snippets");
}
@Test
@@ -47,7 +46,7 @@ public class DefaultAttributesPreprocessorTests {
Options options = new Options();
options.setAttributes(new Attributes("snippets=custom projectdir=../../.."));
String converted = Asciidoctor.Factory.create().convert("{snippets}", options);
- assertThat(converted, containsString("custom"));
+ assertThat(converted).contains("custom");
}
@Test
@@ -56,7 +55,7 @@ public class DefaultAttributesPreprocessorTests {
options.setAttributes(new Attributes("projectdir=../../.."));
String converted = Asciidoctor.Factory.create()
.convert(":snippets: custom\n{snippets}", options);
- assertThat(converted, containsString("custom"));
+ assertThat(converted).contains("custom");
}
}
diff --git a/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/OperationBlockMacroTests.java b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/OperationBlockMacroTests.java
index b3973157..bacfc222 100644
--- a/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/OperationBlockMacroTests.java
+++ b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/OperationBlockMacroTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2017 the original author or authors.
+ * Copyright 2014-2018 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.
@@ -39,10 +39,7 @@ import org.junit.Test;
import org.springframework.util.FileSystemUtils;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.hasItems;
-import static org.hamcrest.CoreMatchers.startsWith;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for Ruby operation block macro.
@@ -73,7 +70,7 @@ public class OperationBlockMacroTests {
public void codeBlockSnippetInclude() throws Exception {
String result = this.asciidoctor.convert(
"operation::some-operation[snippets='curl-request']", this.options);
- assertThat(result, equalTo(getExpectedContentFromFile("snippet-simple")));
+ assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-simple"));
}
@Test
@@ -83,7 +80,7 @@ public class OperationBlockMacroTests {
this.options.setAttributes(attributes);
String result = this.asciidoctor.convert(
"operation::{name}-operation[snippets='curl-request']", this.options);
- assertThat(result, equalTo(getExpectedContentFromFile("snippet-simple")));
+ assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-simple"));
}
@Test
@@ -91,15 +88,15 @@ public class OperationBlockMacroTests {
File output = configurePdfOutput();
this.asciidoctor.convert("operation::some-operation[snippets='curl-request']",
this.options);
- assertThat(extractStrings(output),
- hasItems("Curl request", "$ curl 'http://localhost:8080/' -i", "1"));
+ assertThat(extractStrings(output)).containsExactly("Curl request",
+ "$ curl 'http://localhost:8080/' -i", "1");
}
@Test
public void tableSnippetInclude() throws Exception {
String result = this.asciidoctor.convert(
"operation::some-operation[snippets='response-fields']", this.options);
- assertThat(result, equalTo(getExpectedContentFromFile("snippet-table")));
+ assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-table"));
}
@Test
@@ -107,9 +104,9 @@ public class OperationBlockMacroTests {
File output = configurePdfOutput();
this.asciidoctor.convert("operation::some-operation[snippets='response-fields']",
this.options);
- assertThat(extractStrings(output),
- hasItems("Response fields", "Path", "Type", "Description", "a", "Object",
- "one", "a.b", "Number", "two", "a.c", "String", "three", "1"));
+ assertThat(extractStrings(output)).containsExactly("Response fields", "Path",
+ "Type", "Description", "a", "Object", "one", "a.b", "Number", "two",
+ "a.c", "String", "three", "1");
}
@Test
@@ -117,7 +114,7 @@ public class OperationBlockMacroTests {
String result = this.asciidoctor.convert(
"== Section\n" + "operation::some-operation[snippets='curl-request']",
this.options);
- assertThat(result, equalTo(getExpectedContentFromFile("snippet-in-section")));
+ assertThat(result).isEqualTo(getExpectedContentFromFile("snippet-in-section"));
}
@Test
@@ -126,8 +123,8 @@ public class OperationBlockMacroTests {
this.asciidoctor.convert(
"== Section\n" + "operation::some-operation[snippets='curl-request']",
this.options);
- assertThat(extractStrings(output), hasItems("Section", "Curl request",
- "$ curl 'http://localhost:8080/' -i", "1"));
+ assertThat(extractStrings(output)).containsExactly("Section", "Curl request",
+ "$ curl 'http://localhost:8080/' -i", "1");
}
@Test
@@ -135,43 +132,43 @@ public class OperationBlockMacroTests {
String result = this.asciidoctor.convert(
"operation::some-operation[snippets='curl-request,http-request']",
this.options);
- assertThat(result, equalTo(getExpectedContentFromFile("multiple-snippets")));
+ assertThat(result).isEqualTo(getExpectedContentFromFile("multiple-snippets"));
}
@Test
public void useMacroWithoutSnippetAttributeAddsAllSnippets() throws Exception {
String result = this.asciidoctor.convert("operation::some-operation[]",
this.options);
- assertThat(result, equalTo(getExpectedContentFromFile("all-snippets")));
+ assertThat(result).isEqualTo(getExpectedContentFromFile("all-snippets"));
}
@Test
public void useMacroWithEmptySnippetAttributeAddsAllSnippets() throws Exception {
String result = this.asciidoctor.convert("operation::some-operation[snippets=]",
this.options);
- assertThat(result, equalTo(getExpectedContentFromFile("all-snippets")));
+ assertThat(result).isEqualTo(getExpectedContentFromFile("all-snippets"));
}
@Test
public void includingMissingSnippetAddsWarning() throws Exception {
String result = this.asciidoctor.convert(
"operation::some-operation[snippets='missing-snippet']", this.options);
- assertThat(result, startsWith(getExpectedContentFromFile("missing-snippet")));
+ assertThat(result).startsWith(getExpectedContentFromFile("missing-snippet"));
}
@Test
public void defaultTitleIsProvidedForCustomSnippet() throws Exception {
String result = this.asciidoctor.convert(
"operation::some-operation[snippets='custom-snippet']", this.options);
- assertThat(result,
- equalTo(getExpectedContentFromFile("custom-snippet-default-title")));
+ assertThat(result)
+ .isEqualTo(getExpectedContentFromFile("custom-snippet-default-title"));
}
@Test
public void missingOperationIsHandledGracefully() throws Exception {
String result = this.asciidoctor.convert("operation::missing-operation[]",
this.options);
- assertThat(result, startsWith(getExpectedContentFromFile("missing-operation")));
+ assertThat(result).startsWith(getExpectedContentFromFile("missing-operation"));
}
@Test
@@ -181,8 +178,8 @@ public class OperationBlockMacroTests {
":operation-curl-request-title: Example request\n"
+ "operation::some-operation[snippets='curl-request']",
this.options);
- assertThat(result,
- equalTo(getExpectedContentFromFile("built-in-snippet-custom-title")));
+ assertThat(result)
+ .isEqualTo(getExpectedContentFromFile("built-in-snippet-custom-title"));
}
@Test
@@ -192,8 +189,8 @@ public class OperationBlockMacroTests {
":operation-custom-snippet-title: Customized title\n"
+ "operation::some-operation[snippets='custom-snippet']",
this.options);
- assertThat(result,
- equalTo(getExpectedContentFromFile("custom-snippet-custom-title")));
+ assertThat(result)
+ .isEqualTo(getExpectedContentFromFile("custom-snippet-custom-title"));
}
private String getExpectedContentFromFile(String fileName)
@@ -226,7 +223,7 @@ public class OperationBlockMacroTests {
private List extractStrings(File pdfFile) throws IOException {
PDDocument pdf = PDDocument.load(pdfFile);
- assertThat(pdf.getNumberOfPages(), equalTo(1));
+ assertThat(pdf.getNumberOfPages()).isEqualTo(1);
StringExtractor stringExtractor = new StringExtractor();
stringExtractor.processPage(pdf.getPage(0));
return stringExtractor.getStrings();
diff --git a/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolverTests.java b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolverTests.java
index 74bbda7e..711408be 100644
--- a/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolverTests.java
+++ b/spring-restdocs-asciidoctor/src/test/java/org/springframework/restdocs/asciidoctor/SnippetsDirectoryResolverTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2016 the original author or authors.
+ * Copyright 2014-2018 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.
@@ -26,9 +26,8 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
/**
* Tests for {@link SnippetsDirectoryResolver}.
@@ -52,9 +51,9 @@ public class SnippetsDirectoryResolverTests {
new File(this.temporaryFolder.getRoot(), "src/main/asciidoc")
.getAbsolutePath());
File snippetsDirectory = getMavenSnippetsDirectory(attributes);
- assertThat(snippetsDirectory.isAbsolute(), is(false));
- assertThat(snippetsDirectory,
- equalTo(new File("../../../target/generated-snippets")));
+ assertThat(snippetsDirectory).isRelative();
+ assertThat(snippetsDirectory)
+ .isEqualTo(new File("../../../target/generated-snippets"));
}
@Test
@@ -85,8 +84,8 @@ public class SnippetsDirectoryResolverTests {
attributes.put("projectdir", "project/dir");
File snippetsDirectory = new SnippetsDirectoryResolver()
.getSnippetsDirectory(attributes);
- assertThat(snippetsDirectory,
- equalTo(new File("project/dir/build/generated-snippets")));
+ assertThat(snippetsDirectory)
+ .isEqualTo(new File("project/dir/build/generated-snippets"));
}
@Test
diff --git a/spring-restdocs-core/build.gradle b/spring-restdocs-core/build.gradle
index 47aa151b..186b3405 100644
--- a/spring-restdocs-core/build.gradle
+++ b/spring-restdocs-core/build.gradle
@@ -35,6 +35,7 @@ dependencies {
optional 'junit:junit'
optional 'org.hibernate.validator:hibernate-validator'
optional 'org.junit.jupiter:junit-jupiter-api'
+ testCompile 'org.assertj:assertj-core'
testCompile 'org.javamoney:moneta'
testCompile 'org.mockito:mockito-core'
testCompile 'org.hamcrest:hamcrest-core'
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/AbstractSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/AbstractSnippetTests.java
index 014caa4d..11b51651 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/AbstractSnippetTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/AbstractSnippetTests.java
@@ -27,13 +27,13 @@ import org.junit.runners.Parameterized.Parameters;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpStatus;
import org.springframework.restdocs.templates.TemplateFormat;
-import org.springframework.restdocs.test.ExpectedSnippets;
+import org.springframework.restdocs.test.GeneratedSnippets;
import org.springframework.restdocs.test.OperationBuilder;
-import org.springframework.restdocs.test.SnippetMatchers;
-import org.springframework.restdocs.test.SnippetMatchers.CodeBlockMatcher;
-import org.springframework.restdocs.test.SnippetMatchers.HttpRequestMatcher;
-import org.springframework.restdocs.test.SnippetMatchers.HttpResponseMatcher;
-import org.springframework.restdocs.test.SnippetMatchers.TableMatcher;
+import org.springframework.restdocs.test.SnippetConditions;
+import org.springframework.restdocs.test.SnippetConditions.CodeBlockCondition;
+import org.springframework.restdocs.test.SnippetConditions.HttpRequestCondition;
+import org.springframework.restdocs.test.SnippetConditions.HttpResponseCondition;
+import org.springframework.restdocs.test.SnippetConditions.TableCondition;
import org.springframework.web.bind.annotation.RequestMethod;
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
@@ -50,7 +50,7 @@ public abstract class AbstractSnippetTests {
protected final TemplateFormat templateFormat;
@Rule
- public ExpectedSnippets snippets;
+ public GeneratedSnippets generatedSnippets;
@Rule
public OperationBuilder operationBuilder;
@@ -62,34 +62,34 @@ public abstract class AbstractSnippetTests {
}
public AbstractSnippetTests(String name, TemplateFormat templateFormat) {
- this.snippets = new ExpectedSnippets(templateFormat);
+ this.generatedSnippets = new GeneratedSnippets(templateFormat);
this.templateFormat = templateFormat;
this.operationBuilder = new OperationBuilder(this.templateFormat);
}
- public CodeBlockMatcher> codeBlock(String language) {
+ public CodeBlockCondition> codeBlock(String language) {
return this.codeBlock(language, null);
}
- public CodeBlockMatcher> codeBlock(String language, String options) {
- return SnippetMatchers.codeBlock(this.templateFormat, language, options);
+ public CodeBlockCondition> codeBlock(String language, String options) {
+ return SnippetConditions.codeBlock(this.templateFormat, language, options);
}
- public TableMatcher> tableWithHeader(String... headers) {
- return SnippetMatchers.tableWithHeader(this.templateFormat, headers);
+ public TableCondition> tableWithHeader(String... headers) {
+ return SnippetConditions.tableWithHeader(this.templateFormat, headers);
}
- public TableMatcher> tableWithTitleAndHeader(String title, String... headers) {
- return SnippetMatchers.tableWithTitleAndHeader(this.templateFormat, title,
+ public TableCondition> tableWithTitleAndHeader(String title, String... headers) {
+ return SnippetConditions.tableWithTitleAndHeader(this.templateFormat, title,
headers);
}
- public HttpRequestMatcher httpRequest(RequestMethod method, String uri) {
- return SnippetMatchers.httpRequest(this.templateFormat, method, uri);
+ public HttpRequestCondition httpRequest(RequestMethod method, String uri) {
+ return SnippetConditions.httpRequest(this.templateFormat, method, uri);
}
- public HttpResponseMatcher httpResponse(HttpStatus responseStatus) {
- return SnippetMatchers.httpResponse(this.templateFormat, responseStatus);
+ public HttpResponseCondition httpResponse(HttpStatus responseStatus) {
+ return SnippetConditions.httpResponse(this.templateFormat, responseStatus);
}
protected FileSystemResource snippetResource(String name) {
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 7843d3d0..0f3b453c 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
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2017 the original author or authors.
+ * Copyright 2014-2018 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.
@@ -42,9 +42,7 @@ import org.springframework.restdocs.operation.preprocess.OperationResponsePrepro
import org.springframework.restdocs.operation.preprocess.Preprocessors;
import org.springframework.restdocs.snippet.Snippet;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -206,10 +204,9 @@ public class RestDocumentationGeneratorTests {
throws IOException {
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())));
+ assertThat(this.operationRequest).isEqualTo(operation.getValue().getRequest());
+ assertThat(this.operationResponse).isEqualTo(operation.getValue().getResponse());
+ assertThat(attributes).isEqualTo(operation.getValue().getAttributes());
}
private void verifySnippetInvocation(Snippet snippet,
@@ -217,18 +214,17 @@ public class RestDocumentationGeneratorTests {
Map attributes, int times) throws IOException {
ArgumentCaptor operation = ArgumentCaptor.forClass(Operation.class);
verify(snippet, Mockito.times(times)).document(operation.capture());
- assertThat(operationRequest, is(equalTo(operation.getValue().getRequest())));
- assertThat(operationResponse, is(equalTo(operation.getValue().getResponse())));
+ assertThat(operationRequest).isEqualTo(operation.getValue().getRequest());
+ assertThat(operationResponse).isEqualTo(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())));
+ assertThat(this.operationRequest).isEqualTo(operation.getValue().getRequest());
+ assertThat(this.operationResponse).isEqualTo(operation.getValue().getResponse());
+ assertThat(attributes).isEqualTo(operation.getValue().getAttributes());
}
private static OperationRequest createRequest() {
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/ConcatenatingCommandFormatterTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/ConcatenatingCommandFormatterTests.java
index fe5fe13a..e9d00524 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/ConcatenatingCommandFormatterTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/ConcatenatingCommandFormatterTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2017 the original author or authors.
+ * Copyright 2014-2018 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.
@@ -21,9 +21,7 @@ import java.util.Collections;
import org.junit.Test;
-import static org.hamcrest.Matchers.equalTo;
-import static org.hamcrest.Matchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link CommandFormatter}.
@@ -37,25 +35,25 @@ public class ConcatenatingCommandFormatterTests {
@Test
public void formattingAnEmptyListProducesAnEmptyString() {
- assertThat(this.singleLineFormat.format(Collections.emptyList()),
- is(equalTo("")));
+ assertThat(this.singleLineFormat.format(Collections.emptyList()))
+ .isEqualTo("");
}
@Test
public void formattingNullProducesAnEmptyString() {
- assertThat(this.singleLineFormat.format(null), is(equalTo("")));
+ assertThat(this.singleLineFormat.format(null)).isEqualTo("");
}
@Test
public void formattingASingleElement() {
- assertThat(this.singleLineFormat.format(Collections.singletonList("alpha")),
- is(equalTo(" alpha")));
+ assertThat(this.singleLineFormat.format(Collections.singletonList("alpha")))
+ .isEqualTo(" alpha");
}
@Test
public void formattingMultipleElements() {
- assertThat(this.singleLineFormat.format(Arrays.asList("alpha", "bravo")),
- is(equalTo(String.format(" alpha bravo"))));
+ assertThat(this.singleLineFormat.format(Arrays.asList("alpha", "bravo")))
+ .isEqualTo(String.format(" alpha bravo"));
}
}
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/CurlRequestSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/CurlRequestSnippetTests.java
index 32507e3a..6589c4a8 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/CurlRequestSnippetTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/CurlRequestSnippetTests.java
@@ -25,17 +25,10 @@ import org.junit.runners.Parameterized;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.restdocs.AbstractSnippetTests;
-import org.springframework.restdocs.templates.TemplateEngine;
import org.springframework.restdocs.templates.TemplateFormat;
-import org.springframework.restdocs.templates.TemplateResourceResolver;
-import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
import org.springframework.util.Base64Utils;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.springframework.restdocs.snippet.Attributes.attributes;
-import static org.springframework.restdocs.snippet.Attributes.key;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link CurlRequestSnippet}.
@@ -58,344 +51,325 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
@Test
public void getRequest() throws IOException {
- this.snippets.expectCurlRequest().withContents(
- codeBlock("bash").content("$ curl 'http://localhost/foo' -i -X GET"));
new CurlRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(
+ codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X GET"));
}
@Test
public void getRequestWithParameter() throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo?a=alpha' -i -X GET"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").param("a", "alpha").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo?a=alpha' -i -X GET"));
}
@Test
public void nonGetRequest() throws IOException {
- this.snippets.expectCurlRequest().withContents(
- codeBlock("bash").content("$ curl 'http://localhost/foo' -i -X POST"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").method("POST").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo' -i -X POST"));
}
@Test
public void requestWithContent() throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo' -i -X GET -d 'content'"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").content("content").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo' -i -X GET -d 'content'"));
}
@Test
public void getRequestWithQueryString() throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo?param=value' -i -X GET"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo?param=value").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo?param=value' -i -X GET"));
}
@Test
public void getRequestWithTotallyOverlappingQueryStringAndParameters()
throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo?param=value' -i -X GET"));
new CurlRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/foo?param=value")
.param("param", "value").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo?param=value' -i -X GET"));
}
@Test
public void getRequestWithPartiallyOverlappingQueryStringAndParameters()
throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i -X GET"));
new CurlRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo?a=alpha")
.param("a", "alpha").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i -X GET"));
}
@Test
public void getRequestWithDisjointQueryStringAndParameters() throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i -X GET"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo?a=alpha").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i -X GET"));
}
@Test
public void getRequestWithQueryStringWithNoValue() throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo?param' -i -X GET"));
new CurlRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/foo?param").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo?param' -i -X GET"));
}
@Test
public void postRequestWithQueryString() throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo?param=value' -i -X POST"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo?param=value").method("POST").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo?param=value' -i -X POST"));
}
@Test
public void postRequestWithQueryStringWithNoValue() throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo?param' -i -X POST"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo?param").method("POST").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo?param' -i -X POST"));
}
@Test
public void postRequestWithOneParameter() throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo' -i -X POST -d 'k1=v1'"));
new CurlRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo")
.method("POST").param("k1", "v1").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo' -i -X POST -d 'k1=v1'"));
}
@Test
public void postRequestWithOneParameterWithNoValue() throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo' -i -X POST -d 'k1='"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").method("POST").param("k1").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo' -i -X POST -d 'k1='"));
}
@Test
public void postRequestWithMultipleParameters() throws IOException {
- this.snippets.expectCurlRequest().withContents(
- codeBlock("bash").content("$ curl 'http://localhost/foo' -i -X POST"
- + " -d 'k1=v1&k1=v1-bis&k2=v2'"));
new CurlRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/foo").method("POST")
.param("k1", "v1", "v1-bis").param("k2", "v2").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(
+ codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X POST"
+ + " -d 'k1=v1&k1=v1-bis&k2=v2'"));
}
@Test
public void postRequestWithUrlEncodedParameter() throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo' -i -X POST -d 'k1=a%26b'"));
new CurlRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo")
.method("POST").param("k1", "a&b").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo' -i -X POST -d 'k1=a%26b'"));
}
@Test
public void postRequestWithDisjointQueryStringAndParameter() throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash").content(
- "$ curl 'http://localhost/foo?a=alpha' -i -X POST -d 'b=bravo'"));
new CurlRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo?a=alpha")
.method("POST").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash").withContent(
+ "$ curl 'http://localhost/foo?a=alpha' -i -X POST -d 'b=bravo'"));
}
@Test
public void postRequestWithTotallyOverlappingQueryStringAndParameters()
throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i -X POST"));
new CurlRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo")
.method("POST").param("a", "alpha").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i -X POST"));
}
@Test
public void postRequestWithPartiallyOverlappingQueryStringAndParameters()
throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash").content(
- "$ curl 'http://localhost/foo?a=alpha' -i -X POST -d 'b=bravo'"));
new CurlRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo?a=alpha")
.method("POST").param("a", "alpha").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash").withContent(
+ "$ curl 'http://localhost/foo?a=alpha' -i -X POST -d 'b=bravo'"));
}
@Test
public void postRequestWithOverlappingParametersAndFormUrlEncodedBody()
throws IOException {
- this.snippets.expectCurlRequest().withContents(
- codeBlock("bash").content("$ curl 'http://localhost/foo' -i -X POST "
- + "-H 'Content-Type: application/x-www-form-urlencoded' "
- + "-d 'a=alpha&b=bravo'"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").method("POST").content("a=alpha&b=bravo")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.param("a", "alpha").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(
+ codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X POST "
+ + "-H 'Content-Type: application/x-www-form-urlencoded' "
+ + "-d 'a=alpha&b=bravo'"));
}
@Test
public void putRequestWithOneParameter() throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo' -i -X PUT -d 'k1=v1'"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").method("PUT").param("k1", "v1").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo' -i -X PUT -d 'k1=v1'"));
}
@Test
public void putRequestWithMultipleParameters() throws IOException {
- this.snippets.expectCurlRequest().withContents(
- codeBlock("bash").content("$ curl 'http://localhost/foo' -i -X PUT"
- + " -d 'k1=v1&k1=v1-bis&k2=v2'"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").method("PUT").param("k1", "v1")
.param("k1", "v1-bis").param("k2", "v2").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(
+ codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X PUT"
+ + " -d 'k1=v1&k1=v1-bis&k2=v2'"));
}
@Test
public void putRequestWithUrlEncodedParameter() throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo' -i -X PUT -d 'k1=a%26b'"));
new CurlRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo")
.method("PUT").param("k1", "a&b").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo' -i -X PUT -d 'k1=a%26b'"));
}
@Test
public void requestWithHeaders() throws IOException {
- this.snippets.expectCurlRequest().withContents(
- codeBlock("bash").content("$ curl 'http://localhost/foo' -i -X GET"
- + " -H 'Content-Type: application/json' -H 'a: alpha'"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(
+ codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X GET"
+ + " -H 'Content-Type: application/json' -H 'a: alpha'"));
}
@Test
public void requestWithHeadersMultiline() throws IOException {
- this.snippets.expectCurlRequest()
- .withContents(codeBlock("bash").content(
- String.format("$ curl 'http://localhost/foo' -i -X GET \\%n"
- + " -H 'Content-Type: application/json' \\%n"
- + " -H 'a: alpha'")));
new CurlRequestSnippet(CliDocumentation.multiLineFormat())
.document(this.operationBuilder.request("http://localhost/foo")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent(String.format("$ curl 'http://localhost/foo' -i -X GET \\%n"
+ + " -H 'Content-Type: application/json' \\%n"
+ + " -H 'a: alpha'")));
}
@Test
public void requestWithCookies() throws IOException {
- this.snippets.expectCurlRequest().withContents(
- codeBlock("bash").content("$ curl 'http://localhost/foo' -i -X GET"
- + " --cookie 'name1=value1;name2=value2'"));
new CurlRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo")
.cookie("name1", "value1").cookie("name2", "value2").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(
+ codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X GET"
+ + " --cookie 'name1=value1;name2=value2'"));
}
@Test
public void multipartPostWithNoSubmittedFileName() throws IOException {
- String expectedContent = "$ curl 'http://localhost/upload' -i -X POST -H "
- + "'Content-Type: multipart/form-data' -F "
- + "'metadata={\"description\": \"foo\"}'";
- this.snippets.expectCurlRequest()
- .withContents(codeBlock("bash").content(expectedContent));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("metadata", "{\"description\": \"foo\"}".getBytes()).build());
+ String expectedContent = "$ curl 'http://localhost/upload' -i -X POST -H "
+ + "'Content-Type: multipart/form-data' -F "
+ + "'metadata={\"description\": \"foo\"}'";
+ assertThat(this.generatedSnippets.curlRequest())
+ .is(codeBlock("bash").withContent(expectedContent));
}
@Test
public void multipartPostWithContentType() throws IOException {
- String expectedContent = "$ curl 'http://localhost/upload' -i -X POST -H "
- + "'Content-Type: multipart/form-data' -F "
- + "'image=@documents/images/example.png;type=image/png'";
- this.snippets.expectCurlRequest()
- .withContents(codeBlock("bash").content(expectedContent));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
.submittedFileName("documents/images/example.png").build());
+ String expectedContent = "$ curl 'http://localhost/upload' -i -X POST -H "
+ + "'Content-Type: multipart/form-data' -F "
+ + "'image=@documents/images/example.png;type=image/png'";
+ assertThat(this.generatedSnippets.curlRequest())
+ .is(codeBlock("bash").withContent(expectedContent));
}
@Test
public void multipartPost() throws IOException {
- String expectedContent = "$ curl 'http://localhost/upload' -i -X POST -H "
- + "'Content-Type: multipart/form-data' -F "
- + "'image=@documents/images/example.png'";
- this.snippets.expectCurlRequest()
- .withContents(codeBlock("bash").content(expectedContent));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").build());
+ String expectedContent = "$ curl 'http://localhost/upload' -i -X POST -H "
+ + "'Content-Type: multipart/form-data' -F "
+ + "'image=@documents/images/example.png'";
+ assertThat(this.generatedSnippets.curlRequest())
+ .is(codeBlock("bash").withContent(expectedContent));
}
@Test
public void multipartPostWithParameters() throws IOException {
- String expectedContent = "$ curl 'http://localhost/upload' -i -X POST -H "
- + "'Content-Type: multipart/form-data' -F "
- + "'image=@documents/images/example.png' -F 'a=apple' -F 'a=avocado' "
- + "-F 'b=banana'";
- this.snippets.expectCurlRequest()
- .withContents(codeBlock("bash").content(expectedContent));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").and()
.param("a", "apple", "avocado").param("b", "banana").build());
+ String expectedContent = "$ curl 'http://localhost/upload' -i -X POST -H "
+ + "'Content-Type: multipart/form-data' -F "
+ + "'image=@documents/images/example.png' -F 'a=apple' -F 'a=avocado' "
+ + "-F 'b=banana'";
+ assertThat(this.generatedSnippets.curlRequest())
+ .is(codeBlock("bash").withContent(expectedContent));
}
@Test
public void basicAuthCredentialsAreSuppliedUsingUserOption() throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo' -i -u 'user:secret' -X GET"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo")
.header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils.encodeToString("user:secret".getBytes()))
.build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo' -i -u 'user:secret' -X GET"));
}
@Test
public void customAttributes() throws IOException {
- this.snippets.expectCurlRequest()
- .withContents(containsString("curl request title"));
- TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
- given(resolver.resolveTemplateResource("curl-request"))
- .willReturn(snippetResource("curl-request-with-title"));
- new CurlRequestSnippet(
- attributes(
- key("title").value("curl request title")),
- this.commandFormatter)
- .document(this.operationBuilder
- .attribute(TemplateEngine.class.getName(),
- new MustacheTemplateEngine(resolver))
- .request("http://localhost/foo").build());
- }
-
- @Test
- public void customHostHeaderIsIncluded() throws IOException {
- this.snippets.expectCurlRequest().withContents(codeBlock("bash").content(
- "$ curl 'http://localhost/foo' -i -X GET -H 'Host: api.example.com'"
- + " -H 'Content-Type: application/json' -H 'a: alpha'"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo")
.header(HttpHeaders.HOST, "api.example.com")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash").withContent(
+ "$ curl 'http://localhost/foo' -i -X GET -H 'Host: api.example.com'"
+ + " -H 'Content-Type: application/json' -H 'a: alpha'"));
}
@Test
public void postWithContentAndParameters() throws IOException {
- this.snippets.expectCurlRequest()
- .withContents(codeBlock("bash")
- .content("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i "
- + "-X POST -d 'Some content'"));
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").param("a", "alpha").method("POST")
.param("b", "bravo").content("Some content").build());
+ assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
+ .withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i "
+ + "-X POST -d 'Some content'"));
}
}
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/HttpieRequestSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/HttpieRequestSnippetTests.java
index 48bcf8ba..6a7d2685 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/HttpieRequestSnippetTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/HttpieRequestSnippetTests.java
@@ -25,17 +25,10 @@ import org.junit.runners.Parameterized;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.restdocs.AbstractSnippetTests;
-import org.springframework.restdocs.templates.TemplateEngine;
import org.springframework.restdocs.templates.TemplateFormat;
-import org.springframework.restdocs.templates.TemplateResourceResolver;
-import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
import org.springframework.util.Base64Utils;
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.Mockito.mock;
-import static org.springframework.restdocs.snippet.Attributes.attributes;
-import static org.springframework.restdocs.snippet.Attributes.key;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link HttpieRequestSnippet}.
@@ -59,339 +52,323 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
@Test
public void getRequest() throws IOException {
- this.snippets.expectHttpieRequest().withContents(
- codeBlock("bash").content("$ http GET 'http://localhost/foo'"));
new HttpieRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo").build());
+ assertThat(this.generatedSnippets.httpieRequest())
+ .is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo'"));
}
@Test
public void getRequestWithParameter() throws IOException {
- this.snippets.expectHttpieRequest().withContents(
- codeBlock("bash").content("$ http GET 'http://localhost/foo?a=alpha'"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").param("a", "alpha").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ http GET 'http://localhost/foo?a=alpha'"));
}
@Test
public void nonGetRequest() throws IOException {
- this.snippets.expectHttpieRequest().withContents(
- codeBlock("bash").content("$ http POST 'http://localhost/foo'"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").method("POST").build());
+ assertThat(this.generatedSnippets.httpieRequest())
+ .is(codeBlock("bash").withContent("$ http POST 'http://localhost/foo'"));
}
@Test
public void requestWithContent() throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content("$ echo 'content' | http GET 'http://localhost/foo'"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").content("content").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ echo 'content' | http GET 'http://localhost/foo'"));
}
@Test
public void getRequestWithQueryString() throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content("$ http GET 'http://localhost/foo?param=value'"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo?param=value").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ http GET 'http://localhost/foo?param=value'"));
}
@Test
public void getRequestWithTotallyOverlappingQueryStringAndParameters()
throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content("$ http GET 'http://localhost/foo?param=value'"));
new HttpieRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/foo?param=value")
.param("param", "value").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ http GET 'http://localhost/foo?param=value'"));
}
@Test
public void getRequestWithPartiallyOverlappingQueryStringAndParameters()
throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content("$ http GET 'http://localhost/foo?a=alpha&b=bravo'"));
new HttpieRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo?a=alpha")
.param("a", "alpha").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ http GET 'http://localhost/foo?a=alpha&b=bravo'"));
}
@Test
public void getRequestWithDisjointQueryStringAndParameters() throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content("$ http GET 'http://localhost/foo?a=alpha&b=bravo'"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo?a=alpha").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ http GET 'http://localhost/foo?a=alpha&b=bravo'"));
}
@Test
public void getRequestWithQueryStringWithNoValue() throws IOException {
- this.snippets.expectHttpieRequest().withContents(
- codeBlock("bash").content("$ http GET 'http://localhost/foo?param'"));
new HttpieRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/foo?param").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(
+ codeBlock("bash").withContent("$ http GET 'http://localhost/foo?param'"));
}
@Test
public void postRequestWithQueryString() throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content("$ http POST 'http://localhost/foo?param=value'"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo?param=value").method("POST").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ http POST 'http://localhost/foo?param=value'"));
}
@Test
public void postRequestWithQueryStringWithNoValue() throws IOException {
- this.snippets.expectHttpieRequest().withContents(
- codeBlock("bash").content("$ http POST 'http://localhost/foo?param'"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo?param").method("POST").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ http POST 'http://localhost/foo?param'"));
}
@Test
public void postRequestWithOneParameter() throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content("$ http --form POST 'http://localhost/foo' 'k1=v1'"));
new HttpieRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo")
.method("POST").param("k1", "v1").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ http --form POST 'http://localhost/foo' 'k1=v1'"));
}
@Test
public void postRequestWithOneParameterWithNoValue() throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content("$ http --form POST 'http://localhost/foo' 'k1='"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").method("POST").param("k1").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ http --form POST 'http://localhost/foo' 'k1='"));
}
@Test
public void postRequestWithMultipleParameters() throws IOException {
- this.snippets.expectHttpieRequest().withContents(
- codeBlock("bash").content("$ http --form POST 'http://localhost/foo'"
- + " 'k1=v1' 'k1=v1-bis' 'k2=v2'"));
new HttpieRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/foo").method("POST")
.param("k1", "v1", "v1-bis").param("k2", "v2").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(
+ codeBlock("bash").withContent("$ http --form POST 'http://localhost/foo'"
+ + " 'k1=v1' 'k1=v1-bis' 'k2=v2'"));
}
@Test
public void postRequestWithUrlEncodedParameter() throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content("$ http --form POST 'http://localhost/foo' 'k1=a&b'"));
new HttpieRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo")
.method("POST").param("k1", "a&b").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ http --form POST 'http://localhost/foo' 'k1=a&b'"));
}
@Test
public void postRequestWithDisjointQueryStringAndParameter() throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content("$ http --form POST 'http://localhost/foo?a=alpha' 'b=bravo'"));
new HttpieRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo?a=alpha")
.method("POST").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.httpieRequest())
+ .is(codeBlock("bash").withContent(
+ "$ http --form POST 'http://localhost/foo?a=alpha' 'b=bravo'"));
}
@Test
public void postRequestWithTotallyOverlappingQueryStringAndParameters()
throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content("$ http POST 'http://localhost/foo?a=alpha&b=bravo'"));
new HttpieRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo")
.method("POST").param("a", "alpha").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ http POST 'http://localhost/foo?a=alpha&b=bravo'"));
}
@Test
public void postRequestWithPartiallyOverlappingQueryStringAndParameters()
throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content("$ http --form POST 'http://localhost/foo?a=alpha' 'b=bravo'"));
new HttpieRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo?a=alpha")
.method("POST").param("a", "alpha").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.httpieRequest())
+ .is(codeBlock("bash").withContent(
+ "$ http --form POST 'http://localhost/foo?a=alpha' 'b=bravo'"));
}
@Test
public void postRequestWithOverlappingParametersAndFormUrlEncodedBody()
throws IOException {
- this.snippets.expectHttpieRequest()
- .withContents(codeBlock("bash").content(
- "$ echo 'a=alpha&b=bravo' | http POST 'http://localhost/foo' "
- + "'Content-Type:application/x-www-form-urlencoded'"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").method("POST").content("a=alpha&b=bravo")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.param("a", "alpha").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.httpieRequest())
+ .is(codeBlock("bash").withContent(
+ "$ echo 'a=alpha&b=bravo' | http POST 'http://localhost/foo' "
+ + "'Content-Type:application/x-www-form-urlencoded'"));
}
@Test
public void putRequestWithOneParameter() throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content("$ http --form PUT 'http://localhost/foo' 'k1=v1'"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").method("PUT").param("k1", "v1").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ http --form PUT 'http://localhost/foo' 'k1=v1'"));
}
@Test
public void putRequestWithMultipleParameters() throws IOException {
- this.snippets.expectHttpieRequest().withContents(
- codeBlock("bash").content("$ http --form PUT 'http://localhost/foo'"
- + " 'k1=v1' 'k1=v1-bis' 'k2=v2'"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").method("PUT").param("k1", "v1")
.param("k1", "v1-bis").param("k2", "v2").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(
+ codeBlock("bash").withContent("$ http --form PUT 'http://localhost/foo'"
+ + " 'k1=v1' 'k1=v1-bis' 'k2=v2'"));
}
@Test
public void putRequestWithUrlEncodedParameter() throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content("$ http --form PUT 'http://localhost/foo' 'k1=a&b'"));
new HttpieRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo")
.method("PUT").param("k1", "a&b").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ http --form PUT 'http://localhost/foo' 'k1=a&b'"));
}
@Test
public void requestWithHeaders() throws IOException {
- this.snippets.expectHttpieRequest().withContents(
- codeBlock("bash").content("$ http GET 'http://localhost/foo'"
- + " 'Content-Type:application/json' 'a:alpha'"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
+ assertThat(this.generatedSnippets.httpieRequest())
+ .is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo'"
+ + " 'Content-Type:application/json' 'a:alpha'"));
}
@Test
public void requestWithHeadersMultiline() throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content(String.format("$ http GET 'http://localhost/foo' \\%n"
- + " 'Content-Type:application/json' \\%n 'a:alpha'")));
new HttpieRequestSnippet(CliDocumentation.multiLineFormat())
.document(this.operationBuilder.request("http://localhost/foo")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent(String.format("$ http GET 'http://localhost/foo' \\%n"
+ + " 'Content-Type:application/json' \\%n 'a:alpha'")));
}
@Test
public void requestWithCookies() throws IOException {
- this.snippets.expectHttpieRequest().withContents(
- codeBlock("bash").content("$ http GET 'http://localhost/foo'"
- + " 'Cookie:name1=value1' 'Cookie:name2=value2'"));
new HttpieRequestSnippet(this.commandFormatter)
.document(this.operationBuilder.request("http://localhost/foo")
.cookie("name1", "value1").cookie("name2", "value2").build());
+ assertThat(this.generatedSnippets.httpieRequest())
+ .is(codeBlock("bash").withContent("$ http GET 'http://localhost/foo'"
+ + " 'Cookie:name1=value1' 'Cookie:name2=value2'"));
}
@Test
public void multipartPostWithNoSubmittedFileName() throws IOException {
- String expectedContent = "$ http --form POST 'http://localhost/upload'"
- + " 'metadata'@<(echo '{\"description\": \"foo\"}')";
- this.snippets.expectHttpieRequest()
- .withContents(codeBlock("bash").content(expectedContent));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("metadata", "{\"description\": \"foo\"}".getBytes()).build());
+ String expectedContent = "$ http --form POST 'http://localhost/upload'"
+ + " 'metadata'@<(echo '{\"description\": \"foo\"}')";
+ assertThat(this.generatedSnippets.httpieRequest())
+ .is(codeBlock("bash").withContent(expectedContent));
}
@Test
public void multipartPostWithContentType() throws IOException {
- // httpie does not yet support manually set content type by part
- String expectedContent = "$ http --form POST 'http://localhost/upload'"
- + " 'image'@'documents/images/example.png'";
- this.snippets.expectHttpieRequest()
- .withContents(codeBlock("bash").content(expectedContent));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
.submittedFileName("documents/images/example.png").build());
+ // httpie does not yet support manually set content type by part
+ String expectedContent = "$ http --form POST 'http://localhost/upload'"
+ + " 'image'@'documents/images/example.png'";
+ assertThat(this.generatedSnippets.httpieRequest())
+ .is(codeBlock("bash").withContent(expectedContent));
}
@Test
public void multipartPost() throws IOException {
- String expectedContent = "$ http --form POST 'http://localhost/upload'"
- + " 'image'@'documents/images/example.png'";
- this.snippets.expectHttpieRequest()
- .withContents(codeBlock("bash").content(expectedContent));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").build());
+ String expectedContent = "$ http --form POST 'http://localhost/upload'"
+ + " 'image'@'documents/images/example.png'";
+ assertThat(this.generatedSnippets.httpieRequest())
+ .is(codeBlock("bash").withContent(expectedContent));
}
@Test
public void multipartPostWithParameters() throws IOException {
- String expectedContent = "$ http --form POST 'http://localhost/upload'"
- + " 'image'@'documents/images/example.png' 'a=apple' 'a=avocado'"
- + " 'b=banana'";
- this.snippets.expectHttpieRequest()
- .withContents(codeBlock("bash").content(expectedContent));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").and()
.param("a", "apple", "avocado").param("b", "banana").build());
+ String expectedContent = "$ http --form POST 'http://localhost/upload'"
+ + " 'image'@'documents/images/example.png' 'a=apple' 'a=avocado'"
+ + " 'b=banana'";
+ assertThat(this.generatedSnippets.httpieRequest())
+ .is(codeBlock("bash").withContent(expectedContent));
}
@Test
public void basicAuthCredentialsAreSuppliedUsingAuthOption() throws IOException {
- this.snippets.expectHttpieRequest().withContents(codeBlock("bash")
- .content("$ http --auth 'user:secret' GET 'http://localhost/foo'"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo")
.header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils.encodeToString("user:secret".getBytes()))
.build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ http --auth 'user:secret' GET 'http://localhost/foo'"));
}
@Test
public void customAttributes() throws IOException {
- this.snippets.expectHttpieRequest()
- .withContents(containsString("httpie request title"));
- TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
- given(resolver.resolveTemplateResource("httpie-request"))
- .willReturn(snippetResource("httpie-request-with-title"));
- new HttpieRequestSnippet(
- attributes(key("title")
- .value("httpie request title")),
- this.commandFormatter)
- .document(this.operationBuilder
- .attribute(TemplateEngine.class.getName(),
- new MustacheTemplateEngine(resolver))
- .request("http://localhost/foo").build());
- }
-
- @Test
- public void customHostHeaderIsIncluded() throws IOException {
- this.snippets.expectHttpieRequest()
- .withContents(codeBlock("bash").content(
- "$ http GET 'http://localhost/foo' 'Host:api.example.com'"
- + " 'Content-Type:application/json' 'a:alpha'"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo")
.header(HttpHeaders.HOST, "api.example.com")
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
+ assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash")
+ .withContent("$ http GET 'http://localhost/foo' 'Host:api.example.com'"
+ + " 'Content-Type:application/json' 'a:alpha'"));
}
@Test
public void postWithContentAndParameters() throws IOException {
- this.snippets.expectHttpieRequest().withContents(
- codeBlock("bash").content("$ echo 'Some content' | http POST "
- + "'http://localhost/foo?a=alpha&b=bravo'"));
new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").method("POST").param("a", "alpha")
.param("b", "bravo").content("Some content").build());
+ assertThat(this.generatedSnippets.httpieRequest())
+ .is(codeBlock("bash").withContent("$ echo 'Some content' | http POST "
+ + "'http://localhost/foo?a=alpha&b=bravo'"));
}
}
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/config/RestDocumentationConfigurerTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/config/RestDocumentationConfigurerTests.java
index c4d16936..b0f554d2 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/config/RestDocumentationConfigurerTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/config/RestDocumentationConfigurerTests.java
@@ -22,7 +22,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import org.hamcrest.Matchers;
import org.junit.Test;
import org.springframework.http.HttpHeaders;
@@ -54,13 +53,7 @@ import org.springframework.restdocs.templates.mustache.AsciidoctorTableCellConte
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
import org.springframework.test.util.ReflectionTestUtils;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.Matchers.contains;
-import static org.hamcrest.Matchers.hasEntry;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/**
@@ -78,37 +71,38 @@ public class RestDocumentationConfigurerTests {
public void defaultConfiguration() {
Map configuration = new HashMap<>();
this.configurer.apply(configuration, createContext());
- assertThat(configuration, hasEntry(equalTo(TemplateEngine.class.getName()),
- instanceOf(MustacheTemplateEngine.class)));
- assertThat(configuration, hasEntry(equalTo(WriterResolver.class.getName()),
- instanceOf(StandardWriterResolver.class)));
- assertThat(configuration,
- hasEntry(equalTo(
- RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS),
- instanceOf(List.class)));
+ assertThat(configuration).containsKey(TemplateEngine.class.getName());
+ assertThat(configuration.get(TemplateEngine.class.getName()))
+ .isInstanceOf(MustacheTemplateEngine.class);
+ assertThat(configuration).containsKey(WriterResolver.class.getName());
+ assertThat(configuration.get(WriterResolver.class.getName()))
+ .isInstanceOf(StandardWriterResolver.class);
+ assertThat(configuration)
+ .containsKey(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
+ assertThat(configuration
+ .get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS))
+ .isInstanceOf(List.class);
List defaultSnippets = (List) configuration
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
- assertThat(defaultSnippets,
- contains(instanceOf(CurlRequestSnippet.class),
- instanceOf(HttpieRequestSnippet.class),
- instanceOf(HttpRequestSnippet.class),
- instanceOf(HttpResponseSnippet.class),
- instanceOf(RequestBodySnippet.class),
- instanceOf(ResponseBodySnippet.class)));
- assertThat(configuration, hasEntry(equalTo(SnippetConfiguration.class.getName()),
- instanceOf(SnippetConfiguration.class)));
+ assertThat(defaultSnippets).extracting("class").containsExactlyInAnyOrder(
+ CurlRequestSnippet.class, HttpieRequestSnippet.class,
+ HttpRequestSnippet.class, HttpResponseSnippet.class,
+ RequestBodySnippet.class, ResponseBodySnippet.class);
+ assertThat(configuration).containsKey(SnippetConfiguration.class.getName());
+ assertThat(configuration.get(SnippetConfiguration.class.getName()))
+ .isInstanceOf(SnippetConfiguration.class);
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
.get(SnippetConfiguration.class.getName());
- assertThat(snippetConfiguration.getEncoding(), is(equalTo("UTF-8")));
- assertThat(snippetConfiguration.getTemplateFormat().getId(),
- is(equalTo(TemplateFormats.asciidoctor().getId())));
+ assertThat(snippetConfiguration.getEncoding()).isEqualTo("UTF-8");
+ assertThat(snippetConfiguration.getTemplateFormat().getId())
+ .isEqualTo(TemplateFormats.asciidoctor().getId());
OperationRequestPreprocessor defaultOperationRequestPreprocessor = (OperationRequestPreprocessor) configuration
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_REQUEST_PREPROCESSOR);
- assertThat(defaultOperationRequestPreprocessor, is(nullValue()));
+ assertThat(defaultOperationRequestPreprocessor).isNull();
OperationResponsePreprocessor defaultOperationResponsePreprocessor = (OperationResponsePreprocessor) configuration
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_RESPONSE_PREPROCESSOR);
- assertThat(defaultOperationResponsePreprocessor, is(nullValue()));
+ assertThat(defaultOperationResponsePreprocessor).isNull();
}
@Test
@@ -117,8 +111,8 @@ public class RestDocumentationConfigurerTests {
TemplateEngine templateEngine = mock(TemplateEngine.class);
this.configurer.templateEngine(templateEngine).apply(configuration,
createContext());
- assertThat(configuration, Matchers.hasEntry(
- TemplateEngine.class.getName(), templateEngine));
+ assertThat(configuration).containsEntry(TemplateEngine.class.getName(),
+ templateEngine);
}
@Test
@@ -127,8 +121,8 @@ public class RestDocumentationConfigurerTests {
WriterResolver writerResolver = mock(WriterResolver.class);
this.configurer.writerResolver(writerResolver).apply(configuration,
createContext());
- assertThat(configuration, Matchers.hasEntry(
- WriterResolver.class.getName(), writerResolver));
+ assertThat(configuration).containsEntry(WriterResolver.class.getName(),
+ writerResolver);
}
@Test
@@ -136,14 +130,16 @@ public class RestDocumentationConfigurerTests {
Map configuration = new HashMap<>();
this.configurer.snippets().withDefaults(CliDocumentation.curlRequest())
.apply(configuration, createContext());
- assertThat(configuration,
- hasEntry(equalTo(
- RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS),
- instanceOf(List.class)));
+ assertThat(configuration)
+ .containsKey(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
+ assertThat(configuration
+ .get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS))
+ .isInstanceOf(List.class);
@SuppressWarnings("unchecked")
List defaultSnippets = (List) configuration
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
- assertThat(defaultSnippets, contains(instanceOf(CurlRequestSnippet.class)));
+ assertThat(defaultSnippets).hasSize(1);
+ assertThat(defaultSnippets).hasOnlyElementsOfType(CurlRequestSnippet.class);
}
@SuppressWarnings("unchecked")
@@ -153,19 +149,17 @@ public class RestDocumentationConfigurerTests {
Snippet snippet = mock(Snippet.class);
this.configurer.snippets().withAdditionalDefaults(snippet).apply(configuration,
createContext());
- assertThat(configuration,
- hasEntry(equalTo(
- RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS),
- instanceOf(List.class)));
+ assertThat(configuration)
+ .containsKey(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
+ assertThat(configuration
+ .get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS))
+ .isInstanceOf(List.class);
List defaultSnippets = (List) configuration
.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
- assertThat(defaultSnippets,
- contains(instanceOf(CurlRequestSnippet.class),
- instanceOf(HttpieRequestSnippet.class),
- instanceOf(HttpRequestSnippet.class),
- instanceOf(HttpResponseSnippet.class),
- instanceOf(RequestBodySnippet.class),
- instanceOf(ResponseBodySnippet.class), equalTo(snippet)));
+ assertThat(defaultSnippets).extracting("class").containsExactlyInAnyOrder(
+ CurlRequestSnippet.class, HttpieRequestSnippet.class,
+ HttpRequestSnippet.class, HttpResponseSnippet.class,
+ RequestBodySnippet.class, ResponseBodySnippet.class, snippet.getClass());
}
@Test
@@ -173,11 +167,12 @@ public class RestDocumentationConfigurerTests {
Map configuration = new HashMap<>();
this.configurer.snippets().withEncoding("ISO 8859-1").apply(configuration,
createContext());
- assertThat(configuration, hasEntry(equalTo(SnippetConfiguration.class.getName()),
- instanceOf(SnippetConfiguration.class)));
+ assertThat(configuration).containsKey(SnippetConfiguration.class.getName());
+ assertThat(configuration.get(SnippetConfiguration.class.getName()))
+ .isInstanceOf(SnippetConfiguration.class);
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
.get(SnippetConfiguration.class.getName());
- assertThat(snippetConfiguration.getEncoding(), is(equalTo("ISO 8859-1")));
+ assertThat(snippetConfiguration.getEncoding()).isEqualTo("ISO 8859-1");
}
@Test
@@ -185,12 +180,13 @@ public class RestDocumentationConfigurerTests {
Map configuration = new HashMap<>();
this.configurer.snippets().withTemplateFormat(TemplateFormats.markdown())
.apply(configuration, createContext());
- assertThat(configuration, hasEntry(equalTo(SnippetConfiguration.class.getName()),
- instanceOf(SnippetConfiguration.class)));
+ assertThat(configuration).containsKey(SnippetConfiguration.class.getName());
+ assertThat(configuration.get(SnippetConfiguration.class.getName()))
+ .isInstanceOf(SnippetConfiguration.class);
SnippetConfiguration snippetConfiguration = (SnippetConfiguration) configuration
.get(SnippetConfiguration.class.getName());
- assertThat(snippetConfiguration.getTemplateFormat().getId(),
- is(equalTo(TemplateFormats.markdown().getId())));
+ assertThat(snippetConfiguration.getTemplateFormat().getId())
+ .isEqualTo(TemplateFormats.markdown().getId());
}
@SuppressWarnings("unchecked")
@@ -203,8 +199,9 @@ public class RestDocumentationConfigurerTests {
MustacheTemplateEngine mustacheTemplateEngine = (MustacheTemplateEngine) templateEngine;
Map templateContext = (Map) ReflectionTestUtils
.getField(mustacheTemplateEngine, "context");
- assertThat(templateContext, hasEntry(equalTo("tableCellContent"),
- instanceOf(AsciidoctorTableCellContentLambda.class)));
+ assertThat(templateContext).containsKey("tableCellContent");
+ assertThat(templateContext.get("tableCellContent"))
+ .isInstanceOf(AsciidoctorTableCellContentLambda.class);
}
@SuppressWarnings("unchecked")
@@ -218,7 +215,7 @@ public class RestDocumentationConfigurerTests {
MustacheTemplateEngine mustacheTemplateEngine = (MustacheTemplateEngine) templateEngine;
Map templateContext = (Map) ReflectionTestUtils
.getField(mustacheTemplateEngine, "context");
- assertThat(templateContext.size(), equalTo(0));
+ assertThat(templateContext.size()).isEqualTo(0);
}
@Test
@@ -235,8 +232,8 @@ public class RestDocumentationConfigurerTests {
OperationRequest request = new OperationRequestFactory().create(
URI.create("http://localhost:8080"), HttpMethod.GET, null, headers, null,
Collections.emptyList());
- assertThat(preprocessor.preprocess(request).getHeaders().get("Foo"),
- is(nullValue()));
+ assertThat(preprocessor.preprocess(request).getHeaders())
+ .doesNotContainKey("Foo");
}
@Test
@@ -252,8 +249,8 @@ public class RestDocumentationConfigurerTests {
headers.add("Foo", "value");
OperationResponse response = new OperationResponseFactory().create(HttpStatus.OK,
headers, null);
- assertThat(preprocessor.preprocess(response).getHeaders().get("Foo"),
- is(nullValue()));
+ assertThat(preprocessor.preprocess(response).getHeaders())
+ .doesNotContainKey("Foo");
}
private RestDocumentationContext createContext() {
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/constraints/ConstraintDescriptionsTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/constraints/ConstraintDescriptionsTests.java
index 70c0d1ab..6d9e057c 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/constraints/ConstraintDescriptionsTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/constraints/ConstraintDescriptionsTests.java
@@ -21,10 +21,7 @@ import java.util.Collections;
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.contains;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -56,16 +53,16 @@ public class ConstraintDescriptionsTests {
.willReturn("Bravo");
given(this.constraintDescriptionResolver.resolveDescription(constraint2))
.willReturn("Alpha");
- assertThat(this.constraintDescriptions.descriptionsForProperty("foo"),
- contains("Alpha", "Bravo"));
+ assertThat(this.constraintDescriptions.descriptionsForProperty("foo"))
+ .containsExactly("Alpha", "Bravo");
}
@Test
public void emptyListOfDescriptionsWhenThereAreNoConstraints() {
given(this.constraintResolver.resolveForProperty("foo", Constrained.class))
.willReturn(Collections.emptyList());
- assertThat(this.constraintDescriptions.descriptionsForProperty("foo").size(),
- is(equalTo(0)));
+ assertThat(this.constraintDescriptions.descriptionsForProperty("foo").size())
+ .isEqualTo(0);
}
private static class Constrained {
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/constraints/ResourceBundleConstraintDescriptionResolverTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/constraints/ResourceBundleConstraintDescriptionResolverTests.java
index 95d26e91..8be26ab2 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/constraints/ResourceBundleConstraintDescriptionResolverTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/constraints/ResourceBundleConstraintDescriptionResolverTests.java
@@ -65,9 +65,7 @@ import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.util.Assert;
import org.springframework.util.ReflectionUtils;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ResourceBundleConstraintDescriptionResolver}.
@@ -80,217 +78,214 @@ public class ResourceBundleConstraintDescriptionResolverTests {
@Test
public void defaultMessageAssertFalse() {
- assertThat(constraintDescriptionForField("assertFalse"),
- is(equalTo("Must be false")));
+ assertThat(constraintDescriptionForField("assertFalse"))
+ .isEqualTo("Must be false");
}
@Test
public void defaultMessageAssertTrue() {
- assertThat(constraintDescriptionForField("assertTrue"),
- is(equalTo("Must be true")));
+ assertThat(constraintDescriptionForField("assertTrue")).isEqualTo("Must be true");
}
@Test
public void defaultMessageCodePointLength() {
- assertThat(constraintDescriptionForField("codePointLength"),
- is(equalTo("Code point length must be between 2 and 5 inclusive")));
+ assertThat(constraintDescriptionForField("codePointLength"))
+ .isEqualTo("Code point length must be between 2 and 5 inclusive");
}
@Test
public void defaultMessageCurrency() {
- assertThat(constraintDescriptionForField("currency"),
- is(equalTo("Must be in an accepted currency unit (GBP, USD)")));
+ assertThat(constraintDescriptionForField("currency"))
+ .isEqualTo("Must be in an accepted currency unit (GBP, USD)");
}
@Test
public void defaultMessageDecimalMax() {
- assertThat(constraintDescriptionForField("decimalMax"),
- is(equalTo("Must be at most 9.875")));
+ assertThat(constraintDescriptionForField("decimalMax"))
+ .isEqualTo("Must be at most 9.875");
}
@Test
public void defaultMessageDecimalMin() {
- assertThat(constraintDescriptionForField("decimalMin"),
- is(equalTo("Must be at least 1.5")));
+ assertThat(constraintDescriptionForField("decimalMin"))
+ .isEqualTo("Must be at least 1.5");
}
@Test
public void defaultMessageDigits() {
- assertThat(constraintDescriptionForField("digits"), is(
- equalTo("Must have at most 2 integral digits and 5 fractional digits")));
+ assertThat(constraintDescriptionForField("digits"))
+ .isEqualTo("Must have at most 2 integral digits and 5 fractional digits");
}
@Test
public void defaultMessageFuture() {
- assertThat(constraintDescriptionForField("future"),
- is(equalTo("Must be in the future")));
+ assertThat(constraintDescriptionForField("future"))
+ .isEqualTo("Must be in the future");
}
@Test
public void defaultMessageFutureOrPresent() {
- assertThat(constraintDescriptionForField("futureOrPresent"),
- is(equalTo("Must be in the future or the present")));
+ assertThat(constraintDescriptionForField("futureOrPresent"))
+ .isEqualTo("Must be in the future or the present");
}
@Test
public void defaultMessageMax() {
- assertThat(constraintDescriptionForField("max"),
- is(equalTo("Must be at most 10")));
+ assertThat(constraintDescriptionForField("max")).isEqualTo("Must be at most 10");
}
@Test
public void defaultMessageMin() {
- assertThat(constraintDescriptionForField("min"),
- is(equalTo("Must be at least 10")));
+ assertThat(constraintDescriptionForField("min")).isEqualTo("Must be at least 10");
}
@Test
public void defaultMessageNotNull() {
- assertThat(constraintDescriptionForField("notNull"),
- is(equalTo("Must not be null")));
+ assertThat(constraintDescriptionForField("notNull"))
+ .isEqualTo("Must not be null");
}
@Test
public void defaultMessageNull() {
- assertThat(constraintDescriptionForField("nul"), is(equalTo("Must be null")));
+ assertThat(constraintDescriptionForField("nul")).isEqualTo("Must be null");
}
@Test
public void defaultMessagePast() {
- assertThat(constraintDescriptionForField("past"),
- is(equalTo("Must be in the past")));
+ assertThat(constraintDescriptionForField("past"))
+ .isEqualTo("Must be in the past");
}
@Test
public void defaultMessagePastOrPresent() {
- assertThat(constraintDescriptionForField("pastOrPresent"),
- is(equalTo("Must be in the past or the present")));
+ assertThat(constraintDescriptionForField("pastOrPresent"))
+ .isEqualTo("Must be in the past or the present");
}
@Test
public void defaultMessagePattern() {
- assertThat(constraintDescriptionForField("pattern"),
- is(equalTo("Must match the regular expression `[A-Z][a-z]+`")));
+ assertThat(constraintDescriptionForField("pattern"))
+ .isEqualTo("Must match the regular expression `[A-Z][a-z]+`");
}
@Test
public void defaultMessageSize() {
- assertThat(constraintDescriptionForField("size"),
- is(equalTo("Size must be between 2 and 10 inclusive")));
+ assertThat(constraintDescriptionForField("size"))
+ .isEqualTo("Size must be between 2 and 10 inclusive");
}
@Test
public void defaultMessageCreditCardNumber() {
- assertThat(constraintDescriptionForField("creditCardNumber"),
- is(equalTo("Must be a well-formed credit card number")));
+ assertThat(constraintDescriptionForField("creditCardNumber"))
+ .isEqualTo("Must be a well-formed credit card number");
}
@Test
public void defaultMessageEan() {
- assertThat(constraintDescriptionForField("ean"),
- is(equalTo("Must be a well-formed EAN13 number")));
+ assertThat(constraintDescriptionForField("ean"))
+ .isEqualTo("Must be a well-formed EAN13 number");
}
@Test
public void defaultMessageEmail() {
- assertThat(constraintDescriptionForField("email"),
- is(equalTo("Must be a well-formed email address")));
+ assertThat(constraintDescriptionForField("email"))
+ .isEqualTo("Must be a well-formed email address");
}
@Test
public void defaultMessageEmailHibernateValidator() {
- assertThat(constraintDescriptionForField("emailHibernateValidator"),
- is(equalTo("Must be a well-formed email address")));
+ assertThat(constraintDescriptionForField("emailHibernateValidator"))
+ .isEqualTo("Must be a well-formed email address");
}
@Test
public void defaultMessageLength() {
- assertThat(constraintDescriptionForField("length"),
- is(equalTo("Length must be between 2 and 10 inclusive")));
+ assertThat(constraintDescriptionForField("length"))
+ .isEqualTo("Length must be between 2 and 10 inclusive");
}
@Test
public void defaultMessageLuhnCheck() {
- assertThat(constraintDescriptionForField("luhnCheck"),
- is(equalTo("Must pass the Luhn Modulo 10 checksum algorithm")));
+ assertThat(constraintDescriptionForField("luhnCheck"))
+ .isEqualTo("Must pass the Luhn Modulo 10 checksum algorithm");
}
@Test
public void defaultMessageMod10Check() {
- assertThat(constraintDescriptionForField("mod10Check"),
- is(equalTo("Must pass the Mod10 checksum algorithm")));
+ assertThat(constraintDescriptionForField("mod10Check"))
+ .isEqualTo("Must pass the Mod10 checksum algorithm");
}
@Test
public void defaultMessageMod11Check() {
- assertThat(constraintDescriptionForField("mod11Check"),
- is(equalTo("Must pass the Mod11 checksum algorithm")));
+ assertThat(constraintDescriptionForField("mod11Check"))
+ .isEqualTo("Must pass the Mod11 checksum algorithm");
}
@Test
public void defaultMessageNegative() {
- assertThat(constraintDescriptionForField("negative"),
- is(equalTo("Must be negative")));
+ assertThat(constraintDescriptionForField("negative"))
+ .isEqualTo("Must be negative");
}
@Test
public void defaultMessageNegativeOrZero() {
- assertThat(constraintDescriptionForField("negativeOrZero"),
- is(equalTo("Must be negative or zero")));
+ assertThat(constraintDescriptionForField("negativeOrZero"))
+ .isEqualTo("Must be negative or zero");
}
@Test
public void defaultMessageNotBlank() {
- assertThat(constraintDescriptionForField("notBlank"),
- is(equalTo("Must not be blank")));
+ assertThat(constraintDescriptionForField("notBlank"))
+ .isEqualTo("Must not be blank");
}
@Test
public void defaultMessageNotBlankHibernateValidator() {
- assertThat(constraintDescriptionForField("notBlankHibernateValidator"),
- is(equalTo("Must not be blank")));
+ assertThat(constraintDescriptionForField("notBlankHibernateValidator"))
+ .isEqualTo("Must not be blank");
}
@Test
public void defaultMessageNotEmpty() {
- assertThat(constraintDescriptionForField("notEmpty"),
- is(equalTo("Must not be empty")));
+ assertThat(constraintDescriptionForField("notEmpty"))
+ .isEqualTo("Must not be empty");
}
@Test
public void defaultMessageNotEmptyHibernateValidator() {
- assertThat(constraintDescriptionForField("notEmpty"),
- is(equalTo("Must not be empty")));
+ assertThat(constraintDescriptionForField("notEmpty"))
+ .isEqualTo("Must not be empty");
}
@Test
public void defaultMessagePositive() {
- assertThat(constraintDescriptionForField("positive"),
- is(equalTo("Must be positive")));
+ assertThat(constraintDescriptionForField("positive"))
+ .isEqualTo("Must be positive");
}
@Test
public void defaultMessagePositiveOrZero() {
- assertThat(constraintDescriptionForField("positiveOrZero"),
- is(equalTo("Must be positive or zero")));
+ assertThat(constraintDescriptionForField("positiveOrZero"))
+ .isEqualTo("Must be positive or zero");
}
@Test
public void defaultMessageRange() {
- assertThat(constraintDescriptionForField("range"),
- is(equalTo("Must be at least 10 and at most 100")));
+ assertThat(constraintDescriptionForField("range"))
+ .isEqualTo("Must be at least 10 and at most 100");
}
@Test
public void defaultMessageSafeHtml() {
- assertThat(constraintDescriptionForField("safeHtml"),
- is(equalTo("Must be safe HTML")));
+ assertThat(constraintDescriptionForField("safeHtml"))
+ .isEqualTo("Must be safe HTML");
}
@Test
public void defaultMessageUrl() {
- assertThat(constraintDescriptionForField("url"),
- is(equalTo("Must be a well-formed URL")));
+ assertThat(constraintDescriptionForField("url"))
+ .isEqualTo("Must be a well-formed URL");
}
@Test
@@ -313,7 +308,7 @@ public class ResourceBundleConstraintDescriptionResolverTests {
String description = new ResourceBundleConstraintDescriptionResolver()
.resolveDescription(new Constraint(NotNull.class.getName(),
Collections.emptyMap()));
- assertThat(description, is(equalTo("Should not be null")));
+ assertThat(description).isEqualTo("Should not be null");
}
finally {
@@ -335,7 +330,7 @@ public class ResourceBundleConstraintDescriptionResolverTests {
String description = new ResourceBundleConstraintDescriptionResolver(bundle)
.resolveDescription(new Constraint(NotNull.class.getName(),
Collections.emptyMap()));
- assertThat(description, is(equalTo("Not null")));
+ assertThat(description).isEqualTo("Not null");
}
private String constraintDescriptionForField(String name) {
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/constraints/ValidatorConstraintResolverTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/constraints/ValidatorConstraintResolverTests.java
index 96b176b0..8734a3c1 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/constraints/ValidatorConstraintResolverTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/constraints/ValidatorConstraintResolverTests.java
@@ -32,16 +32,13 @@ import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import javax.validation.constraints.Size;
-import org.hamcrest.BaseMatcher;
-import org.hamcrest.Description;
+import org.assertj.core.api.Condition;
+import org.assertj.core.description.TextDescription;
import org.hibernate.validator.constraints.CompositionType;
import org.hibernate.validator.constraints.ConstraintComposition;
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.containsInAnyOrder;
-import static org.hamcrest.Matchers.hasSize;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ValidatorConstraintResolver}.
@@ -56,36 +53,36 @@ public class ValidatorConstraintResolverTests {
public void singleFieldConstraint() {
List constraints = this.resolver.resolveForProperty("single",
ConstrainedFields.class);
- assertThat(constraints, hasSize(1));
- assertThat(constraints.get(0).getName(), is(NotNull.class.getName()));
+ assertThat(constraints).hasSize(1);
+ assertThat(constraints.get(0).getName()).isEqualTo(NotNull.class.getName());
}
- @SuppressWarnings("unchecked")
@Test
public void multipleFieldConstraints() {
List constraints = this.resolver.resolveForProperty("multiple",
ConstrainedFields.class);
- assertThat(constraints, hasSize(2));
- assertThat(constraints, containsInAnyOrder(constraint(NotNull.class),
- constraint(Size.class).config("min", 8).config("max", 16)));
+ assertThat(constraints).hasSize(2);
+ assertThat(constraints.get(0)).is(constraint(NotNull.class));
+ assertThat(constraints.get(1))
+ .is(constraint(Size.class).config("min", 8).config("max", 16));
}
@Test
public void noFieldConstraints() {
List constraints = this.resolver.resolveForProperty("none",
ConstrainedFields.class);
- assertThat(constraints, hasSize(0));
+ assertThat(constraints).hasSize(0);
}
@Test
public void compositeConstraint() {
List constraints = this.resolver.resolveForProperty("composite",
ConstrainedFields.class);
- assertThat(constraints, hasSize(1));
+ assertThat(constraints).hasSize(1);
}
- private ConstraintMatcher constraint(final Class extends Annotation> annotation) {
- return new ConstraintMatcher(annotation);
+ private ConstraintCondition constraint(final Class extends Annotation> annotation) {
+ return new ConstraintCondition(annotation);
}
private static class ConstrainedFields {
@@ -121,27 +118,25 @@ public class ValidatorConstraintResolverTests {
}
- private static final class ConstraintMatcher extends BaseMatcher {
+ private static final class ConstraintCondition extends Condition {
private final Class> annotation;
private final Map configuration = new HashMap<>();
- private ConstraintMatcher(Class> annotation) {
+ private ConstraintCondition(Class> annotation) {
this.annotation = annotation;
+ as(new TextDescription("Constraint named %s with configuration %s",
+ this.annotation, this.configuration));
}
- public ConstraintMatcher config(String key, Object value) {
+ public ConstraintCondition config(String key, Object value) {
this.configuration.put(key, value);
return this;
}
@Override
- public boolean matches(Object item) {
- if (!(item instanceof Constraint)) {
- return false;
- }
- Constraint constraint = (Constraint) item;
+ public boolean matches(Constraint constraint) {
if (!constraint.getName().equals(this.annotation.getName())) {
return false;
}
@@ -154,12 +149,6 @@ public class ValidatorConstraintResolverTests {
return true;
}
- @Override
- public void describeTo(Description description) {
- description.appendText("Constraint named " + this.annotation.getName()
- + " with configuration " + this.configuration);
- }
-
}
}
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/RequestHeadersSnippetFailureTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/RequestHeadersSnippetFailureTests.java
index e2eba481..95f27678 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/RequestHeadersSnippetFailureTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/RequestHeadersSnippetFailureTests.java
@@ -24,7 +24,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.restdocs.snippet.SnippetException;
-import org.springframework.restdocs.test.ExpectedSnippets;
import org.springframework.restdocs.test.OperationBuilder;
import static org.hamcrest.CoreMatchers.endsWith;
@@ -43,9 +42,6 @@ public class RequestHeadersSnippetFailureTests {
@Rule
public OperationBuilder operationBuilder = new OperationBuilder(asciidoctor());
- @Rule
- public ExpectedSnippets snippets = new ExpectedSnippets(asciidoctor());
-
@Rule
public ExpectedException thrown = ExpectedException.none();
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/RequestHeadersSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/RequestHeadersSnippetTests.java
index 81318305..26820edd 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/RequestHeadersSnippetTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/RequestHeadersSnippetTests.java
@@ -28,7 +28,7 @@ import org.springframework.restdocs.templates.TemplateFormats;
import org.springframework.restdocs.templates.TemplateResourceResolver;
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
-import static org.hamcrest.CoreMatchers.containsString;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
@@ -49,12 +49,6 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
@Test
public void requestWithHeaders() throws IOException {
- this.snippets.expectRequestHeaders()
- .withContents(tableWithHeader("Name", "Description")
- .row("`X-Test`", "one").row("`Accept`", "two")
- .row("`Accept-Encoding`", "three")
- .row("`Accept-Language`", "four").row("`Cache-Control`", "five")
- .row("`Connection`", "six"));
new RequestHeadersSnippet(
Arrays.asList(headerWithName("X-Test").description("one"),
headerWithName("Accept").description("two"),
@@ -68,32 +62,36 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
.header("Accept-Language", "en-US,en;q=0.5")
.header("Cache-Control", "max-age=0")
.header("Connection", "keep-alive").build());
+ assertThat(this.generatedSnippets.requestHeaders())
+ .is(tableWithHeader("Name", "Description").row("`X-Test`", "one")
+ .row("`Accept`", "two").row("`Accept-Encoding`", "three")
+ .row("`Accept-Language`", "four").row("`Cache-Control`", "five")
+ .row("`Connection`", "six"));
}
@Test
public void caseInsensitiveRequestHeaders() throws IOException {
- this.snippets.expectRequestHeaders().withContents(
- tableWithHeader("Name", "Description").row("`X-Test`", "one"));
new RequestHeadersSnippet(
Arrays.asList(headerWithName("X-Test").description("one")))
.document(this.operationBuilder.request("/")
.header("X-test", "test").build());
+ assertThat(this.generatedSnippets.requestHeaders())
+ .is(tableWithHeader("Name", "Description").row("`X-Test`", "one"));
}
@Test
public void undocumentedRequestHeader() throws IOException {
- this.snippets.expectRequestHeaders().withContents(
- tableWithHeader("Name", "Description").row("`X-Test`", "one"));
new RequestHeadersSnippet(
Arrays.asList(headerWithName("X-Test").description("one")))
.document(this.operationBuilder.request("http://localhost")
.header("X-Test", "test").header("Accept", "*/*")
.build());
+ assertThat(this.generatedSnippets.requestHeaders())
+ .is(tableWithHeader("Name", "Description").row("`X-Test`", "one"));
}
@Test
public void requestHeadersWithCustomAttributes() throws IOException {
- this.snippets.expectRequestHeaders().withContents(containsString("Custom title"));
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
given(resolver.resolveTemplateResource("request-headers"))
.willReturn(snippetResource("request-headers-with-title"));
@@ -107,15 +105,11 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
resolver))
.request("http://localhost")
.header("X-Test", "test").build());
+ assertThat(this.generatedSnippets.requestHeaders()).contains("Custom title");
}
@Test
public void requestHeadersWithCustomDescriptorAttributes() throws IOException {
- this.snippets.expectRequestHeaders().withContents(//
- tableWithHeader("Name", "Description", "Foo")
- .row("X-Test", "one", "alpha")
- .row("Accept-Encoding", "two", "bravo")
- .row("Accept", "three", "charlie"));
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
given(resolver.resolveTemplateResource("request-headers"))
.willReturn(snippetResource("request-headers-with-extra-column"));
@@ -136,16 +130,15 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
.header("Accept-Encoding",
"gzip, deflate")
.header("Accept", "*/*").build());
+ assertThat(this.generatedSnippets.requestHeaders()).is(//
+ tableWithHeader("Name", "Description", "Foo")
+ .row("X-Test", "one", "alpha")
+ .row("Accept-Encoding", "two", "bravo")
+ .row("Accept", "three", "charlie"));
}
@Test
public void additionalDescriptors() throws IOException {
- this.snippets.expectRequestHeaders()
- .withContents(tableWithHeader("Name", "Description")
- .row("`X-Test`", "one").row("`Accept`", "two")
- .row("`Accept-Encoding`", "three")
- .row("`Accept-Language`", "four").row("`Cache-Control`", "five")
- .row("`Connection`", "six"));
HeaderDocumentation
.requestHeaders(headerWithName("X-Test").description("one"),
headerWithName("Accept").description("two"),
@@ -159,17 +152,22 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
.header("Accept-Language", "en-US,en;q=0.5")
.header("Cache-Control", "max-age=0")
.header("Connection", "keep-alive").build());
+ assertThat(this.generatedSnippets.requestHeaders())
+ .is(tableWithHeader("Name", "Description").row("`X-Test`", "one")
+ .row("`Accept`", "two").row("`Accept-Encoding`", "three")
+ .row("`Accept-Language`", "four").row("`Cache-Control`", "five")
+ .row("`Connection`", "six"));
}
@Test
public void tableCellContentIsEscapedWhenNecessary() throws IOException {
- this.snippets.expectRequestHeaders().withContents(
- tableWithHeader("Name", "Description").row(escapeIfNecessary("`Foo|Bar`"),
- escapeIfNecessary("one|two")));
new RequestHeadersSnippet(
Arrays.asList(headerWithName("Foo|Bar").description("one|two")))
.document(this.operationBuilder.request("http://localhost")
.header("Foo|Bar", "baz").build());
+ assertThat(this.generatedSnippets.requestHeaders()).is(
+ tableWithHeader("Name", "Description").row(escapeIfNecessary("`Foo|Bar`"),
+ escapeIfNecessary("one|two")));
}
private String escapeIfNecessary(String input) {
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/ResponseHeadersSnippetFailureTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/ResponseHeadersSnippetFailureTests.java
index 72d38fcc..6df4929b 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/ResponseHeadersSnippetFailureTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/ResponseHeadersSnippetFailureTests.java
@@ -24,7 +24,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.restdocs.snippet.SnippetException;
-import org.springframework.restdocs.test.ExpectedSnippets;
import org.springframework.restdocs.test.OperationBuilder;
import static org.hamcrest.CoreMatchers.endsWith;
@@ -43,9 +42,6 @@ public class ResponseHeadersSnippetFailureTests {
@Rule
public OperationBuilder operationBuilder = new OperationBuilder(asciidoctor());
- @Rule
- public ExpectedSnippets snippets = new ExpectedSnippets(asciidoctor());
-
@Rule
public ExpectedException thrown = ExpectedException.none();
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/ResponseHeadersSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/ResponseHeadersSnippetTests.java
index 0156812f..4fbd51f0 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/ResponseHeadersSnippetTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/headers/ResponseHeadersSnippetTests.java
@@ -28,7 +28,7 @@ import org.springframework.restdocs.templates.TemplateFormats;
import org.springframework.restdocs.templates.TemplateResourceResolver;
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
-import static org.hamcrest.CoreMatchers.containsString;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
@@ -49,10 +49,6 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests {
@Test
public void responseWithHeaders() throws IOException {
- this.snippets.expectResponseHeaders().withContents(
- tableWithHeader("Name", "Description").row("`X-Test`", "one")
- .row("`Content-Type`", "two").row("`Etag`", "three")
- .row("`Cache-Control`", "five").row("`Vary`", "six"));
new ResponseHeadersSnippet(
Arrays.asList(headerWithName("X-Test").description("one"),
headerWithName("Content-Type").description("two"),
@@ -64,32 +60,34 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests {
.header("Etag", "lskjadldj3ii32l2ij23")
.header("Cache-Control", "max-age=0")
.header("Vary", "User-Agent").build());
+ assertThat(this.generatedSnippets.responseHeaders())
+ .is(tableWithHeader("Name", "Description").row("`X-Test`", "one")
+ .row("`Content-Type`", "two").row("`Etag`", "three")
+ .row("`Cache-Control`", "five").row("`Vary`", "six"));
}
@Test
public void caseInsensitiveResponseHeaders() throws IOException {
- this.snippets.expectResponseHeaders().withContents(
- tableWithHeader("Name", "Description").row("`X-Test`", "one"));
new ResponseHeadersSnippet(
Arrays.asList(headerWithName("X-Test").description("one")))
.document(this.operationBuilder.response()
.header("X-test", "test").build());
+ assertThat(this.generatedSnippets.responseHeaders())
+ .is(tableWithHeader("Name", "Description").row("`X-Test`", "one"));
}
@Test
public void undocumentedResponseHeader() throws IOException {
- this.snippets.expectResponseHeaders().withContents(
- tableWithHeader("Name", "Description").row("`X-Test`", "one"));
new ResponseHeadersSnippet(
Arrays.asList(headerWithName("X-Test").description("one"))).document(
this.operationBuilder.response().header("X-Test", "test")
.header("Content-Type", "*/*").build());
+ assertThat(this.generatedSnippets.responseHeaders())
+ .is(tableWithHeader("Name", "Description").row("`X-Test`", "one"));
}
@Test
public void responseHeadersWithCustomAttributes() throws IOException {
- this.snippets.expectResponseHeaders()
- .withContents(containsString("Custom title"));
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
given(resolver.resolveTemplateResource("response-headers"))
.willReturn(snippetResource("response-headers-with-title"));
@@ -103,14 +101,11 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests {
resolver))
.response().header("X-Test", "test")
.build());
+ assertThat(this.generatedSnippets.responseHeaders()).contains("Custom title");
}
@Test
public void responseHeadersWithCustomDescriptorAttributes() throws IOException {
- this.snippets.expectResponseHeaders()
- .withContents(tableWithHeader("Name", "Description", "Foo")
- .row("X-Test", "one", "alpha").row("Content-Type", "two", "bravo")
- .row("Etag", "three", "charlie"));
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
given(resolver.resolveTemplateResource("response-headers"))
.willReturn(snippetResource("response-headers-with-extra-column"));
@@ -131,14 +126,14 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests {
"application/json")
.header("Etag", "lskjadldj3ii32l2ij23")
.build());
+ assertThat(this.generatedSnippets.responseHeaders())
+ .is(tableWithHeader("Name", "Description", "Foo")
+ .row("X-Test", "one", "alpha").row("Content-Type", "two", "bravo")
+ .row("Etag", "three", "charlie"));
}
@Test
public void additionalDescriptors() throws IOException {
- this.snippets.expectResponseHeaders().withContents(
- tableWithHeader("Name", "Description").row("`X-Test`", "one")
- .row("`Content-Type`", "two").row("`Etag`", "three")
- .row("`Cache-Control`", "five").row("`Vary`", "six"));
HeaderDocumentation
.responseHeaders(headerWithName("X-Test").description("one"),
headerWithName("Content-Type").description("two"),
@@ -150,17 +145,21 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests {
.header("Etag", "lskjadldj3ii32l2ij23")
.header("Cache-Control", "max-age=0").header("Vary", "User-Agent")
.build());
+ assertThat(this.generatedSnippets.responseHeaders())
+ .is(tableWithHeader("Name", "Description").row("`X-Test`", "one")
+ .row("`Content-Type`", "two").row("`Etag`", "three")
+ .row("`Cache-Control`", "five").row("`Vary`", "six"));
}
@Test
public void tableCellContentIsEscapedWhenNecessary() throws IOException {
- this.snippets.expectResponseHeaders().withContents(
- tableWithHeader("Name", "Description").row(escapeIfNecessary("`Foo|Bar`"),
- escapeIfNecessary("one|two")));
new ResponseHeadersSnippet(
Arrays.asList(headerWithName("Foo|Bar").description("one|two")))
.document(this.operationBuilder.response()
.header("Foo|Bar", "baz").build());
+ assertThat(this.generatedSnippets.responseHeaders()).is(
+ tableWithHeader("Name", "Description").row(escapeIfNecessary("`Foo|Bar`"),
+ escapeIfNecessary("one|two")));
}
private String escapeIfNecessary(String input) {
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java
index 0de3b5ae..6f289144 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java
@@ -29,7 +29,7 @@ import org.springframework.restdocs.templates.TemplateResourceResolver;
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
import org.springframework.web.bind.annotation.RequestMethod;
-import static org.hamcrest.CoreMatchers.containsString;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.springframework.restdocs.snippet.Attributes.attributes;
@@ -51,274 +51,262 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
@Test
public void getRequest() throws IOException {
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.GET, "/foo").header("Alpha", "a")
- .header(HttpHeaders.HOST, "localhost"));
-
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/foo").header("Alpha", "a").build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.GET, "/foo").header("Alpha", "a")
+ .header(HttpHeaders.HOST, "localhost"));
}
@Test
public void getRequestWithParameters() throws IOException {
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.GET, "/foo?b=bravo")
- .header("Alpha", "a").header(HttpHeaders.HOST, "localhost"));
-
new HttpRequestSnippet()
.document(this.operationBuilder.request("http://localhost/foo")
.header("Alpha", "a").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.GET, "/foo?b=bravo").header("Alpha", "a")
+ .header(HttpHeaders.HOST, "localhost"));
}
@Test
public void getRequestWithPort() throws IOException {
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.GET, "/foo").header("Alpha", "a")
- .header(HttpHeaders.HOST, "localhost:8080"));
-
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost:8080/foo").header("Alpha", "a").build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.GET, "/foo").header("Alpha", "a")
+ .header(HttpHeaders.HOST, "localhost:8080"));
}
@Test
public void getRequestWithCookies() throws IOException {
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.GET, "/foo")
- .header(HttpHeaders.HOST, "localhost")
- .header(HttpHeaders.COOKIE, "name1=value1")
- .header(HttpHeaders.COOKIE, "name2=value2"));
-
new HttpRequestSnippet()
.document(this.operationBuilder.request("http://localhost/foo")
.cookie("name1", "value1").cookie("name2", "value2").build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.GET, "/foo")
+ .header(HttpHeaders.HOST, "localhost")
+ .header(HttpHeaders.COOKIE, "name1=value1")
+ .header(HttpHeaders.COOKIE, "name2=value2"));
}
@Test
public void getRequestWithQueryString() throws IOException {
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.GET, "/foo?bar=baz")
- .header(HttpHeaders.HOST, "localhost"));
-
new HttpRequestSnippet().document(
this.operationBuilder.request("http://localhost/foo?bar=baz").build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.GET, "/foo?bar=baz")
+ .header(HttpHeaders.HOST, "localhost"));
}
@Test
public void getRequestWithQueryStringWithNoValue() throws IOException {
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.GET, "/foo?bar")
- .header(HttpHeaders.HOST, "localhost"));
-
new HttpRequestSnippet().document(
this.operationBuilder.request("http://localhost/foo?bar").build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.GET, "/foo?bar").header(HttpHeaders.HOST,
+ "localhost"));
}
@Test
public void getWithPartiallyOverlappingQueryStringAndParameters() throws IOException {
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.GET, "/foo?a=alpha&b=bravo")
- .header(HttpHeaders.HOST, "localhost"));
-
new HttpRequestSnippet()
.document(this.operationBuilder.request("http://localhost/foo?a=alpha")
.param("a", "alpha").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.GET, "/foo?a=alpha&b=bravo")
+ .header(HttpHeaders.HOST, "localhost"));
}
@Test
public void getWithTotallyOverlappingQueryStringAndParameters() throws IOException {
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.GET, "/foo?a=alpha&b=bravo")
- .header(HttpHeaders.HOST, "localhost"));
-
new HttpRequestSnippet().document(
this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo")
.param("a", "alpha").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.GET, "/foo?a=alpha&b=bravo")
+ .header(HttpHeaders.HOST, "localhost"));
}
@Test
public void postRequestWithContent() throws IOException {
String content = "Hello, world";
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.POST, "/foo")
- .header(HttpHeaders.HOST, "localhost").content(content)
- .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
-
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/foo").method("POST").content(content).build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.POST, "/foo")
+ .header(HttpHeaders.HOST, "localhost").content(content)
+ .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
}
@Test
public void postRequestWithContentAndParameters() throws IOException {
String content = "Hello, world";
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.POST, "/foo?a=alpha")
- .header(HttpHeaders.HOST, "localhost").content(content)
- .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
-
new HttpRequestSnippet()
.document(this.operationBuilder.request("http://localhost/foo")
.method("POST").param("a", "alpha").content(content).build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.POST, "/foo?a=alpha")
+ .header(HttpHeaders.HOST, "localhost").content(content)
+ .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
+
}
@Test
public void postRequestWithContentAndDisjointQueryStringAndParameters()
throws IOException {
String content = "Hello, world";
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.POST, "/foo?b=bravo&a=alpha")
- .header(HttpHeaders.HOST, "localhost").content(content)
- .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
-
new HttpRequestSnippet()
.document(this.operationBuilder.request("http://localhost/foo?b=bravo")
.method("POST").param("a", "alpha").content(content).build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.POST, "/foo?b=bravo&a=alpha")
+ .header(HttpHeaders.HOST, "localhost").content(content)
+ .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
}
@Test
public void postRequestWithContentAndPartiallyOverlappingQueryStringAndParameters()
throws IOException {
String content = "Hello, world";
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.POST, "/foo?b=bravo&a=alpha")
- .header(HttpHeaders.HOST, "localhost").content(content)
- .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
-
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/foo?b=bravo").method("POST")
.param("a", "alpha").param("b", "bravo").content(content).build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.POST, "/foo?b=bravo&a=alpha")
+ .header(HttpHeaders.HOST, "localhost").content(content)
+ .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
}
@Test
public void postRequestWithContentAndTotallyOverlappingQueryStringAndParameters()
throws IOException {
String content = "Hello, world";
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.POST, "/foo?b=bravo&a=alpha")
- .header(HttpHeaders.HOST, "localhost").content(content)
- .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
-
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/foo?b=bravo&a=alpha").method("POST")
.param("a", "alpha").param("b", "bravo").content(content).build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.POST, "/foo?b=bravo&a=alpha")
+ .header(HttpHeaders.HOST, "localhost").content(content)
+ .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
}
@Test
public void postRequestWithOverlappingParametersAndFormUrlEncodedBody()
throws IOException {
String content = "a=alpha&b=bravo";
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.POST, "/foo")
- .header(HttpHeaders.CONTENT_TYPE,
- MediaType.APPLICATION_FORM_URLENCODED_VALUE)
- .header(HttpHeaders.HOST, "localhost").content(content)
- .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/foo").method("POST").content("a=alpha&b=bravo")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_FORM_URLENCODED_VALUE)
.param("a", "alpha").param("b", "bravo").build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.POST, "/foo")
+ .header(HttpHeaders.CONTENT_TYPE,
+ MediaType.APPLICATION_FORM_URLENCODED_VALUE)
+ .header(HttpHeaders.HOST, "localhost").content(content)
+ .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
}
@Test
public void postRequestWithCharset() throws IOException {
String japaneseContent = "\u30b3\u30f3\u30c6\u30f3\u30c4";
byte[] contentBytes = japaneseContent.getBytes("UTF-8");
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.POST, "/foo")
- .header("Content-Type", "text/plain;charset=UTF-8")
- .header(HttpHeaders.HOST, "localhost")
- .header(HttpHeaders.CONTENT_LENGTH, contentBytes.length)
- .content(japaneseContent));
-
new HttpRequestSnippet()
.document(this.operationBuilder.request("http://localhost/foo")
.method("POST").header("Content-Type", "text/plain;charset=UTF-8")
.content(contentBytes).build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.POST, "/foo")
+ .header("Content-Type", "text/plain;charset=UTF-8")
+ .header(HttpHeaders.HOST, "localhost")
+ .header(HttpHeaders.CONTENT_LENGTH, contentBytes.length)
+ .content(japaneseContent));
}
@Test
public void postRequestWithParameter() throws IOException {
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.POST, "/foo")
- .header(HttpHeaders.HOST, "localhost")
- .header("Content-Type", "application/x-www-form-urlencoded")
- .content("b%26r=baz&a=alpha"));
-
new HttpRequestSnippet()
.document(this.operationBuilder.request("http://localhost/foo")
.method("POST").param("b&r", "baz").param("a", "alpha").build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.POST, "/foo")
+ .header(HttpHeaders.HOST, "localhost")
+ .header("Content-Type", "application/x-www-form-urlencoded")
+ .content("b%26r=baz&a=alpha"));
}
@Test
public void postRequestWithParameterWithNoValue() throws IOException {
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.POST, "/foo")
+ new HttpRequestSnippet().document(this.operationBuilder
+ .request("http://localhost/foo").method("POST").param("bar").build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.POST, "/foo")
.header(HttpHeaders.HOST, "localhost")
.header("Content-Type", "application/x-www-form-urlencoded")
.content("bar="));
-
- new HttpRequestSnippet().document(this.operationBuilder
- .request("http://localhost/foo").method("POST").param("bar").build());
}
@Test
public void putRequestWithContent() throws IOException {
String content = "Hello, world";
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.PUT, "/foo")
- .header(HttpHeaders.HOST, "localhost").content(content)
- .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
-
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/foo").method("PUT").content(content).build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.PUT, "/foo")
+ .header(HttpHeaders.HOST, "localhost").content(content)
+ .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
}
@Test
public void putRequestWithParameter() throws IOException {
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.PUT, "/foo")
- .header(HttpHeaders.HOST, "localhost")
- .header("Content-Type", "application/x-www-form-urlencoded")
- .content("b%26r=baz&a=alpha"));
-
new HttpRequestSnippet()
.document(this.operationBuilder.request("http://localhost/foo")
.method("PUT").param("b&r", "baz").param("a", "alpha").build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.PUT, "/foo")
+ .header(HttpHeaders.HOST, "localhost")
+ .header("Content-Type", "application/x-www-form-urlencoded")
+ .content("b%26r=baz&a=alpha"));
}
@Test
public void multipartPost() throws IOException {
- String expectedContent = createPart(String.format(
- "Content-Disposition: " + "form-data; " + "name=image%n%n<< data >>"));
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.POST, "/upload")
- .header("Content-Type",
- "multipart/form-data; boundary=" + BOUNDARY)
- .header(HttpHeaders.HOST, "localhost").content(expectedContent));
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", "<< data >>".getBytes()).build());
+ String expectedContent = createPart(String.format(
+ "Content-Disposition: " + "form-data; " + "name=image%n%n<< data >>"));
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.POST, "/upload")
+ .header("Content-Type",
+ "multipart/form-data; boundary=" + BOUNDARY)
+ .header(HttpHeaders.HOST, "localhost").content(expectedContent));
}
@Test
public void multipartPostWithFilename() throws IOException {
- String expectedContent = createPart(String.format("Content-Disposition: "
- + "form-data; " + "name=image; filename=image.png%n%n<< data >>"));
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.POST, "/upload")
- .header("Content-Type",
- "multipart/form-data; boundary=" + BOUNDARY)
- .header(HttpHeaders.HOST, "localhost").content(expectedContent));
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", "<< data >>".getBytes()).submittedFileName("image.png")
.build());
+ String expectedContent = createPart(String.format("Content-Disposition: "
+ + "form-data; " + "name=image; filename=image.png%n%n<< data >>"));
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.POST, "/upload")
+ .header("Content-Type",
+ "multipart/form-data; boundary=" + BOUNDARY)
+ .header(HttpHeaders.HOST, "localhost").content(expectedContent));
}
@Test
public void multipartPostWithParameters() throws IOException {
+ new HttpRequestSnippet().document(this.operationBuilder
+ .request("http://localhost/upload").method("POST")
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
+ .param("a", "apple", "avocado").param("b", "banana")
+ .part("image", "<< data >>".getBytes()).build());
String param1Part = createPart(
String.format("Content-Disposition: form-data; " + "name=a%n%napple"),
false);
@@ -331,67 +319,60 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
String filePart = createPart(String
.format("Content-Disposition: form-data; " + "name=image%n%n<< data >>"));
String expectedContent = param1Part + param2Part + param3Part + filePart;
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.POST, "/upload")
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.POST, "/upload")
.header("Content-Type",
"multipart/form-data; boundary=" + BOUNDARY)
.header(HttpHeaders.HOST, "localhost").content(expectedContent));
- new HttpRequestSnippet().document(this.operationBuilder
- .request("http://localhost/upload").method("POST")
- .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
- .param("a", "apple", "avocado").param("b", "banana")
- .part("image", "<< data >>".getBytes()).build());
}
@Test
public void multipartPostWithParameterWithNoValue() throws IOException {
+ new HttpRequestSnippet().document(this.operationBuilder
+ .request("http://localhost/upload").method("POST")
+ .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
+ .param("a").part("image", "<< data >>".getBytes()).build());
String paramPart = createPart(
String.format("Content-Disposition: form-data; " + "name=a%n"), false);
String filePart = createPart(String
.format("Content-Disposition: form-data; " + "name=image%n%n<< data >>"));
String expectedContent = paramPart + filePart;
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.POST, "/upload")
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.POST, "/upload")
.header("Content-Type",
"multipart/form-data; boundary=" + BOUNDARY)
.header(HttpHeaders.HOST, "localhost").content(expectedContent));
- new HttpRequestSnippet().document(this.operationBuilder
- .request("http://localhost/upload").method("POST")
- .header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
- .param("a").part("image", "<< data >>".getBytes()).build());
}
@Test
public void multipartPostWithContentType() throws IOException {
- String expectedContent = createPart(
- String.format("Content-Disposition: form-data; name=image%nContent-Type: "
- + "image/png%n%n<< data >>"));
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.POST, "/upload")
- .header("Content-Type",
- "multipart/form-data; boundary=" + BOUNDARY)
- .header(HttpHeaders.HOST, "localhost").content(expectedContent));
new HttpRequestSnippet().document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", "<< data >>".getBytes())
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE).build());
+ String expectedContent = createPart(
+ String.format("Content-Disposition: form-data; name=image%nContent-Type: "
+ + "image/png%n%n<< data >>"));
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.POST, "/upload")
+ .header("Content-Type",
+ "multipart/form-data; boundary=" + BOUNDARY)
+ .header(HttpHeaders.HOST, "localhost").content(expectedContent));
}
@Test
public void getRequestWithCustomHost() throws IOException {
- this.snippets.expectHttpRequest()
- .withContents(httpRequest(RequestMethod.GET, "/foo")
- .header(HttpHeaders.HOST, "api.example.com"));
new HttpRequestSnippet()
.document(this.operationBuilder.request("http://localhost/foo")
.header(HttpHeaders.HOST, "api.example.com").build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .is(httpRequest(RequestMethod.GET, "/foo").header(HttpHeaders.HOST,
+ "api.example.com"));
}
@Test
public void requestWithCustomSnippetAttributes() throws IOException {
- this.snippets.expectHttpRequest()
- .withContents(containsString("Title for the request"));
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
given(resolver.resolveTemplateResource("http-request"))
.willReturn(snippetResource("http-request-with-title"));
@@ -400,6 +381,8 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver))
.request("http://localhost/foo").build());
+ assertThat(this.generatedSnippets.httpRequest())
+ .contains("Title for the request");
}
private String createPart(String content) {
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpResponseSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpResponseSnippetTests.java
index ef2a549b..4f924809 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpResponseSnippetTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpResponseSnippetTests.java
@@ -29,7 +29,7 @@ import org.springframework.restdocs.templates.TemplateFormat;
import org.springframework.restdocs.templates.TemplateResourceResolver;
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
-import static org.hamcrest.CoreMatchers.containsString;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.springframework.restdocs.snippet.Attributes.attributes;
@@ -49,61 +49,60 @@ public class HttpResponseSnippetTests extends AbstractSnippetTests {
@Test
public void basicResponse() throws IOException {
- this.snippets.expectHttpResponse().withContents(httpResponse(HttpStatus.OK));
new HttpResponseSnippet().document(this.operationBuilder.build());
+ assertThat(this.generatedSnippets.httpResponse()).is(httpResponse(HttpStatus.OK));
}
@Test
public void nonOkResponse() throws IOException {
- this.snippets.expectHttpResponse()
- .withContents(httpResponse(HttpStatus.BAD_REQUEST));
new HttpResponseSnippet().document(this.operationBuilder.response()
.status(HttpStatus.BAD_REQUEST.value()).build());
+ assertThat(this.generatedSnippets.httpResponse())
+ .is(httpResponse(HttpStatus.BAD_REQUEST));
}
@Test
public void responseWithHeaders() throws IOException {
- this.snippets.expectHttpResponse().withContents(httpResponse(HttpStatus.OK)
- .header("Content-Type", "application/json").header("a", "alpha"));
new HttpResponseSnippet().document(this.operationBuilder.response()
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header("a", "alpha").build());
+ assertThat(this.generatedSnippets.httpResponse()).is(httpResponse(HttpStatus.OK)
+ .header("Content-Type", "application/json").header("a", "alpha"));
}
@Test
public void responseWithContent() throws IOException {
String content = "content";
- this.snippets.expectHttpResponse()
- .withContents(httpResponse(HttpStatus.OK).content(content)
- .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
new HttpResponseSnippet()
.document(this.operationBuilder.response().content(content).build());
+ assertThat(this.generatedSnippets.httpResponse())
+ .is(httpResponse(HttpStatus.OK).content(content)
+ .header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
}
@Test
public void responseWithCharset() throws IOException {
String japaneseContent = "\u30b3\u30f3\u30c6\u30f3\u30c4";
byte[] contentBytes = japaneseContent.getBytes("UTF-8");
- this.snippets.expectHttpResponse()
- .withContents(httpResponse(HttpStatus.OK)
- .header("Content-Type", "text/plain;charset=UTF-8")
- .content(japaneseContent)
- .header(HttpHeaders.CONTENT_LENGTH, contentBytes.length));
new HttpResponseSnippet().document(this.operationBuilder.response()
.header("Content-Type", "text/plain;charset=UTF-8").content(contentBytes)
.build());
+ assertThat(this.generatedSnippets.httpResponse()).is(httpResponse(HttpStatus.OK)
+ .header("Content-Type", "text/plain;charset=UTF-8")
+ .content(japaneseContent)
+ .header(HttpHeaders.CONTENT_LENGTH, contentBytes.length));
}
@Test
public void responseWithCustomSnippetAttributes() throws IOException {
- this.snippets.expectHttpResponse()
- .withContents(containsString("Title for the response"));
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
given(resolver.resolveTemplateResource("http-response"))
.willReturn(snippetResource("http-response-with-title"));
new HttpResponseSnippet(attributes(key("title").value("Title for the response")))
.document(this.operationBuilder.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver)).build());
+ assertThat(this.generatedSnippets.httpResponse())
+ .contains("Title for the response");
}
}
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinkExtractorsPayloadTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinkExtractorsPayloadTests.java
index c6fe7802..7898c71f 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinkExtractorsPayloadTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinkExtractorsPayloadTests.java
@@ -36,7 +36,7 @@ import org.springframework.util.FileCopyUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
-import static org.junit.Assert.assertEquals;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Parameterized tests for {@link HalLinkExtractor} and {@link AtomLinkExtractor} with
@@ -109,7 +109,7 @@ public class LinkExtractorsPayloadTests {
for (Link expectedLink : expectedLinks) {
expectedLinksByRel.add(expectedLink.getRel(), expectedLink);
}
- assertEquals(expectedLinksByRel, actualLinks);
+ assertThat(actualLinks).isEqualTo(expectedLinksByRel);
}
private OperationResponse createResponse(String contentName) throws IOException {
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetFailureTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetFailureTests.java
index f8d9c6a0..c6b62020 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetFailureTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetFailureTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2016 the original author or authors.
+ * Copyright 2014-2018 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.
@@ -25,7 +25,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.springframework.restdocs.snippet.SnippetException;
-import org.springframework.restdocs.test.ExpectedSnippets;
import org.springframework.restdocs.test.OperationBuilder;
import static org.hamcrest.CoreMatchers.equalTo;
@@ -42,9 +41,6 @@ public class LinksSnippetFailureTests {
@Rule
public OperationBuilder operationBuilder = new OperationBuilder(asciidoctor());
- @Rule
- public ExpectedSnippets snippets = new ExpectedSnippets(asciidoctor());
-
@Rule
public ExpectedException thrown = ExpectedException.none();
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java
index 71bf83c0..5fdff546 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java
@@ -28,7 +28,7 @@ import org.springframework.restdocs.templates.TemplateFormats;
import org.springframework.restdocs.templates.TemplateResourceResolver;
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
-import static org.hamcrest.CoreMatchers.containsString;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.springframework.restdocs.snippet.Attributes.attributes;
@@ -47,68 +47,68 @@ public class LinksSnippetTests extends AbstractSnippetTests {
@Test
public void ignoredLink() throws IOException {
- this.snippets.expectLinks().withContents(
- tableWithHeader("Relation", "Description").row("`b`", "Link b"));
new LinksSnippet(
new StubLinkExtractor().withLinks(new Link("a", "alpha"),
new Link("b", "bravo")),
Arrays.asList(new LinkDescriptor("a").ignored(),
new LinkDescriptor("b").description("Link b")))
.document(this.operationBuilder.build());
+ assertThat(this.generatedSnippets.links())
+ .is(tableWithHeader("Relation", "Description").row("`b`", "Link b"));
}
@Test
public void allUndocumentedLinksCanBeIgnored() throws IOException {
- this.snippets.expectLinks().withContents(
- tableWithHeader("Relation", "Description").row("`b`", "Link b"));
new LinksSnippet(
new StubLinkExtractor().withLinks(new Link("a", "alpha"),
new Link("b", "bravo")),
Arrays.asList(new LinkDescriptor("b").description("Link b")), true)
.document(this.operationBuilder.build());
+ assertThat(this.generatedSnippets.links())
+ .is(tableWithHeader("Relation", "Description").row("`b`", "Link b"));
}
@Test
public void presentOptionalLink() throws IOException {
- this.snippets.expectLinks().withContents(
- tableWithHeader("Relation", "Description").row("`foo`", "bar"));
new LinksSnippet(new StubLinkExtractor().withLinks(new Link("foo", "blah")),
Arrays.asList(new LinkDescriptor("foo").description("bar").optional()))
.document(this.operationBuilder.build());
+ assertThat(this.generatedSnippets.links())
+ .is(tableWithHeader("Relation", "Description").row("`foo`", "bar"));
}
@Test
public void missingOptionalLink() throws IOException {
- this.snippets.expectLinks().withContents(
- tableWithHeader("Relation", "Description").row("`foo`", "bar"));
new LinksSnippet(new StubLinkExtractor(),
Arrays.asList(new LinkDescriptor("foo").description("bar").optional()))
.document(this.operationBuilder.build());
+ assertThat(this.generatedSnippets.links())
+ .is(tableWithHeader("Relation", "Description").row("`foo`", "bar"));
}
@Test
public void documentedLinks() throws IOException {
- this.snippets.expectLinks()
- .withContents(tableWithHeader("Relation", "Description").row("`a`", "one")
- .row("`b`", "two"));
new LinksSnippet(
new StubLinkExtractor().withLinks(new Link("a", "alpha"),
new Link("b", "bravo")),
Arrays.asList(new LinkDescriptor("a").description("one"),
new LinkDescriptor("b").description("two")))
.document(this.operationBuilder.build());
+ assertThat(this.generatedSnippets.links())
+ .is(tableWithHeader("Relation", "Description").row("`a`", "one")
+ .row("`b`", "two"));
}
@Test
public void linkDescriptionFromTitleInPayload() throws IOException {
- this.snippets.expectLinks()
- .withContents(tableWithHeader("Relation", "Description").row("`a`", "one")
- .row("`b`", "Link b"));
new LinksSnippet(
new StubLinkExtractor().withLinks(new Link("a", "alpha", "Link a"),
new Link("b", "bravo", "Link b")),
Arrays.asList(new LinkDescriptor("a").description("one"),
new LinkDescriptor("b"))).document(this.operationBuilder.build());
+ assertThat(this.generatedSnippets.links())
+ .is(tableWithHeader("Relation", "Description").row("`a`", "one")
+ .row("`b`", "Link b"));
}
@Test
@@ -116,8 +116,6 @@ public class LinksSnippetTests extends AbstractSnippetTests {
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
given(resolver.resolveTemplateResource("links"))
.willReturn(snippetResource("links-with-title"));
- this.snippets.expectLinks().withContents(containsString("Title for the links"));
-
new LinksSnippet(
new StubLinkExtractor().withLinks(new Link("a", "alpha"),
new Link("b", "bravo")),
@@ -129,6 +127,7 @@ public class LinksSnippetTests extends AbstractSnippetTests {
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver))
.build());
+ assertThat(this.generatedSnippets.links()).contains("Title for the links");
}
@Test
@@ -136,10 +135,6 @@ public class LinksSnippetTests extends AbstractSnippetTests {
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
given(resolver.resolveTemplateResource("links"))
.willReturn(snippetResource("links-with-extra-column"));
- this.snippets.expectLinks()
- .withContents(tableWithHeader("Relation", "Description", "Foo")
- .row("a", "one", "alpha").row("b", "two", "bravo"));
-
new LinksSnippet(
new StubLinkExtractor().withLinks(new Link("a", "alpha"),
new Link("b", "bravo")),
@@ -152,29 +147,32 @@ public class LinksSnippetTests extends AbstractSnippetTests {
TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver))
.build());
+ assertThat(this.generatedSnippets.links())
+ .is(tableWithHeader("Relation", "Description", "Foo")
+ .row("a", "one", "alpha").row("b", "two", "bravo"));
}
@Test
public void additionalDescriptors() throws IOException {
- this.snippets.expectLinks()
- .withContents(tableWithHeader("Relation", "Description").row("`a`", "one")
- .row("`b`", "two"));
HypermediaDocumentation
.links(new StubLinkExtractor().withLinks(new Link("a", "alpha"),
new Link("b", "bravo")),
new LinkDescriptor("a").description("one"))
.and(new LinkDescriptor("b").description("two"))
.document(this.operationBuilder.build());
+ assertThat(this.generatedSnippets.links())
+ .is(tableWithHeader("Relation", "Description").row("`a`", "one")
+ .row("`b`", "two"));
}
@Test
public void tableCellContentIsEscapedWhenNecessary() throws IOException {
- this.snippets.expectLinks()
- .withContents(tableWithHeader("Relation", "Description").row(
- escapeIfNecessary("`Foo|Bar`"), escapeIfNecessary("one|two")));
new LinksSnippet(new StubLinkExtractor().withLinks(new Link("Foo|Bar", "foo")),
Arrays.asList(new LinkDescriptor("Foo|Bar").description("one|two")))
.document(this.operationBuilder.build());
+ assertThat(this.generatedSnippets.links())
+ .is(tableWithHeader("Relation", "Description").row(
+ escapeIfNecessary("`Foo|Bar`"), escapeIfNecessary("one|two")));
}
private String escapeIfNecessary(String input) {
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/ParametersTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/ParametersTests.java
index 3c922886..f4eedcdc 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/ParametersTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/ParametersTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2016 the original author or authors.
+ * Copyright 2014-2018 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.
@@ -18,9 +18,7 @@ package org.springframework.restdocs.operation;
import org.junit.Test;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link Parameters}.
@@ -33,45 +31,45 @@ public class ParametersTests {
@Test
public void queryStringForNoParameters() {
- assertThat(this.parameters.toQueryString(), is(equalTo("")));
+ assertThat(this.parameters.toQueryString()).isEqualTo("");
}
@Test
public void queryStringForSingleParameter() {
this.parameters.add("a", "b");
- assertThat(this.parameters.toQueryString(), is(equalTo("a=b")));
+ assertThat(this.parameters.toQueryString()).isEqualTo("a=b");
}
@Test
public void queryStringForSingleParameterWithMultipleValues() {
this.parameters.add("a", "b");
this.parameters.add("a", "c");
- assertThat(this.parameters.toQueryString(), is(equalTo("a=b&a=c")));
+ assertThat(this.parameters.toQueryString()).isEqualTo("a=b&a=c");
}
@Test
public void queryStringForMutipleParameters() {
this.parameters.add("a", "alpha");
this.parameters.add("b", "bravo");
- assertThat(this.parameters.toQueryString(), is(equalTo("a=alpha&b=bravo")));
+ assertThat(this.parameters.toQueryString()).isEqualTo("a=alpha&b=bravo");
}
@Test
public void queryStringForParameterWithEmptyValue() {
this.parameters.add("a", "");
- assertThat(this.parameters.toQueryString(), is(equalTo("a=")));
+ assertThat(this.parameters.toQueryString()).isEqualTo("a=");
}
@Test
public void queryStringForParameterWithNullValue() {
this.parameters.add("a", null);
- assertThat(this.parameters.toQueryString(), is(equalTo("a=")));
+ assertThat(this.parameters.toQueryString()).isEqualTo("a=");
}
@Test
public void queryStringForParameterThatRequiresEncoding() {
this.parameters.add("a", "alpha&bravo");
- assertThat(this.parameters.toQueryString(), is(equalTo("a=alpha%26bravo")));
+ assertThat(this.parameters.toQueryString()).isEqualTo("a=alpha%26bravo");
}
}
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/QueryStringParserTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/QueryStringParserTests.java
index cf58f72e..7fcf8233 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/QueryStringParserTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/QueryStringParserTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2017 the original author or authors.
+ * Copyright 2014-2018 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.
@@ -23,10 +23,8 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.hasEntry;
-import static org.junit.Assert.assertThat;
/**
* Tests for {@link QueryStringParser}.
@@ -44,41 +42,41 @@ public class QueryStringParserTests {
public void noParameters() {
Parameters parameters = this.queryStringParser
.parse(URI.create("http://localhost"));
- assertThat(parameters.size(), is(equalTo(0)));
+ assertThat(parameters.size()).isEqualTo(0);
}
@Test
public void singleParameter() {
Parameters parameters = this.queryStringParser
.parse(URI.create("http://localhost?a=alpha"));
- assertThat(parameters.size(), is(equalTo(1)));
- assertThat(parameters, hasEntry("a", Arrays.asList("alpha")));
+ assertThat(parameters.size()).isEqualTo(1);
+ assertThat(parameters).containsEntry("a", Arrays.asList("alpha"));
}
@Test
public void multipleParameters() {
Parameters parameters = this.queryStringParser
.parse(URI.create("http://localhost?a=alpha&b=bravo&c=charlie"));
- assertThat(parameters.size(), is(equalTo(3)));
- assertThat(parameters, hasEntry("a", Arrays.asList("alpha")));
- assertThat(parameters, hasEntry("b", Arrays.asList("bravo")));
- assertThat(parameters, hasEntry("c", Arrays.asList("charlie")));
+ assertThat(parameters.size()).isEqualTo(3);
+ assertThat(parameters).containsEntry("a", Arrays.asList("alpha"));
+ assertThat(parameters).containsEntry("b", Arrays.asList("bravo"));
+ assertThat(parameters).containsEntry("c", Arrays.asList("charlie"));
}
@Test
public void multipleParametersWithSameKey() {
Parameters parameters = this.queryStringParser
.parse(URI.create("http://localhost?a=apple&a=avocado"));
- assertThat(parameters.size(), is(equalTo(1)));
- assertThat(parameters, hasEntry("a", Arrays.asList("apple", "avocado")));
+ assertThat(parameters.size()).isEqualTo(1);
+ assertThat(parameters).containsEntry("a", Arrays.asList("apple", "avocado"));
}
@Test
public void encoded() {
Parameters parameters = this.queryStringParser
.parse(URI.create("http://localhost?a=al%26%3Dpha"));
- assertThat(parameters.size(), is(equalTo(1)));
- assertThat(parameters, hasEntry("a", Arrays.asList("al&=pha")));
+ assertThat(parameters.size()).isEqualTo(1);
+ assertThat(parameters).containsEntry("a", Arrays.asList("al&=pha"));
}
@Test
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/ContentModifyingOperationPreprocessorTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/ContentModifyingOperationPreprocessorTests.java
index 4e45a742..7d5ffe16 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/ContentModifyingOperationPreprocessorTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/ContentModifyingOperationPreprocessorTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2015 the original author or authors.
+ * Copyright 2014-2018 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.
@@ -32,9 +32,7 @@ import org.springframework.restdocs.operation.OperationResponse;
import org.springframework.restdocs.operation.OperationResponseFactory;
import org.springframework.restdocs.operation.Parameters;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ContentModifyingOperationPreprocessor}.
@@ -65,7 +63,7 @@ public class ContentModifyingOperationPreprocessorTests {
new HttpHeaders(), new Parameters(),
Collections.emptyList());
OperationRequest preprocessed = this.preprocessor.preprocess(request);
- assertThat(preprocessed.getContent(), is(equalTo("modified".getBytes())));
+ assertThat(preprocessed.getContent()).isEqualTo("modified".getBytes());
}
@Test
@@ -73,7 +71,7 @@ public class ContentModifyingOperationPreprocessorTests {
OperationResponse response = this.responseFactory.create(HttpStatus.OK,
new HttpHeaders(), "content".getBytes());
OperationResponse preprocessed = this.preprocessor.preprocess(response);
- assertThat(preprocessed.getContent(), is(equalTo("modified".getBytes())));
+ assertThat(preprocessed.getContent()).isEqualTo("modified".getBytes());
}
@Test
@@ -85,7 +83,7 @@ public class ContentModifyingOperationPreprocessorTests {
httpHeaders, new Parameters(),
Collections.emptyList());
OperationRequest preprocessed = this.preprocessor.preprocess(request);
- assertThat(preprocessed.getHeaders().getContentLength(), is(equalTo(8L)));
+ assertThat(preprocessed.getHeaders().getContentLength()).isEqualTo(8L);
}
}
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/DelegatingOperationRequestPreprocessorTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/DelegatingOperationRequestPreprocessorTests.java
index 62e69a36..6f2d40ac 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/DelegatingOperationRequestPreprocessorTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/DelegatingOperationRequestPreprocessorTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2015 the original author or authors.
+ * Copyright 2014-2018 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.
@@ -22,8 +22,7 @@ import org.junit.Test;
import org.springframework.restdocs.operation.OperationRequest;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -54,7 +53,7 @@ public class DelegatingOperationRequestPreprocessorTests {
Arrays.asList(preprocessor1, preprocessor2, preprocessor3))
.preprocess(originalRequest);
- assertThat(result, is(preprocessedRequest3));
+ assertThat(result).isSameAs(preprocessedRequest3);
}
}
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/DelegatingOperationResponsePreprocessorTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/DelegatingOperationResponsePreprocessorTests.java
index dc1a9719..7678200d 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/DelegatingOperationResponsePreprocessorTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/DelegatingOperationResponsePreprocessorTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2017 the original author or authors.
+ * Copyright 2014-2018 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.
@@ -22,8 +22,7 @@ import org.junit.Test;
import org.springframework.restdocs.operation.OperationResponse;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -55,7 +54,7 @@ public class DelegatingOperationResponsePreprocessorTests {
Arrays.asList(preprocessor1, preprocessor2, preprocessor3))
.preprocess(originalResponse);
- assertThat(result, is(preprocessedResponse3));
+ assertThat(result).isSameAs(preprocessedResponse3);
}
}
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/HeaderRemovingOperationPreprocessorTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/HeaderRemovingOperationPreprocessorTests.java
index ca13f47b..5610e0f3 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/HeaderRemovingOperationPreprocessorTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/HeaderRemovingOperationPreprocessorTests.java
@@ -32,10 +32,7 @@ import org.springframework.restdocs.operation.OperationResponse;
import org.springframework.restdocs.operation.OperationResponseFactory;
import org.springframework.restdocs.operation.Parameters;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.hasEntry;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link HeaderRemovingOperationPreprocessorTests}.
@@ -59,18 +56,18 @@ public class HeaderRemovingOperationPreprocessorTests {
getHttpHeaders(), new Parameters(),
Collections.emptyList());
OperationRequest preprocessed = this.preprocessor.preprocess(request);
- assertThat(preprocessed.getHeaders().size(), is(equalTo(2)));
- assertThat(preprocessed.getHeaders(), hasEntry("a", Arrays.asList("alpha")));
- assertThat(preprocessed.getHeaders(),
- hasEntry("Host", Arrays.asList("localhost")));
+ assertThat(preprocessed.getHeaders().size()).isEqualTo(2);
+ assertThat(preprocessed.getHeaders()).containsEntry("a", Arrays.asList("alpha"));
+ assertThat(preprocessed.getHeaders()).containsEntry("Host",
+ Arrays.asList("localhost"));
}
@Test
public void modifyResponseHeaders() {
OperationResponse response = createResponse();
OperationResponse preprocessed = this.preprocessor.preprocess(response);
- assertThat(preprocessed.getHeaders().size(), is(equalTo(1)));
- assertThat(preprocessed.getHeaders(), hasEntry("a", Arrays.asList("alpha")));
+ assertThat(preprocessed.getHeaders().size()).isEqualTo(1);
+ assertThat(preprocessed.getHeaders()).containsEntry("a", Arrays.asList("alpha"));
}
@Test
@@ -79,10 +76,10 @@ public class HeaderRemovingOperationPreprocessorTests {
HeaderRemovingOperationPreprocessor processor = new HeaderRemovingOperationPreprocessor(
new PatternMatchHeaderFilter("co.*le(.)gth]"));
OperationResponse preprocessed = processor.preprocess(response);
- assertThat(preprocessed.getHeaders().size(), is(equalTo(2)));
- assertThat(preprocessed.getHeaders(), hasEntry("a", Arrays.asList("alpha")));
- assertThat(preprocessed.getHeaders(),
- hasEntry("b", Arrays.asList("bravo", "banana")));
+ assertThat(preprocessed.getHeaders().size()).isEqualTo(2);
+ assertThat(preprocessed.getHeaders()).containsEntry("a", Arrays.asList("alpha"));
+ assertThat(preprocessed.getHeaders()).containsEntry("b",
+ Arrays.asList("bravo", "banana"));
}
@Test
@@ -90,7 +87,7 @@ public class HeaderRemovingOperationPreprocessorTests {
HeaderRemovingOperationPreprocessor processor = new HeaderRemovingOperationPreprocessor(
new PatternMatchHeaderFilter(".*"));
OperationResponse preprocessed = processor.preprocess(createResponse());
- assertThat(preprocessed.getHeaders().size(), is(equalTo(0)));
+ assertThat(preprocessed.getHeaders().size()).isEqualTo(0);
}
private OperationResponse createResponse(String... extraHeaders) {
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/LinkMaskingContentModifierTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/LinkMaskingContentModifierTests.java
index 09c6affa..2d9b115e 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/LinkMaskingContentModifierTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/LinkMaskingContentModifierTests.java
@@ -30,9 +30,7 @@ import org.junit.Test;
import org.springframework.restdocs.hypermedia.Link;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link LinkMaskingContentModifier}.
@@ -53,39 +51,36 @@ public class LinkMaskingContentModifierTests {
@Test
public void halLinksAreMasked() throws Exception {
assertThat(
- this.contentModifier.modifyContent(halPayloadWithLinks(this.links), null),
- is(equalTo(halPayloadWithLinks(this.maskedLinks))));
+ this.contentModifier.modifyContent(halPayloadWithLinks(this.links), null))
+ .isEqualTo(halPayloadWithLinks(this.maskedLinks));
}
@Test
public void formattedHalLinksAreMasked() throws Exception {
- assertThat(
- this.contentModifier
- .modifyContent(formattedHalPayloadWithLinks(this.links), null),
- is(equalTo(formattedHalPayloadWithLinks(this.maskedLinks))));
+ assertThat(this.contentModifier
+ .modifyContent(formattedHalPayloadWithLinks(this.links), null))
+ .isEqualTo(formattedHalPayloadWithLinks(this.maskedLinks));
}
@Test
public void atomLinksAreMasked() throws Exception {
assertThat(this.contentModifier.modifyContent(atomPayloadWithLinks(this.links),
- null), is(equalTo(atomPayloadWithLinks(this.maskedLinks))));
+ null)).isEqualTo(atomPayloadWithLinks(this.maskedLinks));
}
@Test
public void formattedAtomLinksAreMasked() throws Exception {
- assertThat(
- this.contentModifier
- .modifyContent(formattedAtomPayloadWithLinks(this.links), null),
- is(equalTo(formattedAtomPayloadWithLinks(this.maskedLinks))));
+ assertThat(this.contentModifier
+ .modifyContent(formattedAtomPayloadWithLinks(this.links), null))
+ .isEqualTo(formattedAtomPayloadWithLinks(this.maskedLinks));
}
@Test
public void maskCanBeCustomized() throws Exception {
- assertThat(
- new LinkMaskingContentModifier("custom")
- .modifyContent(formattedAtomPayloadWithLinks(this.links), null),
- is(equalTo(formattedAtomPayloadWithLinks(new Link("a", "custom"),
- new Link("b", "custom")))));
+ assertThat(new LinkMaskingContentModifier("custom")
+ .modifyContent(formattedAtomPayloadWithLinks(this.links), null))
+ .isEqualTo(formattedAtomPayloadWithLinks(new Link("a", "custom"),
+ new Link("b", "custom")));
}
private byte[] atomPayloadWithLinks(Link... links) throws JsonProcessingException {
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/ParametersModifyingOperationPreprocessorTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/ParametersModifyingOperationPreprocessorTests.java
index ebcef8ce..9c862a35 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/ParametersModifyingOperationPreprocessorTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/ParametersModifyingOperationPreprocessorTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2016 the original author or authors.
+ * Copyright 2014-2018 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.
@@ -17,6 +17,7 @@
package org.springframework.restdocs.operation.preprocess;
import java.net.URI;
+import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
@@ -28,11 +29,7 @@ import org.springframework.restdocs.operation.OperationRequestFactory;
import org.springframework.restdocs.operation.OperationRequestPart;
import org.springframework.restdocs.operation.Parameters;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.Matchers.contains;
-import static org.hamcrest.Matchers.hasEntry;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ParametersModifyingOperationPreprocessor}.
@@ -47,63 +44,58 @@ public class ParametersModifyingOperationPreprocessorTests {
public void addNewParameter() {
Parameters parameters = new Parameters();
assertThat(this.preprocessor.add("a", "alpha")
- .preprocess(createRequest(parameters)).getParameters(),
- hasEntry(equalTo("a"), contains("alpha")));
+ .preprocess(createRequest(parameters)).getParameters()).containsEntry("a",
+ Arrays.asList("alpha"));
}
@Test
public void addValueToExistingParameter() {
Parameters parameters = new Parameters();
parameters.add("a", "apple");
- assertThat(
- this.preprocessor.add("a", "alpha").preprocess(createRequest(parameters))
- .getParameters(),
- hasEntry(equalTo("a"), contains("apple", "alpha")));
+ assertThat(this.preprocessor.add("a", "alpha")
+ .preprocess(createRequest(parameters)).getParameters()).containsEntry("a",
+ Arrays.asList("apple", "alpha"));
}
@Test
public void setNewParameter() {
Parameters parameters = new Parameters();
- assertThat(
- this.preprocessor.set("a", "alpha", "avocado")
- .preprocess(createRequest(parameters)).getParameters(),
- hasEntry(equalTo("a"), contains("alpha", "avocado")));
+ assertThat(this.preprocessor.set("a", "alpha", "avocado")
+ .preprocess(createRequest(parameters)).getParameters()).containsEntry("a",
+ Arrays.asList("alpha", "avocado"));
}
@Test
public void setExistingParameter() {
Parameters parameters = new Parameters();
parameters.add("a", "apple");
- assertThat(
- this.preprocessor.set("a", "alpha", "avocado")
- .preprocess(createRequest(parameters)).getParameters(),
- hasEntry(equalTo("a"), contains("alpha", "avocado")));
+ assertThat(this.preprocessor.set("a", "alpha", "avocado")
+ .preprocess(createRequest(parameters)).getParameters()).containsEntry("a",
+ Arrays.asList("alpha", "avocado"));
}
@Test
public void removeNonExistentParameter() {
Parameters parameters = new Parameters();
assertThat(this.preprocessor.remove("a").preprocess(createRequest(parameters))
- .getParameters().size(), is(equalTo(0)));
+ .getParameters().size()).isEqualTo(0);
}
@Test
public void removeParameter() {
Parameters parameters = new Parameters();
parameters.add("a", "apple");
- assertThat(
- this.preprocessor.set("a", "alpha", "avocado")
- .preprocess(createRequest(parameters)).getParameters(),
- hasEntry(equalTo("a"), contains("alpha", "avocado")));
+ assertThat(this.preprocessor.set("a", "alpha", "avocado")
+ .preprocess(createRequest(parameters)).getParameters()).containsEntry("a",
+ Arrays.asList("alpha", "avocado"));
}
@Test
public void removeParameterValueForNonExistentParameter() {
Parameters parameters = new Parameters();
- assertThat(
- this.preprocessor.remove("a", "apple")
- .preprocess(createRequest(parameters)).getParameters().size(),
- is(equalTo(0)));
+ assertThat(this.preprocessor.remove("a", "apple")
+ .preprocess(createRequest(parameters)).getParameters().size())
+ .isEqualTo(0);
}
@Test
@@ -111,20 +103,18 @@ public class ParametersModifyingOperationPreprocessorTests {
Parameters parameters = new Parameters();
parameters.add("a", "apple");
parameters.add("a", "alpha");
- assertThat(
- this.preprocessor.remove("a", "apple")
- .preprocess(createRequest(parameters)).getParameters(),
- hasEntry(equalTo("a"), contains("alpha")));
+ assertThat(this.preprocessor.remove("a", "apple")
+ .preprocess(createRequest(parameters)).getParameters()).containsEntry("a",
+ Arrays.asList("alpha"));
}
@Test
public void removeParameterValueWithSingleValueRemovesEntryEntirely() {
Parameters parameters = new Parameters();
parameters.add("a", "apple");
- assertThat(
- this.preprocessor.remove("a", "apple")
- .preprocess(createRequest(parameters)).getParameters().size(),
- is(equalTo(0)));
+ assertThat(this.preprocessor.remove("a", "apple")
+ .preprocess(createRequest(parameters)).getParameters().size())
+ .isEqualTo(0);
}
private OperationRequest createRequest(Parameters parameters) {
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PatternReplacingContentModifierTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PatternReplacingContentModifierTests.java
index f8ea398d..5742e482 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PatternReplacingContentModifierTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PatternReplacingContentModifierTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2015 the original author or authors.
+ * Copyright 2014-2018 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.
@@ -23,15 +23,12 @@ import org.junit.Test;
import org.springframework.http.MediaType;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link PatternReplacingContentModifier}.
*
* @author Andy Wilkinson
- *
*/
public class PatternReplacingContentModifierTests {
@@ -43,8 +40,8 @@ public class PatternReplacingContentModifierTests {
PatternReplacingContentModifier contentModifier = new PatternReplacingContentModifier(
pattern, "<>");
assertThat(contentModifier.modifyContent(
- "{\"id\" : \"CA761232-ED42-11CE-BACD-00AA0057B223\"}".getBytes(), null),
- is(equalTo("{\"id\" : \"<>\"}".getBytes())));
+ "{\"id\" : \"CA761232-ED42-11CE-BACD-00AA0057B223\"}".getBytes(), null))
+ .isEqualTo("{\"id\" : \"<>\"}".getBytes());
}
@Test
@@ -54,10 +51,9 @@ public class PatternReplacingContentModifierTests {
Pattern.CASE_INSENSITIVE);
PatternReplacingContentModifier contentModifier = new PatternReplacingContentModifier(
pattern, "<>");
- assertThat(
- contentModifier.modifyContent(
- "{\"id\" : \"CA76-ED42-11CE-BACD\"}".getBytes(), null),
- is(equalTo("{\"id\" : \"CA76-ED42-11CE-BACD\"}".getBytes())));
+ assertThat(contentModifier
+ .modifyContent("{\"id\" : \"CA76-ED42-11CE-BACD\"}".getBytes(), null))
+ .isEqualTo("{\"id\" : \"CA76-ED42-11CE-BACD\"}".getBytes());
}
@Test
@@ -66,10 +62,9 @@ public class PatternReplacingContentModifierTests {
Pattern pattern = Pattern.compile("[0-9]+");
PatternReplacingContentModifier contentModifier = new PatternReplacingContentModifier(
pattern, "<>");
- assertThat(
- contentModifier.modifyContent((japaneseContent + " 123").getBytes(),
- new MediaType("text", "plain", Charset.forName("UTF-8"))),
- is(equalTo((japaneseContent + " <>").getBytes())));
+ assertThat(contentModifier.modifyContent((japaneseContent + " 123").getBytes(),
+ new MediaType("text", "plain", Charset.forName("UTF-8"))))
+ .isEqualTo((japaneseContent + " <>").getBytes());
}
}
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PrettyPrintingContentModifierTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PrettyPrintingContentModifierTests.java
index 132b4c49..9d8b8ed6 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PrettyPrintingContentModifierTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/PrettyPrintingContentModifierTests.java
@@ -25,10 +25,8 @@ import org.junit.Test;
import org.springframework.restdocs.test.OutputCapture;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.isEmptyString;
-import static org.junit.Assert.assertThat;
/**
* Tests for {@link PrettyPrintingContentModifier}.
@@ -44,25 +42,23 @@ public class PrettyPrintingContentModifierTests {
@Test
public void prettyPrintJson() throws Exception {
assertThat(new PrettyPrintingContentModifier()
- .modifyContent("{\"a\":5}".getBytes(), null),
- equalTo(String.format("{%n \"a\" : 5%n}").getBytes()));
+ .modifyContent("{\"a\":5}".getBytes(), null))
+ .isEqualTo(String.format("{%n \"a\" : 5%n}").getBytes());
}
@Test
public void prettyPrintXml() throws Exception {
- assertThat(
- new PrettyPrintingContentModifier().modifyContent(
- "".getBytes(), null),
- equalTo(String
- .format("%n"
+ assertThat(new PrettyPrintingContentModifier().modifyContent(
+ "".getBytes(), null)).isEqualTo(
+ String.format("%n"
+ "%n %n%n")
- .getBytes()));
+ .getBytes());
}
@Test
public void empytContentIsHandledGracefully() throws Exception {
- assertThat(new PrettyPrintingContentModifier().modifyContent("".getBytes(), null),
- equalTo("".getBytes()));
+ assertThat(new PrettyPrintingContentModifier().modifyContent("".getBytes(), null))
+ .isEqualTo("".getBytes());
}
@Test
@@ -70,7 +66,7 @@ public class PrettyPrintingContentModifierTests {
String content = "abcdefg";
this.outputCapture.expect(isEmptyString());
assertThat(new PrettyPrintingContentModifier().modifyContent(content.getBytes(),
- null), equalTo(content.getBytes()));
+ null)).isEqualTo(content.getBytes());
}
@@ -83,7 +79,7 @@ public class PrettyPrintingContentModifierTests {
Map output = objectMapper
.readValue(new PrettyPrintingContentModifier().modifyContent(
objectMapper.writeValueAsBytes(input), null), Map.class);
- assertThat(output, is(equalTo(input)));
+ assertThat(output).isEqualTo(input);
}
}
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/UriModifyingOperationPreprocessorTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/UriModifyingOperationPreprocessorTests.java
index 1907cf49..0ab56170 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/UriModifyingOperationPreprocessorTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/operation/preprocess/UriModifyingOperationPreprocessorTests.java
@@ -35,9 +35,7 @@ import org.springframework.restdocs.operation.OperationResponseFactory;
import org.springframework.restdocs.operation.Parameters;
import org.springframework.restdocs.operation.RequestCookie;
-import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
+import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link UriModifyingOperationPreprocessor}.
@@ -57,8 +55,7 @@ public class UriModifyingOperationPreprocessorTests {
this.preprocessor.scheme("https");
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithUri("http://localhost:12345"));
- assertThat(processed.getUri(),
- is(equalTo(URI.create("https://localhost:12345"))));
+ assertThat(processed.getUri()).isEqualTo(URI.create("https://localhost:12345"));
}
@Test
@@ -66,10 +63,10 @@ public class UriModifyingOperationPreprocessorTests {
this.preprocessor.host("api.example.com");
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithUri("http://api.foo.com:12345"));
- assertThat(processed.getUri(),
- is(equalTo(URI.create("http://api.example.com:12345"))));
- assertThat(processed.getHeaders().getFirst(HttpHeaders.HOST),
- is(equalTo("api.example.com:12345")));
+ assertThat(processed.getUri())
+ .isEqualTo(URI.create("http://api.example.com:12345"));
+ assertThat(processed.getHeaders().getFirst(HttpHeaders.HOST))
+ .isEqualTo("api.example.com:12345");
}
@Test
@@ -77,10 +74,10 @@ public class UriModifyingOperationPreprocessorTests {
this.preprocessor.port(23456);
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithUri("http://api.example.com:12345"));
- assertThat(processed.getUri(),
- is(equalTo(URI.create("http://api.example.com:23456"))));
- assertThat(processed.getHeaders().getFirst(HttpHeaders.HOST),
- is(equalTo("api.example.com:23456")));
+ assertThat(processed.getUri())
+ .isEqualTo(URI.create("http://api.example.com:23456"));
+ assertThat(processed.getHeaders().getFirst(HttpHeaders.HOST))
+ .isEqualTo("api.example.com:23456");
}
@Test
@@ -88,9 +85,9 @@ public class UriModifyingOperationPreprocessorTests {
this.preprocessor.removePort();
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithUri("http://api.example.com:12345"));
- assertThat(processed.getUri(), is(equalTo(URI.create("http://api.example.com"))));
- assertThat(processed.getHeaders().getFirst(HttpHeaders.HOST),
- is(equalTo("api.example.com")));
+ assertThat(processed.getUri()).isEqualTo(URI.create("http://api.example.com"));
+ assertThat(processed.getHeaders().getFirst(HttpHeaders.HOST))
+ .isEqualTo("api.example.com");
}
@Test
@@ -98,8 +95,8 @@ public class UriModifyingOperationPreprocessorTests {
this.preprocessor.removePort();
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithUri("http://api.example.com:12345/foo/bar"));
- assertThat(processed.getUri(),
- is(equalTo(URI.create("http://api.example.com/foo/bar"))));
+ assertThat(processed.getUri())
+ .isEqualTo(URI.create("http://api.example.com/foo/bar"));
}
@Test
@@ -107,8 +104,8 @@ public class UriModifyingOperationPreprocessorTests {
this.preprocessor.removePort();
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithUri("http://api.example.com:12345?foo=bar"));
- assertThat(processed.getUri(),
- is(equalTo(URI.create("http://api.example.com?foo=bar"))));
+ assertThat(processed.getUri())
+ .isEqualTo(URI.create("http://api.example.com?foo=bar"));
}
@Test
@@ -116,8 +113,8 @@ public class UriModifyingOperationPreprocessorTests {
this.preprocessor.removePort();
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithUri("http://api.example.com:12345#foo"));
- assertThat(processed.getUri(),
- is(equalTo(URI.create("http://api.example.com#foo"))));
+ assertThat(processed.getUri())
+ .isEqualTo(URI.create("http://api.example.com#foo"));
}
@Test
@@ -126,8 +123,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithContent(
"The uri 'http://localhost:12345' should be used"));
- assertThat(new String(processed.getContent()),
- is(equalTo("The uri 'https://localhost:12345' should be used")));
+ assertThat(new String(processed.getContent()))
+ .isEqualTo("The uri 'https://localhost:12345' should be used");
}
@Test
@@ -136,8 +133,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithContent(
"The uri 'http://localhost:12345' should be used"));
- assertThat(new String(processed.getContent()),
- is(equalTo("The uri 'http://api.example.com:12345' should be used")));
+ assertThat(new String(processed.getContent()))
+ .isEqualTo("The uri 'http://api.example.com:12345' should be used");
}
@Test
@@ -146,8 +143,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithContent(
"The uri 'http://localhost:12345' should be used"));
- assertThat(new String(processed.getContent()),
- is(equalTo("The uri 'http://localhost:23456' should be used")));
+ assertThat(new String(processed.getContent()))
+ .isEqualTo("The uri 'http://localhost:23456' should be used");
}
@Test
@@ -156,8 +153,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithContent(
"The uri 'http://localhost:12345' should be used"));
- assertThat(new String(processed.getContent()),
- is(equalTo("The uri 'http://localhost' should be used")));
+ assertThat(new String(processed.getContent()))
+ .isEqualTo("The uri 'http://localhost' should be used");
}
@Test
@@ -166,8 +163,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithContent(
"Use 'http://localhost:12345' or 'https://localhost:23456' to access the service"));
- assertThat(new String(processed.getContent()), is(equalTo(
- "Use 'http://localhost' or 'https://localhost' to access the service")));
+ assertThat(new String(processed.getContent())).isEqualTo(
+ "Use 'http://localhost' or 'https://localhost' to access the service");
}
@Test
@@ -176,8 +173,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithContent(
"The uri 'http://localhost:12345/foo/bar' should be used"));
- assertThat(new String(processed.getContent()),
- is(equalTo("The uri 'http://localhost/foo/bar' should be used")));
+ assertThat(new String(processed.getContent()))
+ .isEqualTo("The uri 'http://localhost/foo/bar' should be used");
}
@Test
@@ -186,8 +183,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithContent(
"The uri 'http://localhost:12345?foo=bar' should be used"));
- assertThat(new String(processed.getContent()),
- is(equalTo("The uri 'http://localhost?foo=bar' should be used")));
+ assertThat(new String(processed.getContent()))
+ .isEqualTo("The uri 'http://localhost?foo=bar' should be used");
}
@Test
@@ -196,8 +193,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithContent(
"The uri 'http://localhost:12345#foo' should be used"));
- assertThat(new String(processed.getContent()),
- is(equalTo("The uri 'http://localhost#foo' should be used")));
+ assertThat(new String(processed.getContent()))
+ .isEqualTo("The uri 'http://localhost#foo' should be used");
}
@Test
@@ -206,8 +203,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationResponse processed = this.preprocessor
.preprocess(createResponseWithContent(
"The uri 'http://localhost:12345' should be used"));
- assertThat(new String(processed.getContent()),
- is(equalTo("The uri 'https://localhost:12345' should be used")));
+ assertThat(new String(processed.getContent()))
+ .isEqualTo("The uri 'https://localhost:12345' should be used");
}
@Test
@@ -216,8 +213,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationResponse processed = this.preprocessor
.preprocess(createResponseWithContent(
"The uri 'http://localhost:12345' should be used"));
- assertThat(new String(processed.getContent()),
- is(equalTo("The uri 'http://api.example.com:12345' should be used")));
+ assertThat(new String(processed.getContent()))
+ .isEqualTo("The uri 'http://api.example.com:12345' should be used");
}
@Test
@@ -226,8 +223,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationResponse processed = this.preprocessor
.preprocess(createResponseWithContent(
"The uri 'http://localhost:12345' should be used"));
- assertThat(new String(processed.getContent()),
- is(equalTo("The uri 'http://localhost:23456' should be used")));
+ assertThat(new String(processed.getContent()))
+ .isEqualTo("The uri 'http://localhost:23456' should be used");
}
@Test
@@ -236,8 +233,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationResponse processed = this.preprocessor
.preprocess(createResponseWithContent(
"The uri 'http://localhost:12345' should be used"));
- assertThat(new String(processed.getContent()),
- is(equalTo("The uri 'http://localhost' should be used")));
+ assertThat(new String(processed.getContent()))
+ .isEqualTo("The uri 'http://localhost' should be used");
}
@Test
@@ -246,8 +243,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationResponse processed = this.preprocessor
.preprocess(createResponseWithContent(
"Use 'http://localhost:12345' or 'https://localhost:23456' to access the service"));
- assertThat(new String(processed.getContent()), is(equalTo(
- "Use 'http://localhost' or 'https://localhost' to access the service")));
+ assertThat(new String(processed.getContent())).isEqualTo(
+ "Use 'http://localhost' or 'https://localhost' to access the service");
}
@Test
@@ -256,8 +253,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationResponse processed = this.preprocessor
.preprocess(createResponseWithContent(
"The uri 'http://localhost:12345/foo/bar' should be used"));
- assertThat(new String(processed.getContent()),
- is(equalTo("The uri 'http://localhost/foo/bar' should be used")));
+ assertThat(new String(processed.getContent()))
+ .isEqualTo("The uri 'http://localhost/foo/bar' should be used");
}
@Test
@@ -266,8 +263,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationResponse processed = this.preprocessor
.preprocess(createResponseWithContent(
"The uri 'http://localhost:12345?foo=bar' should be used"));
- assertThat(new String(processed.getContent()),
- is(equalTo("The uri 'http://localhost?foo=bar' should be used")));
+ assertThat(new String(processed.getContent()))
+ .isEqualTo("The uri 'http://localhost?foo=bar' should be used");
}
@Test
@@ -276,34 +273,33 @@ public class UriModifyingOperationPreprocessorTests {
OperationResponse processed = this.preprocessor
.preprocess(createResponseWithContent(
"The uri 'http://localhost:12345#foo' should be used"));
- assertThat(new String(processed.getContent()),
- is(equalTo("The uri 'http://localhost#foo' should be used")));
+ assertThat(new String(processed.getContent()))
+ .isEqualTo("The uri 'http://localhost#foo' should be used");
}
@Test
public void urisInRequestHeadersCanBeModified() {
OperationRequest processed = this.preprocessor.host("api.example.com")
.preprocess(createRequestWithHeader("Foo", "http://locahost:12345"));
- assertThat(processed.getHeaders().getFirst("Foo"),
- is(equalTo("http://api.example.com:12345")));
- assertThat(processed.getHeaders().getFirst("Host"),
- is(equalTo("api.example.com")));
+ assertThat(processed.getHeaders().getFirst("Foo"))
+ .isEqualTo("http://api.example.com:12345");
+ assertThat(processed.getHeaders().getFirst("Host")).isEqualTo("api.example.com");
}
@Test
public void urisInResponseHeadersCanBeModified() {
OperationResponse processed = this.preprocessor.host("api.example.com")
.preprocess(createResponseWithHeader("Foo", "http://locahost:12345"));
- assertThat(processed.getHeaders().getFirst("Foo"),
- is(equalTo("http://api.example.com:12345")));
+ assertThat(processed.getHeaders().getFirst("Foo"))
+ .isEqualTo("http://api.example.com:12345");
}
@Test
public void urisInRequestPartHeadersCanBeModified() {
OperationRequest processed = this.preprocessor.host("api.example.com").preprocess(
createRequestWithPartWithHeader("Foo", "http://locahost:12345"));
- assertThat(processed.getParts().iterator().next().getHeaders().getFirst("Foo"),
- is(equalTo("http://api.example.com:12345")));
+ assertThat(processed.getParts().iterator().next().getHeaders().getFirst("Foo"))
+ .isEqualTo("http://api.example.com:12345");
}
@Test
@@ -311,8 +307,8 @@ public class UriModifyingOperationPreprocessorTests {
OperationRequest processed = this.preprocessor.host("api.example.com")
.preprocess(createRequestWithPartWithContent(
"The uri 'http://localhost:12345' should be used"));
- assertThat(new String(processed.getParts().iterator().next().getContent()),
- is(equalTo("The uri 'http://api.example.com:12345' should be used")));
+ assertThat(new String(processed.getParts().iterator().next().getContent()))
+ .isEqualTo("The uri 'http://api.example.com:12345' should be used");
}
@Test
@@ -320,8 +316,8 @@ public class UriModifyingOperationPreprocessorTests {
this.preprocessor.scheme("https");
OperationRequest processed = this.preprocessor
.preprocess(createRequestWithUri("http://localhost:12345?foo=%7B%7D"));
- assertThat(processed.getUri(),
- is(equalTo(URI.create("https://localhost:12345?foo=%7B%7D"))));
+ assertThat(processed.getUri())
+ .isEqualTo(URI.create("https://localhost:12345?foo=%7B%7D"));
}
@@ -333,7 +329,7 @@ public class UriModifyingOperationPreprocessorTests {
new HttpHeaders(), new Parameters(),
Collections.emptyList(), cookies);
OperationRequest processed = this.preprocessor.preprocess(request);
- assertThat(processed.getCookies().size(), is(equalTo(1)));
+ assertThat(processed.getCookies().size()).isEqualTo(1);
}
private OperationRequest createRequestWithUri(String uri) {
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/AsciidoctorRequestFieldsSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/AsciidoctorRequestFieldsSnippetTests.java
index 9f737e3a..1ce44f4b 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/AsciidoctorRequestFieldsSnippetTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/AsciidoctorRequestFieldsSnippetTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2016 the original author or authors.
+ * Copyright 2014-2018 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.
@@ -26,14 +26,15 @@ import org.springframework.core.io.FileSystemResource;
import org.springframework.restdocs.templates.TemplateEngine;
import org.springframework.restdocs.templates.TemplateResourceResolver;
import org.springframework.restdocs.templates.mustache.MustacheTemplateEngine;
-import org.springframework.restdocs.test.ExpectedSnippets;
+import org.springframework.restdocs.test.GeneratedSnippets;
import org.springframework.restdocs.test.OperationBuilder;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
import static org.springframework.restdocs.templates.TemplateFormats.asciidoctor;
-import static org.springframework.restdocs.test.SnippetMatchers.tableWithHeader;
+import static org.springframework.restdocs.test.SnippetConditions.tableWithHeader;
/**
* Tests for {@link RequestFieldsSnippet} that are specific to Asciidoctor.
@@ -46,19 +47,13 @@ public class AsciidoctorRequestFieldsSnippetTests {
public OperationBuilder operationBuilder = new OperationBuilder(asciidoctor());
@Rule
- public ExpectedSnippets snippets = new ExpectedSnippets(asciidoctor());
+ public GeneratedSnippets generatedSnippets = new GeneratedSnippets(asciidoctor());
@Test
public void requestFieldsWithListDescription() throws IOException {
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
given(resolver.resolveTemplateResource("request-fields"))
.willReturn(snippetResource("request-fields-with-list-description"));
- this.snippets.expectRequestFields().withContents(
- tableWithHeader(asciidoctor(), "Path", "Type", "Description")
- //
- .row("a", "String", String.format(" - one%n - two"))
- .configuration("[cols=\"1,1,1a\"]"));
-
new RequestFieldsSnippet(
Arrays.asList(
fieldWithPath("a").description(Arrays.asList("one", "two"))))
@@ -69,6 +64,11 @@ public class AsciidoctorRequestFieldsSnippetTests {
resolver))
.request("http://localhost")
.content("{\"a\": \"foo\"}").build());
+ assertThat(this.generatedSnippets.requestFields())
+ .is(tableWithHeader(asciidoctor(), "Path", "Type", "Description")
+ //
+ .row("a", "String", String.format(" - one%n - two"))
+ .configuration("[cols=\"1,1,1a\"]"));
}
private FileSystemResource snippetResource(String name) {
diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/FieldPathPayloadSubsectionExtractorTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/FieldPathPayloadSubsectionExtractorTests.java
index eabc887a..42c7ae07 100644
--- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/FieldPathPayloadSubsectionExtractorTests.java
+++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/FieldPathPayloadSubsectionExtractorTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014-2016 the original author or authors.
+ * Copyright 2014-2018 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.
@@ -29,9 +29,8 @@ import org.junit.rules.ExpectedException;
import org.springframework.http.MediaType;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.CoreMatchers.equalTo;
-import static org.hamcrest.CoreMatchers.is;
-import static org.junit.Assert.assertThat;
/**
* Tests for {@link FieldPathPayloadSubsectionExtractor}.
@@ -52,8 +51,8 @@ public class FieldPathPayloadSubsectionExtractorTests {
MediaType.APPLICATION_JSON);
Map extracted = new ObjectMapper().readValue(extractedPayload,
Map.class);
- assertThat(extracted.size(), is(equalTo(1)));
- assertThat(extracted.get("c"), is(equalTo((Object) 5)));
+ assertThat(extracted.size()).isEqualTo(1);
+ assertThat(extracted.get("c")).isEqualTo(5);
}
@Test
@@ -65,9 +64,9 @@ public class FieldPathPayloadSubsectionExtractorTests {
MediaType.APPLICATION_JSON);
List