Skip to content

Commit c9932bb

Browse files
izeyewilkinsona
authored andcommitted
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
1 parent ed4ab66 commit c9932bb

File tree

11 files changed

+23
-23
lines changed

11 files changed

+23
-23
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/ValidationFailureAnalyzerTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import org.springframework.context.annotation.Import;
3131

3232
import static org.assertj.core.api.Assertions.assertThat;
33-
import static org.junit.jupiter.api.Assertions.fail;
33+
import static org.assertj.core.api.Assertions.fail;
3434

3535
/**
3636
* Tests for {@link ValidationFailureAnalyzer}.

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
import static org.assertj.core.api.Assertions.assertThat;
4545
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
46-
import static org.junit.jupiter.api.Assertions.fail;
46+
import static org.assertj.core.api.Assertions.fail;
4747

4848
/**
4949
* Tests for {@link SpringApplicationAdminJmxAutoConfiguration}.

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/TomcatDataSourceConfigurationTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import org.springframework.context.annotation.EnableMBeanExport;
3535

3636
import static org.assertj.core.api.Assertions.assertThat;
37-
import static org.junit.jupiter.api.Assertions.fail;
37+
import static org.assertj.core.api.Assertions.fail;
3838

3939
/**
4040
* Tests for {@link TomcatDataSourceConfiguration}.

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfigurationTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
import org.springframework.web.socket.sockjs.client.WebSocketTransport;
7070

7171
import static org.assertj.core.api.Assertions.assertThat;
72-
import static org.junit.jupiter.api.Assertions.fail;
72+
import static org.assertj.core.api.Assertions.fail;
7373

7474
/**
7575
* Tests for {@link WebSocketMessagingAutoConfiguration}.

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/SilentExitExceptionHandlerTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.junit.jupiter.api.Test;
2222

2323
import static org.assertj.core.api.Assertions.assertThat;
24-
import static org.junit.jupiter.api.Assertions.fail;
24+
import static org.assertj.core.api.Assertions.fail;
2525

2626
/**
2727
* Tests for {@link SilentExitExceptionHandler}.

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/properties/PropertyMapperTests.java

+13-13
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

1919
import java.util.function.Supplier;
2020

21-
import org.junit.jupiter.api.Assertions;
2221
import org.junit.jupiter.api.Test;
2322

2423
import static org.assertj.core.api.Assertions.assertThat;
2524
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
25+
import static org.assertj.core.api.Assertions.fail;
2626

2727
/**
2828
* Tests for {@link PropertyMapper}.
@@ -56,7 +56,7 @@ void fromValueAsIntShouldAdaptValue() {
5656

5757
@Test
5858
void fromValueAlwaysApplyingWhenNonNullShouldAlwaysApplyNonNullToSource() {
59-
this.map.alwaysApplyingWhenNonNull().from((String) null).toCall(Assertions::fail);
59+
this.map.alwaysApplyingWhenNonNull().from((String) null).toCall(() -> fail(null));
6060
}
6161

6262
@Test
@@ -100,14 +100,14 @@ void asShouldAdaptSupplier() {
100100

101101
@Test
102102
void whenNonNullWhenSuppliedNullShouldNotMap() {
103-
this.map.from(() -> null).whenNonNull().as(String::valueOf).toCall(Assertions::fail);
103+
this.map.from(() -> null).whenNonNull().as(String::valueOf).toCall(() -> fail(null));
104104
}
105105

106106
@Test
107107
void whenNonNullWhenSuppliedThrowsNullPointerExceptionShouldNotMap() {
108108
this.map.from(() -> {
109109
throw new NullPointerException();
110-
}).whenNonNull().as(String::valueOf).toCall(Assertions::fail);
110+
}).whenNonNull().as(String::valueOf).toCall(() -> fail(null));
111111
}
112112

113113
@Test
@@ -118,7 +118,7 @@ void whenTrueWhenValueIsTrueShouldMap() {
118118

119119
@Test
120120
void whenTrueWhenValueIsFalseShouldNotMap() {
121-
this.map.from(false).whenTrue().toCall(Assertions::fail);
121+
this.map.from(false).whenTrue().toCall(() -> fail(null));
122122
}
123123

124124
@Test
@@ -129,17 +129,17 @@ void whenFalseWhenValueIsFalseShouldMap() {
129129

130130
@Test
131131
void whenFalseWhenValueIsTrueShouldNotMap() {
132-
this.map.from(true).whenFalse().toCall(Assertions::fail);
132+
this.map.from(true).whenFalse().toCall(() -> fail(null));
133133
}
134134

135135
@Test
136136
void whenHasTextWhenValueIsNullShouldNotMap() {
137-
this.map.from(() -> null).whenHasText().toCall(Assertions::fail);
137+
this.map.from(() -> null).whenHasText().toCall(() -> fail(null));
138138
}
139139

140140
@Test
141141
void whenHasTextWhenValueIsEmptyShouldNotMap() {
142-
this.map.from("").whenHasText().toCall(Assertions::fail);
142+
this.map.from("").whenHasText().toCall(() -> fail(null));
143143
}
144144

145145
@Test
@@ -156,7 +156,7 @@ void whenEqualToWhenValueIsEqualShouldMatch() {
156156

157157
@Test
158158
void whenEqualToWhenValueIsNotEqualShouldNotMatch() {
159-
this.map.from("123").whenEqualTo("321").toCall(Assertions::fail);
159+
this.map.from("123").whenEqualTo("321").toCall(() -> fail(null));
160160
}
161161

162162
@Test
@@ -168,7 +168,7 @@ void whenInstanceOfWhenValueIsTargetTypeShouldMatch() {
168168
@Test
169169
void whenInstanceOfWhenValueIsNotTargetTypeShouldNotMatch() {
170170
Supplier<Number> supplier = () -> 123L;
171-
this.map.from(supplier).whenInstanceOf(Double.class).toCall(Assertions::fail);
171+
this.map.from(supplier).whenInstanceOf(Double.class).toCall(() -> fail(null));
172172
}
173173

174174
@Test
@@ -179,7 +179,7 @@ void whenWhenValueMatchesShouldMap() {
179179

180180
@Test
181181
void whenWhenValueDoesNotMatchShouldNotMap() {
182-
this.map.from("123").when("321"::equals).toCall(Assertions::fail);
182+
this.map.from("123").when("321"::equals).toCall(() -> fail(null));
183183
}
184184

185185
@Test
@@ -197,12 +197,12 @@ void whenWhenCombinedWithAsUsesSourceValue() {
197197

198198
@Test
199199
void alwaysApplyingWhenNonNullShouldAlwaysApplyNonNullToSource() {
200-
this.map.alwaysApplyingWhenNonNull().from(() -> null).toCall(Assertions::fail);
200+
this.map.alwaysApplyingWhenNonNull().from(() -> null).toCall(() -> fail(null));
201201
}
202202

203203
@Test
204204
void whenWhenValueNotMatchesShouldSupportChainedCalls() {
205-
this.map.from("123").when("456"::equals).when("123"::equals).toCall(Assertions::fail);
205+
this.map.from("123").when("456"::equals).when("123"::equals).toCall(() -> fail(null));
206206
}
207207

208208
@Test

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanCurrentlyInCreationFailureAnalyzerTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import org.springframework.context.annotation.Configuration;
3838

3939
import static org.assertj.core.api.Assertions.assertThat;
40-
import static org.junit.jupiter.api.Assertions.fail;
40+
import static org.assertj.core.api.Assertions.fail;
4141

4242
/**
4343
* Tests for {@link BeanCurrentlyInCreationFailureAnalyzer}.

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/diagnostics/analyzer/BeanNotOfRequiredTypeFailureAnalyzerTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.springframework.scheduling.annotation.EnableAsync;
3030

3131
import static org.assertj.core.api.Assertions.assertThat;
32-
import static org.junit.jupiter.api.Assertions.fail;
32+
import static org.assertj.core.api.Assertions.fail;
3333

3434
/**
3535
* Tests for {@link BeanNotOfRequiredTypeFailureAnalyzer}.

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/util/LambdaSafeTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
import static org.assertj.core.api.Assertions.assertThat;
3131
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
32-
import static org.junit.jupiter.api.Assertions.fail;
32+
import static org.assertj.core.api.Assertions.fail;
3333
import static org.mockito.ArgumentMatchers.any;
3434
import static org.mockito.ArgumentMatchers.contains;
3535
import static org.mockito.BDDMockito.given;

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/servlet/server/AbstractServletWebServerFactoryTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
150150
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
151151
import static org.assertj.core.api.Assertions.assertThatThrownBy;
152-
import static org.junit.jupiter.api.Assertions.fail;
152+
import static org.assertj.core.api.Assertions.fail;
153153
import static org.mockito.ArgumentMatchers.any;
154154
import static org.mockito.BDDMockito.given;
155155
import static org.mockito.BDDMockito.then;

src/checkstyle/checkstyle.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
</module>
3333
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
3434
<property name="maximum" value="0"/>
35-
<property name="format" value="org\.junit\.Assert\.assert" />
35+
<property name="format" value="org\.junit\.Assert|org\.junit\.jupiter\.api\.Assertions" />
3636
<property name="message"
3737
value="Please use AssertJ imports." />
3838
<property name="ignoreComments" value="true" />

0 commit comments

Comments
 (0)