Add tests
This commit is contained in:
4 files changed
+45
-10
No files matched your search
+5
-5
@@ -34,11 +34,11 @@ public class JUnitTestsShouldIncludeAssertRule extends AbstractJavaRulechainRule
|
||||
ASTBlock body = method.getBody();
|
||||
Set<String> extraAsserts = getProperty(EXTRA_ASSERT_METHOD_NAMES);
|
||||
if (body != null
|
||||
&& TestFrameworksUtil.isTestMethod(method)
|
||||
&& !TestFrameworksUtil.isExpectAnnotated(method)
|
||||
&& body.descendants(ASTMethodCall.class)
|
||||
.none(call -> TestFrameworksUtil.isProbableAssertCall(call)
|
||||
|| extraAsserts.contains(call.getMethodName()))) {
|
||||
&& TestFrameworksUtil.isTestMethod(method)
|
||||
&& !TestFrameworksUtil.isExpectAnnotated(method)
|
||||
&& body.descendants(ASTMethodCall.class)
|
||||
.none(call -> TestFrameworksUtil.isProbableAssertCall(call)
|
||||
|| extraAsserts.contains(call.getMethodName()))) {
|
||||
asCtx(data).addViolation(method);
|
||||
}
|
||||
return data;
|
||||
|
||||
+5
-5
@@ -174,11 +174,11 @@ public final class TestFrameworksUtil {
|
||||
public static boolean isProbableAssertCall(ASTMethodCall call) {
|
||||
String name = call.getMethodName();
|
||||
return name.startsWith("assert") && !isSoftAssert(call)
|
||||
|| name.startsWith("check")
|
||||
|| name.startsWith("verify")
|
||||
|| "fail".equals(name)
|
||||
|| "failWith".equals(name)
|
||||
|| isExpectExceptionCall(call);
|
||||
|| name.startsWith("check")
|
||||
|| name.startsWith("verify")
|
||||
|| "fail".equals(name)
|
||||
|| "failWith".equals(name)
|
||||
|| isExpectExceptionCall(call);
|
||||
}
|
||||
|
||||
private static boolean isSoftAssert(ASTMethodCall call) {
|
||||
|
||||
+19
@@ -272,4 +272,23 @@ public class MyTestCase {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>Extra properties</description>
|
||||
<rule-property name="extraAssertMethodNames">customAssertion</rule-property>
|
||||
<expected-problems>1</expected-problems>
|
||||
<code><![CDATA[
|
||||
import org.junit.jupiter.api.Test;
|
||||
public class A {
|
||||
@Test
|
||||
void test() {
|
||||
customAssertion("aueoau");
|
||||
customAssertion("aueoau");
|
||||
customAssertion("aueoau");
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
|
||||
</test-data>
|
||||
+16
@@ -773,4 +773,20 @@ public class CustomAssertTests {
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
<test-code>
|
||||
<description>Extra properties</description>
|
||||
<rule-property name="extraAssertMethodNames">customAssertion</rule-property>
|
||||
<expected-problems>0</expected-problems>
|
||||
<code><![CDATA[
|
||||
import org.junit.jupiter.api.Test;
|
||||
public class A {
|
||||
@Test
|
||||
void test() {
|
||||
customAssertion("aueoau");
|
||||
}
|
||||
}
|
||||
]]></code>
|
||||
</test-code>
|
||||
|
||||
</test-data>
|
||||
Reference in new issue
Block a user