Skip to content

Commit e2a2e13

Browse files
author
Moritz Pflügner
committed
#12: recognition of org.wildfly.common.Assert assert methods
1 parent 12e15fb commit e2a2e13

File tree

5 files changed

+125
-0
lines changed

5 files changed

+125
-0
lines changed

pom.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,18 @@
104104
<version>3.8.1</version>
105105
<scope>test</scope>
106106
</dependency>
107+
<dependency>
108+
<groupId>org.wildfly.common</groupId>
109+
<artifactId>wildfly-common</artifactId>
110+
<version>2.0.1</version>
111+
<scope>test</scope>
112+
<exclusions>
113+
<exclusion>
114+
<groupId>org.jboss.logging</groupId>
115+
<artifactId>jboss-logging</artifactId>
116+
</exclusion>
117+
</exclusions>
118+
</dependency>
107119
</dependencies>
108120
</dependencyManagement>
109121

@@ -165,5 +177,10 @@
165177
<artifactId>reactor-test</artifactId>
166178
<scope>test</scope>
167179
</dependency>
180+
<dependency>
181+
<groupId>org.wildfly.common</groupId>
182+
<artifactId>wildfly-common</artifactId>
183+
<scope>test</scope>
184+
</dependency>
168185
</dependencies>
169186
</project>

src/main/resources/META-INF/jqassistant-plugin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
<resource>mockito.xml</resource>
1212
<resource>camunda-bpmn.xml</resource>
1313
<resource>projectreactor.xml</resource>
14+
<resource>wildfly-assert.xml</resource>
1415
</rules>
1516
</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="java-testing-wildfly-assert:AssertMethod">
6+
<providesConcept refId="java:AssertMethod"/>
7+
<description>
8+
Sets labels :Assert and :Wildfly for assert methods of the Wildfly Common Library.
9+
</description>
10+
<cypher><![CDATA[
11+
MATCH
12+
(assertType:Type)-[:DECLARES]->(assertMethod)
13+
WHERE
14+
assertType.fqn =~ 'org\\.wildfly\\.common\\.Assert.*'
15+
AND assertMethod.signature =~ '.* assert.*'
16+
SET
17+
assertMethod:Wildfly:Assert
18+
RETURN
19+
assertMethod
20+
]]></cypher>
21+
</concept>
22+
23+
</jqassistant-rules>

src/test/java/org/jqassistant/plugin/java_testing/concept/AssertExample.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests;
66
import org.mockito.BDDMockito;
77
import org.mockito.MockedStatic;
8+
import org.wildfly.common.Assert;
89
import org.xmlunit.assertj.XmlAssert;
910
import reactor.test.StepVerifier;
1011

@@ -54,4 +55,8 @@ void projectReactorAssertExampleMethod() {
5455
StepVerifier.create(null).expectComplete().verify();
5556
}
5657

58+
void wildflyAssertExampleMethod() {
59+
Assert.assertTrue(true);
60+
}
61+
5762
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package org.jqassistant.plugin.java_testing.concept;
2+
3+
import com.buschmais.jqassistant.core.report.api.model.Column;
4+
import com.buschmais.jqassistant.core.report.api.model.Result;
5+
import com.buschmais.jqassistant.core.report.api.model.Row;
6+
import com.buschmais.jqassistant.core.rule.api.model.Concept;
7+
import com.buschmais.jqassistant.plugin.java.api.model.MethodDescriptor;
8+
import com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor;
9+
import com.buschmais.jqassistant.plugin.java.test.AbstractJavaPluginIT;
10+
import org.junit.jupiter.api.Test;
11+
import org.wildfly.common.Assert;
12+
13+
import java.util.List;
14+
import java.util.stream.Collectors;
15+
16+
import static com.buschmais.jqassistant.core.report.api.model.Result.Status.SUCCESS;
17+
import static com.buschmais.jqassistant.plugin.java.test.assertj.MethodDescriptorCondition.methodDescriptor;
18+
import static com.buschmais.jqassistant.plugin.java.test.assertj.TypeDescriptorCondition.typeDescriptor;
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
import static org.assertj.core.api.InstanceOfAssertFactories.type;
21+
22+
public class WildflyAssertIT extends AbstractJavaPluginIT {
23+
24+
@Test
25+
void wildflyAssertMethod() throws Exception {
26+
scanClasses(AssertExample.class);
27+
28+
final Result<Concept> conceptResult = applyConcept("java-testing-wildfly-assert:AssertMethod");
29+
assertThat(conceptResult.getStatus()).isEqualTo(SUCCESS);
30+
31+
store.beginTransaction();
32+
33+
assertThat(conceptResult.getRows().size()).isEqualTo(1);
34+
assertThat(conceptResult.getRows()
35+
.get(0)
36+
.getColumns()
37+
.get("assertMethod")
38+
.getValue()).asInstanceOf(type(MethodDescriptor.class))
39+
.is(methodDescriptor(Assert.class, "assertTrue", boolean.class));
40+
41+
verifyResultGraph();
42+
43+
store.commitTransaction();
44+
}
45+
46+
@Test
47+
void providedConceptAssertMethod() throws Exception {
48+
scanClasses(AssertExample.class);
49+
50+
final Result<Concept> conceptResult = applyConcept("java:AssertMethod");
51+
assertThat(conceptResult.getStatus()).isEqualTo(SUCCESS);
52+
53+
store.beginTransaction();
54+
55+
final List<TypeDescriptor> declaringTypes = conceptResult.getRows().stream()
56+
.map(Row::getColumns)
57+
.map(columns -> columns.get("DeclaringType"))
58+
.map(Column::getValue)
59+
.map(TypeDescriptor.class::cast)
60+
.collect(Collectors.toList());
61+
assertThat(declaringTypes).haveExactly(1, typeDescriptor(Assert.class));
62+
63+
verifyResultGraph();
64+
65+
store.commitTransaction();
66+
}
67+
68+
// Expects an open transaction
69+
private void verifyResultGraph() throws NoSuchMethodException {
70+
final TestResult methodQueryResult = query(
71+
"MATCH (testMethod:Method)-[:INVOKES]->(assertMethod:Method) "
72+
+ "WHERE assertMethod:Wildfly:Assert "
73+
+ "RETURN testMethod, assertMethod");
74+
assertThat(methodQueryResult.<MethodDescriptor>getColumn("testMethod"))
75+
.haveExactly(1, methodDescriptor(AssertExample.class, "wildflyAssertExampleMethod"));
76+
assertThat(methodQueryResult.<MethodDescriptor>getColumn("assertMethod"))
77+
.haveExactly(1, methodDescriptor(Assert.class, "assertTrue", boolean.class));
78+
}
79+
}

0 commit comments

Comments
 (0)