META-INF.jqassistant-rules.junit5.xml Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of junit Show documentation
Show all versions of junit Show documentation
Plugin for jQAssistant to be able to scan and to
analyze JUnit related artifacts.
The newest version!
<jqassistant-rules xmlns="http://schema.jqassistant.org/rule/v1.10"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://schema.jqassistant.org/rule/v1.10 http://schema.jqassistant.org/rule/jqassistant-rule-v1.10.xsd">
<group id="junit5:Default">
<includeConstraint refId="junit5:AssertionMustProvideMessage"/>
<includeConstraint refId="junit5:NonJUnit5TestMethod"/>
<includeConstraint refId="junit5:UsageOfJUnit4TestApi"/>
</group>
<concept id="junit5:TestMethod">
<providesConcept refId="java:TestMethod"/>
<description>
Finds all test methods (i.e. annotated with "@org.junit.jupiter.api.Test") and
labels them with "Test" and "Junit5".
</description>
<cypher><![CDATA[
MATCH
(m:Method)-[:ANNOTATED_BY]-()-[:OF_TYPE]->(a:Type)
WHERE
a.fqn="org.junit.jupiter.api.Test"
SET
m:Test:Junit5
RETURN
m AS Test
]]></cypher>
</concept>
<concept id="junit5:RepeatedTestMethod">
<providesConcept refId="java:TestMethod"/>
<description>
Finds all test methods (i.e. annotated with "@org.junit.jupiter.api.RepeatedTest") and
labels them with "Test", "Repeated", and "Junit5".
</description>
<cypher><![CDATA[
MATCH
(m:Method)-[:ANNOTATED_BY]-()-[:OF_TYPE]->(a:Type)
WHERE
a.fqn="org.junit.jupiter.api.RepeatedTest"
SET
m:Repeated:Test:Junit5
RETURN
m AS Test
]]></cypher>
</concept>
<concept id="junit5:ParameterizedTestMethod">
<providesConcept refId="java:TestMethod"/>
<description>
Finds all test methods (i.e. annotated with "@org.junit.jupiter.api.ParameterizedTest") and
labels them with "Test", "Parameterized", and "Junit5".
</description>
<cypher><![CDATA[
MATCH
(m:Method)-[:ANNOTATED_BY]-()-[:OF_TYPE]->(a:Type)
WHERE
a.fqn="org.junit.jupiter.params.ParameterizedTest"
SET
m:Parameterized:Test:Junit5
RETURN
m AS Test
]]></cypher>
</concept>
<concept id="junit5:DisabledTestClassOrMethod">
<description>
Labels all classes or methods annotated with "@org.junit.jupiter.api.Disabled"
with "Junit5" and "Ignore".
</description>
<cypher><![CDATA[
MATCH
(e)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(a:Type)
WHERE
a.fqn="org.junit.jupiter.api.Disabled"
SET
e:Junit5:Disabled
RETURN
e AS IgnoredElement
]]></cypher>
</concept>
<concept id="junit5:BeforeEach">
<description>
Labels all methods annotated by "@org.junit.jupiter.api.BeforeEach"
with "Junit5" and "Before".</description>
<cypher><![CDATA[
MATCH
(c:Type:Class)-[:DECLARES]->(m:Method),
(m:Method)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(a:Type)
WHERE
a.fqn="org.junit.jupiter.api.BeforeEach"
SET
m:Junit5:BeforeEach
RETURN
m AS BeforeMethod, c AS TestClass
]]></cypher>
</concept>
<concept id="junit5:BeforeAll">
<description>
Labels all methods annotated by "@org.junit.jupiter.api.BeforeAll"
with "Junit5" and "BeforeClass".</description>
<cypher><![CDATA[
MATCH
(c:Type:Class)-[:DECLARES]->(m:Method),
(m:Method)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(a:Type)
WHERE
a.fqn="org.junit.jupiter.api.BeforeAll"
SET
m:Junit5:BeforeAll
RETURN
m AS BeforeClassMethod, c AS TestClass
]]></cypher>
</concept>
<concept id="junit5:AfterEach">
<description>
Labels all methods annotated by "@org.junit.jupiter.api.AfterEach"
with "Junit5" and "After".</description>
<cypher><![CDATA[
MATCH
(c:Type:Class)-[:DECLARES]->(m:Method),
(m:Method)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(a:Type)
WHERE
a.fqn="org.junit.jupiter.api.AfterEach"
SET
m:Junit5:AfterEach
RETURN
m AS AfterEachMethod, c AS TestClass
]]></cypher>
</concept>
<concept id="junit5:AfterAll">
<description>
Labels all methods annotated by "@org.junit.jupiter.api.AfterAll"
with "Junit5" and "AfterClass".</description>
<cypher><![CDATA[
MATCH
(c:Type:Class)-[:DECLARES]->(m:Method),
(m:Method)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(a:Type)
WHERE
a.fqn="org.junit.jupiter.api.AfterAll"
SET
m:Junit5:AfterAll
RETURN
m AS AfterClassMethod, c AS TestClass
]]></cypher>
</concept>
<concept id="junit5:TestTemplateMethod">
<providesConcept refId="java:TestMethod"/>
<description>
Labels all methods annotated by "@org.junit.jupiter.api.TestTemplate"
with "Junit5", "Test" and "Template".</description>
<cypher><![CDATA[
MATCH
(c:Type:Class)-[:DECLARES]->(m:Method),
(m:Method)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(a:Type)
WHERE
a.fqn="org.junit.jupiter.api.TestTemplate"
SET
m:Junit5:Test:Template
RETURN
m AS AfterClassMethod, c AS TestClass
]]></cypher>
</concept>
<concept id="junit5:TaggedMethodWithMetaAnnotation">
<requiresConcept refId="junit5:TestMethod"/>
<requiresConcept refId="junit5:RepeatedTestMethod"/>
<requiresConcept refId="junit5:TestTemplateMethod"/>
<requiresConcept refId="junit5:ParameterizedTestMethod"/>
<description>
Labels all methods annotated by an Junit meta annotation
with "Junit5", "Test" and "Tag".</description>
<cypher><![CDATA[
MATCH
(meth:Java:Method:Junit5:Test)-[:ANNOTATED_BY]->(a:Annotation)
-[:OF_TYPE]->(metaAnn:Java:Type:Annotation)
-[:ANNOTATED_BY]->(tagAnn:Java:Annotation)
-[:OF_TYPE]->(tagAnnType:Java:Type { name: 'Tag'})
SET
meth:Tag
RETURN
meth AS TestMethod
UNION
MATCH
(meth:Java:Method:Junit5:Test)
-[:ANNOTATED_BY]->(a:Annotation)
-[:OF_TYPE]->(metaAnn:Annotation)
-[:ANNOTATED_BY]->(tags:Annotation)
-[:OF_TYPE]->(tagsType { fqn: 'org.junit.jupiter.api.Tags' }),
(tags)-[:HAS]->(v:Array:Value)
-[:CONTAINS]->(b:Annotation:Value)
-[:OF_TYPE]->(tag:Type { fqn: 'org.junit.jupiter.api.Tag' })
SET
meth:Tag
RETURN
meth AS TestMethod
]]>
</cypher>
</concept>
<concept id="junit5:TaggedClassWithMetaAnnotation">
<requiresConcept refId="junit5:TestMethod"/>
<requiresConcept refId="junit5:RepeatedTestMethod"/>
<requiresConcept refId="junit5:TestTemplateMethod"/>
<requiresConcept refId="junit5:ParameterizedTestMethod"/>
<description>
Labels all classes annotated by an Junit meta annotation
with "Junit5", and "Tag".</description>
<cypher><![CDATA[
MATCH
(c:Java:Type)-[:ANNOTATED_BY]->(a:Annotation)
-[:OF_TYPE]->(metaAnn:Java:Type:Annotation)
-[:ANNOTATED_BY]->(tagAnn:Java:Annotation)
-[:OF_TYPE]->(tagAnnType:Java:Type { name: 'Tag'})
SET
c:Tag:Junit5
RETURN
c AS TaggedClass
UNION
MATCH
(c:Java:Type)
-[:ANNOTATED_BY]->(a:Annotation)
-[:OF_TYPE]->(metaAnn:Annotation)
-[:ANNOTATED_BY]->(tags:Annotation)
-[:OF_TYPE]->(tagsType { fqn: 'org.junit.jupiter.api.Tags' }),
(tags)-[:HAS]->(v:Array:Value)
-[:CONTAINS]->(b:Annotation:Value)
-[:OF_TYPE]->(tag:Type { fqn: 'org.junit.jupiter.api.Tag' })
SET
c:Tag:Junit5
RETURN
c AS TaggedClass
]]>
</cypher>
</concept>
<concept id="junit5:TaggedMethod">
<requiresConcept refId="junit5:TestMethod"/>
<requiresConcept refId="junit5:RepeatedTestMethod"/>
<requiresConcept refId="junit5:TestTemplateMethod"/>
<requiresConcept refId="junit5:ParameterizedTestMethod"/>
<description>
Labels all methods annotated by "@org.junit.jupiter.api.Tag"
with "Junit5", "Test" and "Tag".</description>
<cypher><![CDATA[
MATCH
(c:Type:Class)-[:DECLARES]->(m:Method),
(m:Method:Junit5:Test)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(a:Type)
WHERE
a.fqn="org.junit.jupiter.api.Tag"
SET
m:Junit5:Test:Tag
RETURN
m AS TestMethod, c AS TestClass
UNION
MATCH
(c:Type:Class)-[:DECLARES]->(m:Method),
(m:Method:Test:Junit5)-[:ANNOTATED_BY]->(a:Annotation)-[:OF_TYPE]->(tags:Type),
(a)-[:HAS]->(v:Array:Value)-[:CONTAINS]->(b:Annotation:Value)-[:OF_TYPE]->(tag:Type)
WHERE
tags.fqn="org.junit.jupiter.api.Tags"
AND tag.fqn="org.junit.jupiter.api.Tag"
SET
m:Junit5:Test:Tag
RETURN
m AS TestMethod, c AS TestClass
]]></cypher>
</concept>
<concept id="junit5:TaggedMethodTags">
<description>Collects all tags of methods annotated with
"@org.junit.jupiter.api.Tag" and "@org.junit.jupiter.api.Test"
and stores them in an array property of the method descriptor.</description>
<cypher><![CDATA[
MATCH
(c:Type:Class)-[:DECLARES]->(m:Method),
(m:Method)-[:ANNOTATED_BY]->(a:Annotation)-[:OF_TYPE]->(tags:Type),
(a)-[:HAS]->(v:Array:Value)-[:CONTAINS]->(b:Annotation:Value)-[:OF_TYPE]->(tag:Type),
(b)-[:HAS]->(tagValue:Value)
WHERE
tags.fqn="org.junit.jupiter.api.Tags"
AND tag.fqn="org.junit.jupiter.api.Tag"
WITH
collect(distinct tagValue.value) AS tagValues, m
SET
m.tags = tagValues
RETURN
m
UNION
MATCH
(c:Type:Class)-[:DECLARES]->(m:Method),
(m:Method)-[:ANNOTATED_BY]->(a:Annotation)-[:OF_TYPE]->(t:Type),
(a:Annotation)-[:HAS]->(v:Value)
WHERE
t.fqn="org.junit.jupiter.api.Tag"
WITH
collect(distinct v.value) as tagValues, m
SET
m.tags = tagValues
RETURN
m
]]></cypher>
</concept>
<concept id="junit5:TaggedClass">
<requiresConcept refId="junit5:TestMethod"/>
<requiresConcept refId="junit5:RepeatedTestMethod"/>
<requiresConcept refId="junit5:TestTemplateMethod"/>
<requiresConcept refId="junit5:ParameterizedTestMethod"/>
<description>
Labels all methods annotated by "@org.junit.jupiter.api.Tag"
with "Junit5", and "Tag".</description>
<cypher><![CDATA[
MATCH
(c:Type:Class)-[:ANNOTATED_BY]->()-[:OF_TYPE]->(a:Type)
WHERE
a.fqn="org.junit.jupiter.api.Tag"
SET
c:Junit5:Tag
RETURN
c AS TestClass
UNION
MATCH
(c:Type:Class)-[:ANNOTATED_BY]->(a:Annotation)-[:OF_TYPE]->(tags:Type),
(a)-[:HAS]->(v:Array:Value)-[:CONTAINS]->(b:Annotation:Value)-[:OF_TYPE]->(tag:Type)
SET
c:Junit5:Tag
RETURN
c AS TestClass
]]></cypher>
</concept>
<concept id="junit5:TaggedClassTags">
<description>
Collects all tags of classes annotated with
"@org.junit.jupiter.api.Tag" and containing test methods (":Test:Method:Junit5")
and stores them in an array property of the class descriptor.</description>
<cypher><![CDATA[
MATCH
(c:Type:Class)-[:ANNOTATED_BY]->(a:Annotation)-[:OF_TYPE]->(tag:Type),
(c:Type:Class)-[:DECLARES]->(m:Method:Junit5:Test),
// (m:Method)-[:ANNOTATED_BY]->(a:Annotation)-[:OF_TYPE]->(tag:Type),
(a)-[:HAS]->(tagValue:Value)
WHERE
tag.fqn="org.junit.jupiter.api.Tag"
WITH
collect(distinct tagValue.value) AS tagValues, c
SET
c.tags = tagValues, c:Test:Junit5
RETURN
c
UNION
MATCH
(c:Type:Class)-[:DECLARES]->(m:Method:Test:Junit5),
(c:Type:Class)-[:ANNOTATED_BY]->(a:Annotation)-[:OF_TYPE]->(tags:Type),
(a)-[:HAS]->(v:Array:Value)-[:CONTAINS]->(b:Annotation:Value)-[:OF_TYPE]->(tag:Type),
(b)-[:HAS]->(tagValue:Value)
WHERE
tags.fqn="org.junit.jupiter.api.Tags"
AND tag.fqn="org.junit.jupiter.api.Tag"
WITH
collect(distinct tagValue.value) AS tagValues, c
SET
c.tags = tagValues, c:Test:Junit5
RETURN
c
]]></cypher>
</concept>
<concept id="junit5:TestClass">
<requiresConcept refId="junit5:TestMethod"/>
<requiresConcept refId="junit5:RepeatedTestMethod"/>
<requiresConcept refId="junit5:TestTemplateMethod"/>
<requiresConcept refId="junit5:ParameterizedTestMethod"/>
<description>Labels all classes containing test methods with "Test" and "Junit5".</description>
<cypher><![CDATA[
MATCH
(c:Type:Class)-[:DECLARES]->(m:Method:Junit5:Test)
SET
c:Test:Junit5
RETURN
c AS TestClass, COLLECT(m) AS TestMethods
]]></cypher>
</concept>
<concept id="junit5:NestedTestClass">
<description>Labels all nested test classes annotated with "@org.junit.jupiter.api.Nested",
independently from the number of tests contained in the method, with
"Junit5" and "Nested".
</description>
<cypher><![CDATA[
MATCH
(c:Type:Class)-[:ANNOTATED_BY]->(a:Annotation)-[:OF_TYPE]->(n:Type)
WHERE
n.fqn = "org.junit.jupiter.api.Nested"
SET
c:Junit5:Nested
RETURN
c
]]></cypher>
</concept>
<concept id="junit5:AssertMethod">
<providesConcept refId="java:AssertMethod"/>
<description>
Labels all assertion methods declared by "org.junit.jupiter.api.Assertions" with "Junit5"
and "Assert".
</description>
<cypher><![CDATA[
MATCH
(assertType:Type)-[:DECLARES]->(assertMethod)
WHERE
assertType.fqn = 'org.junit.jupiter.api.Assertions'
and (
assertMethod.signature CONTAINS ' assert'
or assertMethod.signature CONTAINS ' fail'
)
SET
assertMethod:Junit5:Assert
RETURN
assertMethod
]]></cypher>
</concept>
<constraint id="junit5:AssertionMustProvideMessage">
<requiresConcept refId="java:TestMethod"/>
<requiresConcept refId="junit5:AssertMethod"/>
<description>All assertions must provide a message.</description>
<cypher><![CDATA[
MATCH
(testType:Type)-[:DECLARES]->(testMethod:Test:Method),
(testMethod)-[invocation:INVOKES]->(assertMethod:Junit5:Assert:Method)
WHERE NOT (
assertMethod.signature =~ '.*assert.*\\(.*java.lang.String\\)'
or assertMethod.signature =~ '.*assert.*\\(.*java.util.function.Supplier\\)'
or assertMethod.signature = 'java.lang.Object fail(java.lang.String)'
)
RETURN
invocation AS Invocation,
testType AS DeclaringType,
testMethod AS Method
]]></cypher>
</constraint>
<constraint id="junit5:NonJUnit5TestMethod">
<requiresConcept refId="junit3:TestMethod"/>
<requiresConcept refId="junit4:TestMethod"/>
<description>Only the jUnit 5-test annotation must be used to identify test methods in a jUnit 5-based project.</description>
<cypher><![CDATA[
MATCH
(:Artifact)-[:CONTAINS]->(t:Type)-[:DECLARES]->(m:Test:Method)
WHERE
m:Junit3 OR m:Junit4
RETURN
t AS TestClass,
m AS TestMethod
]]></cypher>
<report primaryColumn="TestMethod"/>
</constraint>
<constraint id="junit5:UsageOfJUnit4TestApi">
<requiresConcept refId="java:TestMethod"/>
<requiresConcept refId="java:AssertMethod"/>
<description>Only the jUnit 5-test api must be used in a jUnit 5-based project.</description>
<cypher><![CDATA[
MATCH
(:Artifact)-[:CONTAINS]->(t:Type)-[:DECLARES]->(m:Test:Method),
(m)-[:INVOKES*..3]->(:Junit4:Assert:Method)
RETURN DISTINCT
t AS TestClass,
m AS TestMethod
]]></cypher>
<report primaryColumn="TestMethod"/>
</constraint>
</jqassistant-rules>
© 2015 - 2025 Weber Informatics LLC | Privacy Policy