diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportTests.java index 453adaf11f..86bf63ffb4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionEvaluationReportTests.java @@ -34,7 +34,6 @@ import org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportM import org.springframework.boot.autoconfigure.web.servlet.MultipartAutoConfiguration; import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration; import org.springframework.boot.test.util.TestPropertyValues; -import org.springframework.boot.testsupport.assertj.Matched; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Condition; @@ -47,8 +46,6 @@ import org.springframework.core.type.AnnotatedTypeMetadata; import org.springframework.util.ClassUtils; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.nullValue; /** * Tests for {@link ConditionEvaluationReport}. @@ -86,7 +83,7 @@ class ConditionEvaluationReportTests { @Test void get() { - assertThat(this.report).isNotEqualTo(nullValue()); + assertThat(this.report).isNotNull(); assertThat(this.report).isSameAs(ConditionEvaluationReport.get(this.beanFactory)); } @@ -95,8 +92,8 @@ class ConditionEvaluationReportTests { this.beanFactory.setParentBeanFactory(new DefaultListableBeanFactory()); ConditionEvaluationReport.get((ConfigurableListableBeanFactory) this.beanFactory.getParentBeanFactory()); assertThat(this.report).isSameAs(ConditionEvaluationReport.get(this.beanFactory)); - assertThat(this.report).isNotEqualTo(nullValue()); - assertThat(this.report.getParent()).isNotEqualTo(nullValue()); + assertThat(this.report).isNotNull(); + assertThat(this.report.getParent()).isNotNull(); ConditionEvaluationReport.get((ConfigurableListableBeanFactory) this.beanFactory.getParentBeanFactory()); assertThat(this.report).isSameAs(ConditionEvaluationReport.get(this.beanFactory)); assertThat(this.report.getParent()).isSameAs(ConditionEvaluationReport @@ -184,7 +181,7 @@ class ConditionEvaluationReportTests { outcomes.add(this.condition1, new ConditionOutcome(true, "Message 1")); outcomes.add(this.condition2, new ConditionOutcome(true, "Message 2")); outcomes.add(this.condition3, new ConditionOutcome(true, "Message 2")); - assertThat(getNumberOfOutcomes(outcomes)).isEqualTo(2); + assertThat(outcomes).hasSize(2); } @Test @@ -193,15 +190,15 @@ class ConditionEvaluationReportTests { ConditionEvaluationReport report = ConditionEvaluationReport.get(context.getBeanFactory()); String autoconfigKey = MultipartAutoConfiguration.class.getName(); ConditionAndOutcomes outcomes = report.getConditionAndOutcomesBySource().get(autoconfigKey); - assertThat(outcomes).isNotEqualTo(nullValue()); - assertThat(getNumberOfOutcomes(outcomes)).isEqualTo(2); + assertThat(outcomes).isNotNull(); + assertThat(outcomes).hasSize(2); List messages = new ArrayList<>(); for (ConditionAndOutcome outcome : outcomes) { messages.add(outcome.getOutcome().getMessage()); } - assertThat(messages).areAtLeastOne(Matched.by(containsString("@ConditionalOnClass found required classes " + assertThat(messages).anyMatch((message) -> message.contains("@ConditionalOnClass found required classes " + "'javax.servlet.Servlet', 'org.springframework.web.multipart." - + "support.StandardServletMultipartResolver', 'javax.servlet.MultipartConfigElement'"))); + + "support.StandardServletMultipartResolver', 'javax.servlet.MultipartConfigElement'")); context.close(); } @@ -252,16 +249,6 @@ class ConditionEvaluationReportTests { context.close(); } - private int getNumberOfOutcomes(ConditionAndOutcomes outcomes) { - Iterator iterator = outcomes.iterator(); - int numberOfOutcomesAdded = 0; - while (iterator.hasNext()) { - numberOfOutcomesAdded++; - iterator.next(); - } - return numberOfOutcomesAdded; - } - @Configuration(proxyBeanMethods = false) @Import(WebMvcAutoConfiguration.class) static class Config { diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ResourcePropertiesTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ResourcePropertiesTests.java index da6396a3bb..4172490aef 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ResourcePropertiesTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/ResourcePropertiesTests.java @@ -21,11 +21,9 @@ import java.time.Duration; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.web.ResourceProperties.Cache; -import org.springframework.boot.testsupport.assertj.Matched; import org.springframework.http.CacheControl; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.endsWith; /** * Tests for {@link ResourceProperties}. @@ -62,7 +60,7 @@ class ResourcePropertiesTests { @Test void defaultStaticLocationsAllEndWithTrailingSlash() { - assertThat(this.properties.getStaticLocations()).are(Matched.by(endsWith("/"))); + assertThat(this.properties.getStaticLocations()).allMatch((location) -> location.endsWith("/")); } @Test diff --git a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java index dee3a81de2..c82ea3ba84 100644 --- a/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java +++ b/spring-boot-project/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/install/GroovyGrabDependencyResolverTests.java @@ -23,7 +23,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import org.assertj.core.api.Condition; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -31,11 +30,8 @@ import org.springframework.boot.cli.compiler.GroovyCompilerConfiguration; import org.springframework.boot.cli.compiler.GroovyCompilerScope; import org.springframework.boot.cli.compiler.RepositoryConfigurationFactory; import org.springframework.boot.cli.compiler.grape.RepositoryConfiguration; -import org.springframework.boot.testsupport.assertj.Matched; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.startsWith; /** * Tests for {@link GroovyGrabDependencyResolver}. @@ -104,12 +100,13 @@ class GroovyGrabDependencyResolverTests { } @Test - @SuppressWarnings({ "unchecked", "rawtypes" }) void resolveShorthandArtifactWithDependencies() throws Exception { List resolved = this.resolver.resolve(Arrays.asList("spring-beans")); assertThat(resolved).hasSize(3); - assertThat(getNames(resolved)).has((Condition) Matched - .by(hasItems(startsWith("spring-core-"), startsWith("spring-beans-"), startsWith("spring-jcl-")))); + Set names = getNames(resolved); + assertThat(names).anyMatch((name) -> name.startsWith("spring-core-")); + assertThat(names).anyMatch((name) -> name.startsWith("spring-beans-")); + assertThat(names).anyMatch((name) -> name.startsWith("spring-jcl-")); } @Test diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/pom.xml b/spring-boot-project/spring-boot-tools/spring-boot-test-support/pom.xml index 6281d30878..b3b8996a37 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support/pom.xml +++ b/spring-boot-project/spring-boot-tools/spring-boot-test-support/pom.xml @@ -47,10 +47,6 @@ org.springframework spring-core - - org.hamcrest - hamcrest - org.assertj assertj-core diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/assertj/Matched.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/assertj/Matched.java deleted file mode 100644 index d005959f95..0000000000 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/assertj/Matched.java +++ /dev/null @@ -1,61 +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 - * - * https://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.testsupport.assertj; - -import org.assertj.core.api.Condition; -import org.hamcrest.Matcher; -import org.hamcrest.StringDescription; - -import org.springframework.util.Assert; - -/** - * Adapter class allowing a Hamcrest {@link Matcher} to be used as an AssertJ - * {@link Condition}. - * - * @param the type of object that the condition accepts - * @author Phillip Webb - * @since 2.0.0 - */ -public final class Matched extends Condition { - - private final Matcher matcher; - - private Matched(Matcher matcher) { - Assert.notNull(matcher, "Matcher must not be null"); - this.matcher = matcher; - } - - @Override - public boolean matches(T value) { - if (this.matcher.matches(value)) { - return true; - } - StringDescription description = new StringDescription(); - this.matcher.describeTo(description); - describedAs(description.toString()); - return false; - } - - public static Condition when(Matcher matcher) { - return by(matcher); - } - - public static Condition by(Matcher matcher) { - return new Matched<>(matcher); - } - -} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/assertj/package-info.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/assertj/package-info.java deleted file mode 100644 index 46bf5155ca..0000000000 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/main/java/org/springframework/boot/testsupport/assertj/package-info.java +++ /dev/null @@ -1,20 +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 - * - * https://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. - */ - -/** - * Utilities and helpers for AssertJ. - */ -package org.springframework.boot.testsupport.assertj; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/test/java/org/springframework/boot/testsupport/assertj/MatchedTests.java b/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/test/java/org/springframework/boot/testsupport/assertj/MatchedTests.java deleted file mode 100644 index 30d6b5d689..0000000000 --- a/spring-boot-project/spring-boot-tools/spring-boot-test-support/src/test/java/org/springframework/boot/testsupport/assertj/MatchedTests.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2012-2019 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 - * - * https://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.testsupport.assertj; - -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; -import static org.hamcrest.Matchers.startsWith; - -/** - * Tests for {@link Matched}. - * - * @author Phillip Webb - */ -class MatchedTests { - - @Test - void byMatcherMatches() { - assertThat("1234").is(Matched.by(startsWith("12"))); - } - - @Test - void byMatcherDoesNotMatch() { - assertThatExceptionOfType(AssertionError.class) - .isThrownBy(() -> assertThat("1234").is(Matched.by(startsWith("23")))) - .withMessageContaining("a string starting with \"23\""); - } - - @Test - void whenMatcherMatches() { - assertThat("1234").is(Matched.when(startsWith("12"))); - } - - @Test - void whenMatcherDoesNotMatch() { - assertThatExceptionOfType(AssertionError.class) - .isThrownBy(() -> assertThat("1234").is(Matched.when(startsWith("23")))) - .withMessageContaining("a string starting with \"23\""); - } - -} diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/type/classreading/ConcurrentReferenceCachingMetadataReaderFactoryTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/type/classreading/ConcurrentReferenceCachingMetadataReaderFactoryTests.java index 7b85f397d6..359a83c18f 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/type/classreading/ConcurrentReferenceCachingMetadataReaderFactoryTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/type/classreading/ConcurrentReferenceCachingMetadataReaderFactoryTests.java @@ -22,7 +22,6 @@ import org.springframework.core.io.Resource; import org.springframework.core.type.classreading.MetadataReader; import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.Matchers.sameInstance; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; @@ -53,7 +52,7 @@ class ConcurrentReferenceCachingMetadataReaderFactoryTests { MetadataReader metadataReader1 = factory.getMetadataReader(getClass().getName()); factory.clearCache(); MetadataReader metadataReader2 = factory.getMetadataReader(getClass().getName()); - assertThat(metadataReader1).isNotEqualTo(sameInstance(metadataReader2)); + assertThat(metadataReader1).isNotSameAs(metadataReader2); verify(factory, times(2)).createMetadataReader(any(Resource.class)); }