parent
3bf5cf1124
commit
2038fac825
|
|
@ -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<String> 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<ConditionAndOutcome> iterator = outcomes.iterator();
|
||||
int numberOfOutcomesAdded = 0;
|
||||
while (iterator.hasNext()) {
|
||||
numberOfOutcomesAdded++;
|
||||
iterator.next();
|
||||
}
|
||||
return numberOfOutcomesAdded;
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Import(WebMvcAutoConfiguration.class)
|
||||
static class Config {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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<File> 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<String> 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
|
||||
|
|
|
|||
|
|
@ -47,10 +47,6 @@
|
|||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
|
|
|
|||
|
|
@ -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 <T> the type of object that the condition accepts
|
||||
* @author Phillip Webb
|
||||
* @since 2.0.0
|
||||
*/
|
||||
public final class Matched<T> extends Condition<T> {
|
||||
|
||||
private final Matcher<? extends T> matcher;
|
||||
|
||||
private Matched(Matcher<? extends T> 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 <T> Condition<T> when(Matcher<? extends T> matcher) {
|
||||
return by(matcher);
|
||||
}
|
||||
|
||||
public static <T> Condition<T> by(Matcher<? extends T> matcher) {
|
||||
return new Matched<>(matcher);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
@ -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\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue