Skip to content

Commit

Permalink
Polish "Broaden Checkstyle rule for AssertJ assertion enforcement"
Browse files Browse the repository at this point in the history
See gh-392
  • Loading branch information
wilkinsona committed Oct 13, 2023
1 parent a88d56d commit 2909060
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
</module>
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
<property name="maximum" value="0"/>
<property name="format" value="org\.junit\.(Assert|jupiter\.api\.Assertions)\.assert" />
<property name="format" value="org\.junit\.(Assert|jupiter\.api\.Assertions)" />
<property name="message"
value="Please use AssertJ imports." />
<property name="ignoreComments" value="true" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
+Please use AssertJ imports.
+3 errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
+Please use AssertJ imports.
+3 errors
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2017-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.junit.Assert;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
* Import of banned org.junit.Assert.
*
* @author Andy Wilkinson
*/
public class AssertJBadAssertImport {

@Test
void useTheImports() {
assertTrue(true);
Assert.assertFalse(false);
fail("oops");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2017-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

/**
* Import of banned org.junit.jupiter.api.Assertions.
*
* @author Andy Wilkinson
*/
public class AssertJBadAssertionsImport {

@Test
void useTheImports() {
assertTrue(true);
Assertions.assertFalse(false);
fail("oops");
}

}
2 changes: 1 addition & 1 deletion src/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
</module>
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
<property name="maximum" value="0"/>
<property name="format" value="org\.junit\.Assert|org\.junit\.jupiter\.api\.Assertions" />
<property name="format" value="org\.junit\.Assert\.assert" />
<property name="message"
value="Please use AssertJ imports." />
<property name="ignoreComments" value="true" />
Expand Down

0 comments on commit 2909060

Please sign in to comment.