Skip to content

Commit 7598bca

Browse files
committed
Revise Checkstyle rules to prohibit use of assertions other than AssertJ
Closes gh-31116
1 parent f9588de commit 7598bca

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

spring-test/src/test/java/org/springframework/test/context/junit4/FailingBeforeAndAfterMethodsTestNGTests.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.springframework.util.ClassUtils;
3535

3636
import static org.assertj.core.api.Assertions.assertThat;
37+
import static org.assertj.core.api.Assertions.fail;
3738

3839
/**
3940
* Integration tests which verify that '<i>before</i>' and '<i>after</i>'
@@ -112,55 +113,55 @@ static class AlwaysFailingBeforeTestClassTestExecutionListener implements TestEx
112113

113114
@Override
114115
public void beforeTestClass(TestContext testContext) {
115-
org.testng.Assert.fail("always failing beforeTestClass()");
116+
fail("always failing beforeTestClass()");
116117
}
117118
}
118119

119120
static class AlwaysFailingAfterTestClassTestExecutionListener implements TestExecutionListener {
120121

121122
@Override
122123
public void afterTestClass(TestContext testContext) {
123-
org.testng.Assert.fail("always failing afterTestClass()");
124+
fail("always failing afterTestClass()");
124125
}
125126
}
126127

127128
static class AlwaysFailingPrepareTestInstanceTestExecutionListener implements TestExecutionListener {
128129

129130
@Override
130131
public void prepareTestInstance(TestContext testContext) throws Exception {
131-
org.testng.Assert.fail("always failing prepareTestInstance()");
132+
fail("always failing prepareTestInstance()");
132133
}
133134
}
134135

135136
static class AlwaysFailingBeforeTestMethodTestExecutionListener implements TestExecutionListener {
136137

137138
@Override
138139
public void beforeTestMethod(TestContext testContext) {
139-
org.testng.Assert.fail("always failing beforeTestMethod()");
140+
fail("always failing beforeTestMethod()");
140141
}
141142
}
142143

143144
static class AlwaysFailingBeforeTestExecutionTestExecutionListener implements TestExecutionListener {
144145

145146
@Override
146147
public void beforeTestExecution(TestContext testContext) {
147-
org.testng.Assert.fail("always failing beforeTestExecution()");
148+
fail("always failing beforeTestExecution()");
148149
}
149150
}
150151

151152
static class AlwaysFailingAfterTestExecutionTestExecutionListener implements TestExecutionListener {
152153

153154
@Override
154155
public void afterTestExecution(TestContext testContext) {
155-
org.testng.Assert.fail("always failing afterTestExecution()");
156+
fail("always failing afterTestExecution()");
156157
}
157158
}
158159

159160
static class AlwaysFailingAfterTestMethodTestExecutionListener implements TestExecutionListener {
160161

161162
@Override
162163
public void afterTestMethod(TestContext testContext) {
163-
org.testng.Assert.fail("always failing afterTestMethod()");
164+
fail("always failing afterTestMethod()");
164165
}
165166
}
166167

@@ -210,7 +211,7 @@ public void testNothing() {
210211

211212
@BeforeTransaction
212213
public void beforeTransaction() {
213-
org.testng.Assert.fail("always failing beforeTransaction()");
214+
fail("always failing beforeTransaction()");
214215
}
215216
}
216217

@@ -223,7 +224,7 @@ public void testNothing() {
223224

224225
@AfterTransaction
225226
public void afterTransaction() {
226-
org.testng.Assert.fail("always failing afterTransaction()");
227+
fail("always failing afterTransaction()");
227228
}
228229
}
229230

spring-web/src/test/java/org/springframework/http/codec/json/Jackson2TokenizerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@
4444
import static java.util.Arrays.asList;
4545
import static java.util.Collections.singletonList;
4646
import static org.assertj.core.api.Assertions.assertThat;
47-
import static org.junit.jupiter.api.Assertions.fail;
47+
import static org.assertj.core.api.Assertions.fail;
4848

4949
/**
5050
* @author Arjen Poutsma
@@ -339,7 +339,7 @@ public void useBigDecimalForFloats(boolean useBigDecimalForFloats) {
339339
}
340340
}
341341
catch (IOException ex) {
342-
fail(ex);
342+
fail(ex.getMessage(), ex);
343343
}
344344
})
345345
.verifyComplete();

src/checkstyle/checkstyle.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,22 @@
233233
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
234234
<property name="id" value="junit4Assertions"/>
235235
<property name="maximum" value="0"/>
236-
<property name="format" value="org\.junit\.Assert\.assert"/>
236+
<property name="format" value="org\.junit\.Assert"/>
237237
<property name="message" value="Please use AssertJ assertions."/>
238238
<property name="ignoreComments" value="true"/>
239239
</module>
240240
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
241241
<property name="id" value="junitJupiterAssertions"/>
242242
<property name="maximum" value="0"/>
243-
<property name="format" value="org\.junit\.jupiter\.api\.Assertions\.assert"/>
243+
<property name="format" value="org\.junit\.jupiter\.api\.Assertions"/>
244244
<property name="message" value="Please use AssertJ assertions."/>
245245
<property name="ignoreComments" value="true"/>
246246
</module>
247247
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
248248
<property name="id" value="testNGAssertions"/>
249249
<property name="maximum" value="0"/>
250250
<!-- should cover org.testng.Assert and org.testng.AssertJUnit -->
251-
<property name="format" value="org\.testng\.Assert(JUnit)?\.assert"/>
251+
<property name="format" value="org\.testng\.Assert(JUnit)?"/>
252252
<property name="message" value="Please use AssertJ assertions."/>
253253
<property name="ignoreComments" value="true"/>
254254
</module>

0 commit comments

Comments
 (0)