Search in sources :

Example 1 with MethodDescriptor

use of com.buschmais.jqassistant.plugin.java.api.model.MethodDescriptor in project jqa-java-plugin by buschmais.

the class AnonymousInnerClassIT method assertOuterClassContainsInnerClass.

/**
     * Asserts that the outer class can be fetched and contains a relation to
     * the inner class.
     */
private void assertOuterClassContainsInnerClass() throws NoSuchMethodException {
    store.beginTransaction();
    TestResult testResult = query("MATCH (outerClass:Type)-[:DECLARES]->(innerClass:Type)<-[:DECLARES]-(method:Method)<-[:DECLARES]-(outerClass) RETURN outerClass, innerClass, method");
    assertThat(testResult.getRows().size(), equalTo(1));
    Map<String, Object> row = testResult.getRows().get(0);
    TypeDescriptor outerClass = (TypeDescriptor) row.get("outerClass");
    assertThat(outerClass, typeDescriptor(AnonymousInnerClass.class));
    TypeDescriptor innerClass = (TypeDescriptor) row.get("innerClass");
    assertThat(innerClass, typeDescriptor(INNERCLASS_NAME));
    MethodDescriptor method = (MethodDescriptor) row.get("method");
    assertThat(method, methodDescriptor(AnonymousInnerClass.class, "iterator"));
    store.commitTransaction();
}
Also used : TypeDescriptor(com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor) AnonymousInnerClass(com.buschmais.jqassistant.plugin.java.test.set.scanner.innerclass.AnonymousInnerClass) MethodDescriptor(com.buschmais.jqassistant.plugin.java.api.model.MethodDescriptor)

Example 2 with MethodDescriptor

use of com.buschmais.jqassistant.plugin.java.api.model.MethodDescriptor in project jqa-java-plugin by buschmais.

the class CyclomaticComplexityIT method cyclomaticComplexity.

@Test
public void cyclomaticComplexity() throws IOException {
    Map<String, Integer> expectedComplexities = new HashMap<>();
    expectedComplexities.put("<init>", valueOf(1));
    expectedComplexities.put("ifStatement", valueOf(2));
    expectedComplexities.put("caseStatement", valueOf(3));
    scanClasses(CyclomaticComplexityType.class);
    store.beginTransaction();
    List<MethodDescriptor> methods = query("match (:Class)-[:DECLARES]->(m:Method) return m").getColumn("m");
    assertThat(methods.size(), equalTo(3));
    for (MethodDescriptor methodDescriptor : methods) {
        String name = methodDescriptor.getName();
        int cyclomaticComplexity = methodDescriptor.getCyclomaticComplexity();
        Integer expectedComplexity = expectedComplexities.get(name);
        assertThat(expectedComplexity, notNullValue());
        assertThat(cyclomaticComplexity, equalTo(expectedComplexity));
    }
    store.commitTransaction();
}
Also used : HashMap(java.util.HashMap) MethodDescriptor(com.buschmais.jqassistant.plugin.java.api.model.MethodDescriptor) Test(org.junit.Test)

Example 3 with MethodDescriptor

use of com.buschmais.jqassistant.plugin.java.api.model.MethodDescriptor in project jqa-java-plugin by buschmais.

the class PojoIT method lineNumbers.

@Test
public void lineNumbers() throws IOException {
    scanClasses(Pojo.class);
    store.beginTransaction();
    List<int[]> lines = query("MATCH (:Method{name:'hashCode'})-[i:INVOKES]->() return i.lineNumber as lines").getColumn("lines");
    assertThat(lines.size(), equalTo(1));
    lines = query("MATCH (:Method{name:'getStringValue'})-[i:READS]->() return i.lineNumber as lines").getColumn("lines");
    assertThat(lines.size(), equalTo(1));
    lines = query("MATCH (:Method{name:'setStringValue'})-[i:WRITES]->() return i.lineNumber as lines").getColumn("lines");
    assertThat(lines.size(), equalTo(1));
    List<MethodDescriptor> hashCodeList = query("MATCH (hashCode:Method{name:'hashCode'}) return hashCode ").getColumn("hashCode");
    assertThat(hashCodeList.size(), equalTo(1));
    MethodDescriptor hashCode = hashCodeList.get(0);
    assertThat(hashCode.getFirstLineNumber(), notNullValue());
    assertThat(hashCode.getLastLineNumber(), notNullValue());
    assertThat(hashCode.getLastLineNumber(), greaterThan(hashCode.getFirstLineNumber()));
    List<MethodDescriptor> equalsList = query("MATCH (equals:Method{name:'equals'}) return equals ").getColumn("equals");
    assertThat(equalsList.size(), equalTo(1));
    MethodDescriptor equals = equalsList.get(0);
    assertThat(equals.getEffectiveLineCount(), equalTo(5));
    store.commitTransaction();
}
Also used : MethodDescriptor(com.buschmais.jqassistant.plugin.java.api.model.MethodDescriptor) Test(org.junit.Test)

Aggregations

MethodDescriptor (com.buschmais.jqassistant.plugin.java.api.model.MethodDescriptor)3 Test (org.junit.Test)2 TypeDescriptor (com.buschmais.jqassistant.plugin.java.api.model.TypeDescriptor)1 AnonymousInnerClass (com.buschmais.jqassistant.plugin.java.test.set.scanner.innerclass.AnonymousInnerClass)1 HashMap (java.util.HashMap)1