Our project uses assert methods from assertj library as well in some of the unit test methods. So the current cypher rule to search for assert method doesn't identify assert methods like below and flags them as violations.
assertThat("x").isEqualTo("Y"); in the unit test methods.
how to modify the script to consider any "assert*" invocations from unit test method.
<cypher><![CDATA[
MATCH
(c:Type:Class)-[:DECLARES]->(m:Method:JunitTestMethod),
(m)-[:INVOKES*..10]->(assert:Method)
WHERE
assert.signature =~ "void assert.*"
OR assert.signature =~ "void fail.*"
OR assert.signature =~ "void verify.*"
SET
m:JunitTestWithAssert
RETURN
c.fqn AS TestClass, m.name AS TestMethodWithAssert
]]></cypher>
Sample Test method :
@Test
public void testAssertWithDiffLibrary() {
String testName = "Hello";
assertThat(testName).isEqualTo("Hello");
}
Note : Tried adding a where clause "OR assert.name =~ ".assert."" but doesn't detect these asserts.