Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
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;
Expand All @@ -47,8 +46,6 @@
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}.
Expand Down Expand Up @@ -86,7 +83,7 @@ void setup() {

@Test
void get() {
assertThat(this.report).isNotEqualTo(nullValue());
assertThat(this.report).isNotNull();
assertThat(this.report).isSameAs(ConditionEvaluationReport.get(this.beanFactory));
}

Expand All @@ -95,8 +92,8 @@ void parent() {
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
Expand Down Expand Up @@ -184,7 +181,7 @@ void testDuplicateConditionAndOutcomes() {
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
Expand All @@ -193,15 +190,15 @@ void duplicateOutcomes() {
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();
}

Expand Down Expand Up @@ -252,16 +249,6 @@ void reportMessageWhenSameShortNamePresentMoreThanOnceShouldUseFullyQualifiedNam
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@
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}.
Expand Down Expand Up @@ -62,7 +60,7 @@ void resourceChainDisabled() {

@Test
void defaultStaticLocationsAllEndWithTrailingSlash() {
assertThat(this.properties.getStaticLocations()).are(Matched.by(endsWith("/")));
assertThat(this.properties.getStaticLocations()).allMatch((location) -> location.endsWith("/"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,15 @@
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;

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}.
Expand Down Expand Up @@ -104,12 +100,13 @@ void resolveArtifactWithDependencies() throws Exception {
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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;
Expand Down Expand Up @@ -53,7 +52,7 @@ void clearResetsCache() throws Exception {
MetadataReader metadataReader1 = factory.getMetadataReader(getClass().getName());
factory.clearCache();
MetadataReader metadataReader2 = factory.getMetadataReader(getClass().getName());
assertThat(metadataReader1).isNotEqualTo(sameInstance(metadataReader2));
assertThat(metadataReader1).isNotSameAs(metadataReader2);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hope that slightly related polishing is okay here.

verify(factory, times(2)).createMetadataReader(any(Resource.class));
}

Expand Down