mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-07-15 01:07:30 +08:00
Use AssertJ's fail, not JUnit's
This commit also updates Checkstyle to prevent use of JUnit's assertions from being reintroduced. See gh-37655
This commit is contained in:
parent
ed4ab667a1
commit
c9932bb73a
@ -30,7 +30,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests for {@link ValidationFailureAnalyzer}.
|
||||
|
@ -43,7 +43,7 @@ import org.springframework.jmx.export.MBeanExporter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests for {@link SpringApplicationAdminJmxAutoConfiguration}.
|
||||
|
@ -34,7 +34,7 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.EnableMBeanExport;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests for {@link TomcatDataSourceConfiguration}.
|
||||
|
@ -69,7 +69,7 @@ import org.springframework.web.socket.sockjs.client.Transport;
|
||||
import org.springframework.web.socket.sockjs.client.WebSocketTransport;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests for {@link WebSocketMessagingAutoConfiguration}.
|
||||
|
@ -21,7 +21,7 @@ import java.util.concurrent.CountDownLatch;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests for {@link SilentExitExceptionHandler}.
|
||||
|
@ -18,11 +18,11 @@ package org.springframework.boot.context.properties;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests for {@link PropertyMapper}.
|
||||
@ -56,7 +56,7 @@ class PropertyMapperTests {
|
||||
|
||||
@Test
|
||||
void fromValueAlwaysApplyingWhenNonNullShouldAlwaysApplyNonNullToSource() {
|
||||
this.map.alwaysApplyingWhenNonNull().from((String) null).toCall(Assertions::fail);
|
||||
this.map.alwaysApplyingWhenNonNull().from((String) null).toCall(() -> fail(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -100,14 +100,14 @@ class PropertyMapperTests {
|
||||
|
||||
@Test
|
||||
void whenNonNullWhenSuppliedNullShouldNotMap() {
|
||||
this.map.from(() -> null).whenNonNull().as(String::valueOf).toCall(Assertions::fail);
|
||||
this.map.from(() -> null).whenNonNull().as(String::valueOf).toCall(() -> fail(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenNonNullWhenSuppliedThrowsNullPointerExceptionShouldNotMap() {
|
||||
this.map.from(() -> {
|
||||
throw new NullPointerException();
|
||||
}).whenNonNull().as(String::valueOf).toCall(Assertions::fail);
|
||||
}).whenNonNull().as(String::valueOf).toCall(() -> fail(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -118,7 +118,7 @@ class PropertyMapperTests {
|
||||
|
||||
@Test
|
||||
void whenTrueWhenValueIsFalseShouldNotMap() {
|
||||
this.map.from(false).whenTrue().toCall(Assertions::fail);
|
||||
this.map.from(false).whenTrue().toCall(() -> fail(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -129,17 +129,17 @@ class PropertyMapperTests {
|
||||
|
||||
@Test
|
||||
void whenFalseWhenValueIsTrueShouldNotMap() {
|
||||
this.map.from(true).whenFalse().toCall(Assertions::fail);
|
||||
this.map.from(true).whenFalse().toCall(() -> fail(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenHasTextWhenValueIsNullShouldNotMap() {
|
||||
this.map.from(() -> null).whenHasText().toCall(Assertions::fail);
|
||||
this.map.from(() -> null).whenHasText().toCall(() -> fail(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenHasTextWhenValueIsEmptyShouldNotMap() {
|
||||
this.map.from("").whenHasText().toCall(Assertions::fail);
|
||||
this.map.from("").whenHasText().toCall(() -> fail(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -156,7 +156,7 @@ class PropertyMapperTests {
|
||||
|
||||
@Test
|
||||
void whenEqualToWhenValueIsNotEqualShouldNotMatch() {
|
||||
this.map.from("123").whenEqualTo("321").toCall(Assertions::fail);
|
||||
this.map.from("123").whenEqualTo("321").toCall(() -> fail(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -168,7 +168,7 @@ class PropertyMapperTests {
|
||||
@Test
|
||||
void whenInstanceOfWhenValueIsNotTargetTypeShouldNotMatch() {
|
||||
Supplier<Number> supplier = () -> 123L;
|
||||
this.map.from(supplier).whenInstanceOf(Double.class).toCall(Assertions::fail);
|
||||
this.map.from(supplier).whenInstanceOf(Double.class).toCall(() -> fail(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -179,7 +179,7 @@ class PropertyMapperTests {
|
||||
|
||||
@Test
|
||||
void whenWhenValueDoesNotMatchShouldNotMap() {
|
||||
this.map.from("123").when("321"::equals).toCall(Assertions::fail);
|
||||
this.map.from("123").when("321"::equals).toCall(() -> fail(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -197,12 +197,12 @@ class PropertyMapperTests {
|
||||
|
||||
@Test
|
||||
void alwaysApplyingWhenNonNullShouldAlwaysApplyNonNullToSource() {
|
||||
this.map.alwaysApplyingWhenNonNull().from(() -> null).toCall(Assertions::fail);
|
||||
this.map.alwaysApplyingWhenNonNull().from(() -> null).toCall(() -> fail(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenWhenValueNotMatchesShouldSupportChainedCalls() {
|
||||
this.map.from("123").when("456"::equals).when("123"::equals).toCall(Assertions::fail);
|
||||
this.map.from("123").when("456"::equals).when("123"::equals).toCall(() -> fail(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -37,7 +37,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests for {@link BeanCurrentlyInCreationFailureAnalyzer}.
|
||||
|
@ -29,7 +29,7 @@ import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Tests for {@link BeanNotOfRequiredTypeFailureAnalyzer}.
|
||||
|
@ -29,7 +29,7 @@ import org.springframework.boot.util.LambdaSafe.InvocationResult;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.contains;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
@ -149,7 +149,7 @@ import static org.assertj.core.api.Assertions.assertThatIOException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.then;
|
||||
|
@ -32,7 +32,7 @@
|
||||
</module>
|
||||
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
|
||||
<property name="maximum" value="0"/>
|
||||
<property name="format" value="org\.junit\.Assert\.assert" />
|
||||
<property name="format" value="org\.junit\.Assert|org\.junit\.jupiter\.api\.Assertions" />
|
||||
<property name="message"
|
||||
value="Please use AssertJ imports." />
|
||||
<property name="ignoreComments" value="true" />
|
||||
|
Loading…
Reference in New Issue
Block a user