Skip to content

Commit e22f7cb

Browse files
committed
Moved testing-plugin from jQA core
1 parent d0ec5b6 commit e22f7cb

File tree

11 files changed

+637
-0
lines changed

11 files changed

+637
-0
lines changed

pom.xml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,47 @@
3535
</developer>
3636
</developers>
3737

38+
<properties>
39+
<camunda-bpm-assert.version>7.23.0</camunda-bpm-assert.version>
40+
</properties>
41+
42+
43+
<build>
44+
<plugins>
45+
<plugin>
46+
<groupId>org.apache.maven.plugins</groupId>
47+
<artifactId>maven-dependency-plugin</artifactId>
48+
<executions>
49+
<execution>
50+
<id>unpack-asciidoc-stylesheets</id>
51+
</execution>
52+
</executions>
53+
</plugin>
54+
<plugin>
55+
<groupId>org.codehaus.mojo</groupId>
56+
<artifactId>xml-maven-plugin</artifactId>
57+
<executions>
58+
<execution>
59+
<id>transform-xml2asciidoc</id>
60+
</execution>
61+
</executions>
62+
</plugin>
63+
<plugin>
64+
<groupId>org.apache.maven.plugins</groupId>
65+
<artifactId>maven-assembly-plugin</artifactId>
66+
<executions>
67+
<execution>
68+
<id>attach-asciidoc</id>
69+
</execution>
70+
</executions>
71+
</plugin>
72+
<plugin>
73+
<groupId>org.cyclonedx</groupId>
74+
<artifactId>cyclonedx-maven-plugin</artifactId>
75+
</plugin>
76+
</plugins>
77+
</build>
78+
3879
<scm>
3980
<connection>scm:git:https://github.com/jqassistant-plugin/jqassistant-java-testing-plugin.git</connection>
4081
<developerConnection>scm:git:https://github.com/jqassistant-plugin/jqassistant-java-testing-plugin.git
@@ -43,6 +84,76 @@
4384
<tag>HEAD</tag>
4485
</scm>
4586

87+
88+
<dependencyManagement>
89+
<dependencies>
90+
<dependency>
91+
<groupId>org.camunda.bpm</groupId>
92+
<artifactId>camunda-bpm-assert</artifactId>
93+
<version>${camunda-bpm-assert.version}</version>
94+
<scope>test</scope>
95+
</dependency>
96+
<dependency>
97+
<groupId>org.camunda.bpm</groupId>
98+
<artifactId>camunda-engine</artifactId>
99+
<version>${camunda-bpm-assert.version}</version>
100+
<scope>test</scope>
101+
</dependency>
102+
</dependencies>
103+
</dependencyManagement>
104+
46105
<dependencies>
106+
<dependency>
107+
<groupId>com.buschmais.jqassistant.core</groupId>
108+
<artifactId>test</artifactId>
109+
<scope>test</scope>
110+
</dependency>
111+
<dependency>
112+
<groupId>com.buschmais.jqassistant.plugin</groupId>
113+
<artifactId>common</artifactId>
114+
<type>test-jar</type>
115+
<scope>test</scope>
116+
</dependency>
117+
<dependency>
118+
<groupId>com.buschmais.jqassistant.plugin</groupId>
119+
<artifactId>java</artifactId>
120+
<scope>test</scope>
121+
</dependency>
122+
<dependency>
123+
<groupId>com.buschmais.jqassistant.plugin</groupId>
124+
<artifactId>java</artifactId>
125+
<type>test-jar</type>
126+
<scope>test</scope>
127+
</dependency>
128+
<dependency>
129+
<groupId>org.assertj</groupId>
130+
<artifactId>assertj-core</artifactId>
131+
<scope>test</scope>
132+
</dependency>
133+
<dependency>
134+
<groupId>org.xmlunit</groupId>
135+
<artifactId>xmlunit-assertj</artifactId>
136+
<scope>test</scope>
137+
</dependency>
138+
<dependency>
139+
<groupId>org.junit.jupiter</groupId>
140+
<artifactId>junit-jupiter-engine</artifactId>
141+
<scope>test</scope>
142+
</dependency>
143+
<dependency>
144+
<groupId>org.mockito</groupId>
145+
<artifactId>mockito-junit-jupiter</artifactId>
146+
<scope>test</scope>
147+
</dependency>
148+
<dependency>
149+
<groupId>org.camunda.bpm</groupId>
150+
<artifactId>camunda-bpm-assert</artifactId>
151+
<scope>test</scope>
152+
</dependency>
153+
<dependency>
154+
<groupId>org.camunda.bpm</groupId>
155+
<artifactId>camunda-engine</artifactId>
156+
<scope>test</scope>
157+
</dependency>
47158
</dependencies>
48159
</project>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<jqassistant-plugin xmlns="http://schema.jqassistant.org/plugin/v2.4"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://schema.jqassistant.org/plugin/v2.4 https://schema.jqassistant.org/plugin/jqassistant-plugin-v2.4.xsd"
4+
id="jqa.plugin.java.testing"
5+
name="jQAssistant Java Testing Plugin"
6+
version="${project.version}">
7+
<description>jQAssistant rules providing concepts to identify framework-specific assertions</description>
8+
<rules>
9+
<resource>assertj.xml</resource>
10+
<resource>xmlunit-assertj.xml</resource>
11+
<resource>mockito.xml</resource>
12+
<resource>camunda-bpmn.xml</resource>
13+
</rules>
14+
</jqassistant-plugin>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<jqassistant-rules xmlns="http://schema.jqassistant.org/rule/v2.2"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://schema.jqassistant.org/rule/v2.2 https://jqassistant.github.io/jqassistant/current/schema/jqassistant-rule-v2.2.xsd">
4+
5+
<concept id="assertj:AssertMethod">
6+
<providesConcept refId="java:AssertMethod"/>
7+
<description>
8+
Sets labels :Assert and :AssertJ for AssertJ assert methods.
9+
</description>
10+
<cypher><![CDATA[
11+
MATCH
12+
(assertType:Type)-[:DECLARES]->(assertMethod)
13+
WHERE
14+
assertType.fqn =~ 'org\\.assertj\\.core\\.api\\..*Assertions.*'
15+
AND assertMethod.signature =~ '.* assert.*'
16+
SET
17+
assertMethod:AssertJ:Assert
18+
RETURN
19+
assertMethod
20+
]]></cypher>
21+
</concept>
22+
23+
</jqassistant-rules>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<jqassistant-rules xmlns="http://schema.jqassistant.org/rule/v2.2"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://schema.jqassistant.org/rule/v2.2 https://jqassistant.github.io/jqassistant/current/schema/jqassistant-rule-v2.2.xsd">
4+
5+
<concept id="camunda-bpmn:AssertMethod">
6+
<providesConcept refId="java:AssertMethod"/>
7+
<description>
8+
Sets labels :Assert and :Camunda for Camunda BPMN assert methods.
9+
</description>
10+
<cypher><![CDATA[
11+
MATCH
12+
(assertType:Type)-[:DECLARES]->(assertMethod)
13+
WHERE
14+
assertType.fqn = 'org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests'
15+
AND assertMethod.signature =~ '.* assert.*'
16+
SET
17+
assertMethod:Camunda:Assert
18+
RETURN
19+
assertMethod
20+
]]></cypher>
21+
</concept>
22+
23+
</jqassistant-rules>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<jqassistant-rules xmlns="http://schema.jqassistant.org/rule/v2.2"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://schema.jqassistant.org/rule/v2.2 https://jqassistant.github.io/jqassistant/current/schema/jqassistant-rule-v2.2.xsd">
4+
5+
<concept id="mockito:VerifyMethod">
6+
<providesConcept refId="java:AssertMethod"/>
7+
<description>
8+
Sets labels :Assert and :Mockito for Mockito verify methods.
9+
</description>
10+
<cypher><![CDATA[
11+
MATCH
12+
(assertType:Java:Type)-[:DECLARES]->(assertMethod:Java:Method)
13+
WHERE
14+
assertType.fqn = 'org.mockito.Mockito'
15+
and assertMethod.signature =~ '.* verify.*'
16+
SET
17+
assertMethod:Mockito:Assert
18+
RETURN
19+
assertMethod
20+
]]></cypher>
21+
</concept>
22+
23+
<concept id="mockito:BddThenShouldMethod">
24+
<providesConcept refId="java:AssertMethod"/>
25+
<description>
26+
Sets labels :Assert and :Mockito for BDDMockito then-should methods.
27+
</description>
28+
<cypher><![CDATA[
29+
MATCH
30+
(type:Java:Type)-[:IMPLEMENTS|EXTENDS*0..]->(bddMockitoThenType:Java:Type),
31+
(type)-[:DECLARES]->(assertMethod:Java:Method)
32+
WHERE
33+
bddMockitoThenType.fqn = 'org.mockito.BDDMockito$Then'
34+
and assertMethod.signature =~ '.* should.*'
35+
SET
36+
assertMethod:Mockito:Assert
37+
RETURN
38+
assertMethod
39+
]]></cypher>
40+
</concept>
41+
42+
</jqassistant-rules>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<jqassistant-rules xmlns="http://schema.jqassistant.org/rule/v2.2"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://schema.jqassistant.org/rule/v2.2 https://jqassistant.github.io/jqassistant/current/schema/jqassistant-rule-v2.2.xsd">
4+
5+
<concept id="xmlunit-assertj:AssertMethod">
6+
<providesConcept refId="java:AssertMethod"/>
7+
<description>
8+
Sets labels :Assert and :AssertJ for xmlunit-assertj assert methods.
9+
</description>
10+
<cypher><![CDATA[
11+
MATCH
12+
(assertType:Type)-[:DECLARES]->(assertMethod)
13+
WHERE
14+
assertType.fqn =~ 'org\\.xmlunit\\.assertj\\..*Assert.*'
15+
AND assertMethod.signature =~ '.* assert.*'
16+
SET
17+
assertMethod:AssertJ:Assert
18+
RETURN
19+
assertMethod
20+
]]></cypher>
21+
</concept>
22+
23+
</jqassistant-rules>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.jqassistant.plugin.java_testing.concept;
2+
3+
import org.assertj.core.api.Assertions;
4+
import org.camunda.bpm.engine.repository.ProcessDefinition;
5+
import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests;
6+
import org.mockito.BDDMockito;
7+
import org.xmlunit.assertj.XmlAssert;
8+
9+
import static org.mockito.ArgumentMatchers.any;
10+
import static org.mockito.Mockito.mock;
11+
import static org.mockito.Mockito.verify;
12+
13+
/**
14+
* Example class used by integration tests.
15+
*/
16+
public class AssertExample {
17+
18+
void assertjAssertExampleMethod() {
19+
Assertions.assertThat(true).isTrue();
20+
}
21+
22+
void xmlAssertExampleMethod() {
23+
XmlAssert.assertThat("<nop/>").and("<nop />").normalizeWhitespace().areSimilar();
24+
}
25+
26+
27+
void mockitoVerifyExampleMethod() {
28+
verify(mock(Object.class).equals(any(Object.class)));
29+
}
30+
31+
void bddMockitoThenShouldExampleMethod() {
32+
BDDMockito.then(mock(Object.class)).shouldHaveNoInteractions();
33+
}
34+
35+
void camundaBpmnAssertExampleMethod() {
36+
ProcessDefinition processDefinition = mock(ProcessDefinition.class);
37+
BpmnAwareTests.assertThat(processDefinition).hasActiveInstances(0);
38+
}
39+
40+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package org.jqassistant.plugin.java_testing.concept;
2+
3+
import java.util.List;
4+
import java.util.stream.Collectors;
5+
6+
import com.buschmais.jqassistant.core.report.api.model.Column;
7+
import com.buschmais.jqassistant.core.report.api.model.Result;
8+
import com.buschmais.jqassistant.core.report.api.model.Row;
9+
import com.buschmais.jqassistant.core.rule.api.model.Concept;
10+
import com.buschmais.jqassistant.plugin.java.api.model.MethodDescriptor;
11+
import com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor;
12+
import com.buschmais.jqassistant.plugin.java.test.AbstractJavaPluginIT;
13+
14+
import org.assertj.core.api.Assertions;
15+
import org.junit.jupiter.api.Test;
16+
17+
import static com.buschmais.jqassistant.core.report.api.model.Result.Status.SUCCESS;
18+
import static com.buschmais.jqassistant.plugin.java.test.assertj.MethodDescriptorCondition.methodDescriptor;
19+
import static com.buschmais.jqassistant.plugin.java.test.assertj.TypeDescriptorCondition.typeDescriptor;
20+
import static org.assertj.core.api.Assertions.assertThat;
21+
import static org.assertj.core.api.InstanceOfAssertFactories.type;
22+
23+
class AssertJIT extends AbstractJavaPluginIT {
24+
25+
@Test
26+
void assertjAssertMethod() throws Exception {
27+
scanClasses(AssertExample.class);
28+
29+
final Result<Concept> conceptResult = applyConcept("assertj:AssertMethod");
30+
assertThat(conceptResult.getStatus()).isEqualTo(SUCCESS);
31+
32+
store.beginTransaction();
33+
34+
assertThat(conceptResult.getRows().size()).isEqualTo(1);
35+
assertThat(conceptResult.getRows()
36+
.get(0)
37+
.getColumns()
38+
.get("assertMethod")
39+
.getValue()).asInstanceOf(type(MethodDescriptor.class))
40+
.is(methodDescriptor(Assertions.class, "assertThat", boolean.class));
41+
42+
verifyResultGraph();
43+
44+
store.commitTransaction();
45+
}
46+
47+
@Test
48+
void providedConceptAssertMethod() throws Exception {
49+
scanClasses(AssertExample.class);
50+
51+
final Result<Concept> conceptResult = applyConcept("java:AssertMethod");
52+
assertThat(conceptResult.getStatus()).isEqualTo(SUCCESS);
53+
54+
store.beginTransaction();
55+
56+
final List<TypeDescriptor> declaringTypes = conceptResult.getRows().stream()
57+
.map(Row::getColumns)
58+
.map(columns -> columns.get("DeclaringType"))
59+
.map(Column::getValue)
60+
.map(TypeDescriptor.class::cast)
61+
.collect(Collectors.toList());
62+
assertThat(declaringTypes).haveExactly(1, typeDescriptor(Assertions.class));
63+
64+
verifyResultGraph();
65+
66+
store.commitTransaction();
67+
}
68+
69+
// Expects an open transaction
70+
private void verifyResultGraph() throws NoSuchMethodException {
71+
final TestResult methodQueryResult = query(
72+
"MATCH (testMethod:Method)-[:INVOKES]->(assertMethod:Method) "
73+
+ "WHERE assertMethod:AssertJ:Assert "
74+
+ "RETURN testMethod, assertMethod");
75+
assertThat(methodQueryResult.<MethodDescriptor>getColumn("testMethod"))
76+
.haveExactly(1, methodDescriptor(AssertExample.class, "assertjAssertExampleMethod"));
77+
assertThat(methodQueryResult.<MethodDescriptor>getColumn("assertMethod"))
78+
.haveExactly(1, methodDescriptor(Assertions.class, "assertThat", boolean.class));
79+
}
80+
81+
}

0 commit comments

Comments
 (0)