From 3544ed045b8def260bce5db023bd6684fa8a6ae2 Mon Sep 17 00:00:00 2001 From: dreis2211 Date: Mon, 10 Dec 2018 00:14:08 +0100 Subject: [PATCH] Drop ContentContainingCondition in favor of Assertions.contentOf Closes gh-15429 --- .../restdocs/ContentContainingCondition.java | 54 ------------------- ...AdvancedConfigurationIntegrationTests.java | 10 ++-- ...DocsAutoConfigurationIntegrationTests.java | 14 ++--- ...AdvancedConfigurationIntegrationTests.java | 14 ++--- ...DocsAutoConfigurationIntegrationTests.java | 14 ++--- ...AdvancedConfigurationIntegrationTests.java | 14 ++--- ...DocsAutoConfigurationIntegrationTests.java | 14 ++--- 7 files changed, 28 insertions(+), 106 deletions(-) delete mode 100644 spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/ContentContainingCondition.java diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/ContentContainingCondition.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/ContentContainingCondition.java deleted file mode 100644 index 2ca90ac054..0000000000 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/ContentContainingCondition.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2012-2017 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.test.autoconfigure.restdocs; - -import java.io.File; -import java.io.FileReader; -import java.io.IOException; -import java.io.Reader; - -import org.assertj.core.api.Condition; -import org.assertj.core.description.TextDescription; - -import org.springframework.util.FileCopyUtils; - -/** - * A {@link Condition} to assert that a file's contents contain a given string. - * - * @author Andy Wilkinson - */ -class ContentContainingCondition extends Condition { - - private final String toContain; - - ContentContainingCondition(String toContain) { - super(new TextDescription("content containing %s", toContain)); - this.toContain = toContain; - } - - @Override - public boolean matches(File value) { - try (Reader reader = new FileReader(value)) { - String content = FileCopyUtils.copyToString(reader); - return content.contains(this.toContain); - } - catch (IOException ex) { - throw new IllegalStateException(ex); - } - } - -} diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/MockMvcRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/MockMvcRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java index 54bf1cdeaf..7891764be2 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/MockMvcRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/MockMvcRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java @@ -18,7 +18,6 @@ package org.springframework.boot.test.autoconfigure.restdocs; import java.io.File; -import org.assertj.core.api.Condition; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -37,6 +36,7 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.util.FileSystemUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.contentOf; import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.linkWithRel; import static org.springframework.restdocs.hypermedia.HypermediaDocumentation.links; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; @@ -77,16 +77,12 @@ public class MockMvcRestDocsAutoConfigurationAdvancedConfigurationIntegrationTes linkWithRel("self").description("Canonical location of this resource")))); File defaultSnippetsDir = new File(this.generatedSnippets, "snippet-generation"); assertThat(defaultSnippetsDir).exists(); - assertThat(new File(defaultSnippetsDir, "curl-request.md")) - .has(contentContaining("'http://localhost:8080/'")); + assertThat(contentOf(new File(defaultSnippetsDir, "curl-request.md"))) + .contains("'http://localhost:8080/'"); assertThat(new File(defaultSnippetsDir, "links.md")).isFile(); assertThat(new File(defaultSnippetsDir, "response-fields.md")).isFile(); } - private Condition contentContaining(String toContain) { - return new ContentContainingCondition(toContain); - } - @TestConfiguration public static class CustomizationConfiguration { diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/MockMvcRestDocsAutoConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/MockMvcRestDocsAutoConfigurationIntegrationTests.java index 905230c786..c5ca5ae20c 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/MockMvcRestDocsAutoConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/MockMvcRestDocsAutoConfigurationIntegrationTests.java @@ -18,7 +18,6 @@ package org.springframework.boot.test.autoconfigure.restdocs; import java.io.File; -import org.assertj.core.api.Condition; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -31,6 +30,7 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.util.FileSystemUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.contentOf; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -61,15 +61,11 @@ public class MockMvcRestDocsAutoConfigurationIntegrationTests { this.mvc.perform(get("/")).andDo(document("default-snippets")); File defaultSnippetsDir = new File(this.generatedSnippets, "default-snippets"); assertThat(defaultSnippetsDir).exists(); - assertThat(new File(defaultSnippetsDir, "curl-request.adoc")) - .has(contentContaining("'https://api.example.com/'")); - assertThat(new File(defaultSnippetsDir, "http-request.adoc")) - .has(contentContaining("api.example.com")); + assertThat(contentOf(new File(defaultSnippetsDir, "curl-request.adoc"))) + .contains("'https://api.example.com/'"); + assertThat(contentOf(new File(defaultSnippetsDir, "http-request.adoc"))) + .contains("api.example.com"); assertThat(new File(defaultSnippetsDir, "http-response.adoc")).isFile(); } - private Condition contentContaining(String toContain) { - return new ContentContainingCondition(toContain); - } - } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/RestAssuredRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/RestAssuredRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java index ce00d5bc7e..2d5f797bbd 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/RestAssuredRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/RestAssuredRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java @@ -19,7 +19,6 @@ package org.springframework.boot.test.autoconfigure.restdocs; import java.io.File; import io.restassured.specification.RequestSpecification; -import org.assertj.core.api.Condition; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -39,6 +38,7 @@ import org.springframework.util.FileSystemUtils; import static io.restassured.RestAssured.given; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.contentOf; import static org.hamcrest.CoreMatchers.is; import static org.springframework.restdocs.operation.preprocess.Preprocessors.modifyUris; import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; @@ -81,18 +81,14 @@ public class RestAssuredRestDocsAutoConfigurationAdvancedConfigurationIntegratio .when().port(this.port).get("/").then().assertThat().statusCode(is(200)); File defaultSnippetsDir = new File(this.generatedSnippets, "default-snippets"); assertThat(defaultSnippetsDir).exists(); - assertThat(new File(defaultSnippetsDir, "curl-request.md")) - .has(contentContaining("'https://api.example.com/'")); - assertThat(new File(defaultSnippetsDir, "http-request.md")) - .has(contentContaining("api.example.com")); + assertThat(contentOf(new File(defaultSnippetsDir, "curl-request.md"))) + .contains("'https://api.example.com/'"); + assertThat(contentOf(new File(defaultSnippetsDir, "http-request.md"))) + .contains("api.example.com"); assertThat(new File(defaultSnippetsDir, "http-response.md")).isFile(); assertThat(new File(defaultSnippetsDir, "response-fields.md")).isFile(); } - private Condition contentContaining(String toContain) { - return new ContentContainingCondition(toContain); - } - @TestConfiguration public static class CustomizationConfiguration { diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/RestAssuredRestDocsAutoConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/RestAssuredRestDocsAutoConfigurationIntegrationTests.java index cd77333c13..19c211ed10 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/RestAssuredRestDocsAutoConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/RestAssuredRestDocsAutoConfigurationIntegrationTests.java @@ -19,7 +19,6 @@ package org.springframework.boot.test.autoconfigure.restdocs; import java.io.File; import io.restassured.specification.RequestSpecification; -import org.assertj.core.api.Condition; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -34,6 +33,7 @@ import org.springframework.util.FileSystemUtils; import static io.restassured.RestAssured.given; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.contentOf; import static org.hamcrest.CoreMatchers.is; import static org.springframework.restdocs.operation.preprocess.Preprocessors.modifyUris; import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest; @@ -73,15 +73,11 @@ public class RestAssuredRestDocsAutoConfigurationIntegrationTests { .when().port(this.port).get("/").then().assertThat().statusCode(is(200)); File defaultSnippetsDir = new File(this.generatedSnippets, "default-snippets"); assertThat(defaultSnippetsDir).exists(); - assertThat(new File(defaultSnippetsDir, "curl-request.adoc")) - .has(contentContaining("'https://api.example.com/'")); - assertThat(new File(defaultSnippetsDir, "http-request.adoc")) - .has(contentContaining("api.example.com")); + assertThat(contentOf(new File(defaultSnippetsDir, "curl-request.adoc"))) + .contains("'https://api.example.com/'"); + assertThat(contentOf(new File(defaultSnippetsDir, "http-request.adoc"))) + .contains("api.example.com"); assertThat(new File(defaultSnippetsDir, "http-response.adoc")).isFile(); } - private Condition contentContaining(String toContain) { - return new ContentContainingCondition(toContain); - } - } diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/WebTestClientRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/WebTestClientRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java index 7301b7c58f..6cab3131fc 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/WebTestClientRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/WebTestClientRestDocsAutoConfigurationAdvancedConfigurationIntegrationTests.java @@ -18,7 +18,6 @@ package org.springframework.boot.test.autoconfigure.restdocs; import java.io.File; -import org.assertj.core.api.Condition; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -37,6 +36,7 @@ import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.util.FileSystemUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.contentOf; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document; @@ -70,18 +70,14 @@ public class WebTestClientRestDocsAutoConfigurationAdvancedConfigurationIntegrat .expectBody().consumeWith(document("default-snippets")); File defaultSnippetsDir = new File(this.generatedSnippets, "default-snippets"); assertThat(defaultSnippetsDir).exists(); - assertThat(new File(defaultSnippetsDir, "curl-request.md")) - .has(contentContaining("'https://api.example.com/'")); - assertThat(new File(defaultSnippetsDir, "http-request.md")) - .has(contentContaining("api.example.com")); + assertThat(contentOf(new File(defaultSnippetsDir, "curl-request.md"))) + .contains("'https://api.example.com/'"); + assertThat(contentOf(new File(defaultSnippetsDir, "http-request.md"))) + .contains("api.example.com"); assertThat(new File(defaultSnippetsDir, "http-response.md")).isFile(); assertThat(new File(defaultSnippetsDir, "response-fields.md")).isFile(); } - private Condition contentContaining(String toContain) { - return new ContentContainingCondition(toContain); - } - @TestConfiguration public static class CustomizationConfiguration { diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/WebTestClientRestDocsAutoConfigurationIntegrationTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/WebTestClientRestDocsAutoConfigurationIntegrationTests.java index f98c46f817..c170e918ce 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/WebTestClientRestDocsAutoConfigurationIntegrationTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/restdocs/WebTestClientRestDocsAutoConfigurationIntegrationTests.java @@ -18,7 +18,6 @@ package org.springframework.boot.test.autoconfigure.restdocs; import java.io.File; -import org.assertj.core.api.Condition; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -32,6 +31,7 @@ import org.springframework.test.web.reactive.server.WebTestClient; import org.springframework.util.FileSystemUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.contentOf; import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document; /** @@ -63,15 +63,11 @@ public class WebTestClientRestDocsAutoConfigurationIntegrationTests { .expectBody().consumeWith(document("default-snippets")); File defaultSnippetsDir = new File(this.generatedSnippets, "default-snippets"); assertThat(defaultSnippetsDir).exists(); - assertThat(new File(defaultSnippetsDir, "curl-request.adoc")) - .has(contentContaining("'https://api.example.com/'")); - assertThat(new File(defaultSnippetsDir, "http-request.adoc")) - .has(contentContaining("api.example.com")); + assertThat(contentOf(new File(defaultSnippetsDir, "curl-request.adoc"))) + .contains("'https://api.example.com/'"); + assertThat(contentOf(new File(defaultSnippetsDir, "http-request.adoc"))) + .contains("api.example.com"); assertThat(new File(defaultSnippetsDir, "http-response.adoc")).isFile(); } - private Condition contentContaining(String toContain) { - return new ContentContainingCondition(toContain); - } - }