1

I have the following Rule:

[[junit4:C_TestMethodWithoutAssertion]]
.All Unit Tests must either use a expected Exception or call an Assert Method.
[source,cypher,role=constraint,requiresConcepts="junit4:TestClass,junit4:AssertMethod,junit4:TestMethod",severity=blocker]
----
MATCH
  (testType:Type)-[:DECLARES]->(testMethod:Test:Method)
  -[:ANNOTATED_BY]-(annotation:Annotation)-[:OF_TYPE]->(atype:Type)
WHERE
atype.fqn="org.junit.Test"
AND NOT testMethod.abstract
AND NOT (annotation)-[:HAS]->(:Value{name:"expected"})
AND NOT (testMethod)-[:INVOKES*..3]->(:Method:Assert)
RETURN
  testType AS DeclaringType,
  testMethod AS Method
----

if I use it in the neo4j browser, the rule works perfectly. But if I use it for a Report in an adoc file, I get a lot of "FalsePositives". Has anyone an Idea.

LG Chris

idefixcert
  • 302
  • 2
  • 5

2 Answers2

1

The last query does not return results because the abstract part filters too much. Here's a fixed and slightly restructured version:

MATCH (testType:Type)-[:DECLARES]->(testMethod:Test:Method) -[:ANNOTATED_BY]-(annotation:Annotation)-[:OF_TYPE]->(atype:Type) WHERE atype.fqn="org.junit.Test" AND NOT (has(testMethod.abstract) AND testMethod.abstract) AND NOT ( (annotation)-[:HAS]->(:Value{name:"expected"}) OR (testMethod)-[:INVOKES*..3]->(:Method:Assert) ) RETURN testType AS DeclaringType, testMethod AS Method

Dirk Mahler
  • 1,186
  • 1
  • 6
  • 7
0

Ok now I bracket "()" the NOT statements, and so it works:

[[junit4:C_TestMethodWithoutAssertion]]
.All Unit Tests must either use a expected Exception or call an Assert Method.
[source,cypher,role=constraint,requiresConcepts="junit4:TestClass,junit4:AssertMethod,junit4:TestMethod",severity=blocker]
----
MATCH
  (testType:Type)-[:DECLARES]->(testMethod:Test:Method)
  -[:ANNOTATED_BY]-(annotation:Annotation)-[:OF_TYPE]->(atype:Type)
WHERE
atype.fqn="org.junit.Test"
AND NOT (testMethod.abstract)
AND NOT ((annotation)-[:HAS]->(:Value{name:"expected"}))
AND NOT ((testMethod)-[:INVOKES*..3]->(:Method:Assert))
RETURN
  testType AS DeclaringType,
  testMethod AS Method
----
idefixcert
  • 302
  • 2
  • 5