Skip to content

Commit 2909060

Browse files
committed
Polish "Broaden Checkstyle rule for AssertJ assertion enforcement"
See gh-392
1 parent a88d56d commit 2909060

File tree

6 files changed

+80
-2
lines changed

6 files changed

+80
-2
lines changed

Diff for: spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
</module>
129129
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
130130
<property name="maximum" value="0"/>
131-
<property name="format" value="org\.junit\.(Assert|jupiter\.api\.Assertions)\.assert" />
131+
<property name="format" value="org\.junit\.(Assert|jupiter\.api\.Assertions)" />
132132
<property name="message"
133133
value="Please use AssertJ imports." />
134134
<property name="ignoreComments" value="true" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
+Please use AssertJ imports.
2+
+3 errors
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
+Please use AssertJ imports.
2+
+3 errors
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2017-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import org.junit.Assert;
18+
import org.junit.jupiter.api.Test;
19+
20+
import static org.junit.Assert.assertTrue;
21+
import static org.junit.Assert.fail;
22+
23+
/**
24+
* Import of banned org.junit.Assert.
25+
*
26+
* @author Andy Wilkinson
27+
*/
28+
public class AssertJBadAssertImport {
29+
30+
@Test
31+
void useTheImports() {
32+
assertTrue(true);
33+
Assert.assertFalse(false);
34+
fail("oops");
35+
}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2017-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import org.junit.jupiter.api.Assertions;
18+
import org.junit.jupiter.api.Test;
19+
20+
import static org.junit.jupiter.api.Assertions.assertTrue;
21+
import static org.junit.jupiter.api.Assertions.fail;
22+
23+
/**
24+
* Import of banned org.junit.jupiter.api.Assertions.
25+
*
26+
* @author Andy Wilkinson
27+
*/
28+
public class AssertJBadAssertionsImport {
29+
30+
@Test
31+
void useTheImports() {
32+
assertTrue(true);
33+
Assertions.assertFalse(false);
34+
fail("oops");
35+
}
36+
37+
}

Diff for: src/checkstyle/checkstyle.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
</module>
138138
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
139139
<property name="maximum" value="0"/>
140-
<property name="format" value="org\.junit\.Assert|org\.junit\.jupiter\.api\.Assertions" />
140+
<property name="format" value="org\.junit\.Assert\.assert" />
141141
<property name="message"
142142
value="Please use AssertJ imports." />
143143
<property name="ignoreComments" value="true" />

0 commit comments

Comments
 (0)