Search in sources :

Example 1 with ExpectedDependencies

use of com.github.sevntu.checkstyle.domain.ExpectedDependencies in project methods-distance by sevntu-checkstyle.

the class MethodCallDependenciesModuleTestSupport method mustBeSame.

private static void mustBeSame(final ExpectedDependencies expected, final MethodOrder actual) {
    for (final String expectedMethod : expected.getMethods()) {
        assertTrue("Method " + expectedMethod + " is not present is actual info", actual.getMethods().stream().anyMatch(md -> expectedMethod.equals(md.getSignature())));
    }
    for (final Method actualMethod : actual.getMethods()) {
        assertTrue("Method " + actualMethod.getSignature() + " is not present in expected info", expected.getMethods().stream().anyMatch(mi -> mi.equals(actualMethod.getSignature())));
    }
    for (final String method : expected.getMethods()) {
        final Method caller = actual.getMethods().stream().filter(m -> m.getSignature().equals(method)).findFirst().get();
        final List<Method> dependencies = actual.getMethodDependenciesInAppearanceOrder(caller);
        final List<ExpectedDependencies.MethodInvocation> invocations = expected.getInvocationsFromMethod(method);
        assertEquals("Actual method dependencies count and count of invocations from method " + method + " does not match", invocations.size(), dependencies.size());
        for (int i = 0; i < invocations.size(); ++i) {
            final Method calledMethod = dependencies.get(i);
            final ExpectedDependencies.MethodInvocation invocationOfMethod = invocations.get(i);
            assertTrue("Method " + calledMethod.getSignature() + " is present as actual " + i + " dependency of " + method + " but should not be!", calledMethod.getSignature().equals(expected.getMethodByIndex(invocationOfMethod.callee)));
        }
    }
}
Also used : DependencyInformationConsumerInjector(com.github.sevntu.checkstyle.common.DependencyInformationConsumerInjector) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Assert.assertTrue(org.junit.Assert.assertTrue) HashMap(java.util.HashMap) ExpectedDependencies(com.github.sevntu.checkstyle.domain.ExpectedDependencies) MethodCallDependencyCheckstyleModule(com.github.sevntu.checkstyle.module.MethodCallDependencyCheckstyleModule) BaseCheckTestSupport(com.github.sevntu.checkstyle.domain.BaseCheckTestSupport) MethodOrder(com.github.sevntu.checkstyle.ordering.MethodOrder) Method(com.github.sevntu.checkstyle.ordering.Method) List(java.util.List) Configuration(com.puppycrawl.tools.checkstyle.api.Configuration) DependencyInformationConsumer(com.github.sevntu.checkstyle.module.DependencyInformationConsumer) Locale(java.util.Locale) Checker(com.puppycrawl.tools.checkstyle.Checker) Map(java.util.Map) DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) Dependencies(com.github.sevntu.checkstyle.domain.Dependencies) Assert.assertEquals(org.junit.Assert.assertEquals) Method(com.github.sevntu.checkstyle.ordering.Method) ExpectedDependencies(com.github.sevntu.checkstyle.domain.ExpectedDependencies)

Example 2 with ExpectedDependencies

use of com.github.sevntu.checkstyle.domain.ExpectedDependencies in project methods-distance by sevntu-checkstyle.

the class MethodCallDependencyCheckstyleModuleTest method testAnonymousClasses.

@Test
public void testAnonymousClasses() throws Exception {
    final DefaultConfiguration dc = createCheckConfig(MethodCallDependencyCheckstyleModule.class);
    final ExpectedDependencies expected = ExpectedDependencies.build().method("method()").method("a()").method("a(String)").method("topLevelMethod()").get();
    verifyInfo(dc, "InputAnonymousClasses.java", expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) ExpectedDependencies(com.github.sevntu.checkstyle.domain.ExpectedDependencies) Test(org.junit.Test)

Example 3 with ExpectedDependencies

use of com.github.sevntu.checkstyle.domain.ExpectedDependencies in project methods-distance by sevntu-checkstyle.

the class MethodCallDependencyCheckstyleModuleTest method testVarargMethodCall.

@Test
public void testVarargMethodCall() throws Exception {
    final DefaultConfiguration dc = createCheckConfig(MethodCallDependencyCheckstyleModule.class);
    final ExpectedDependencies expected = ExpectedDependencies.build().method("c1()").callsTo(3).at(6, 20).method("c2()").callsTo(3).at(10, 20).method("c3()").callsTo(3).at(14, 20).method("varargMethod(Integer...)").get();
    verifyInfo(dc, "InputVarargMethodCall.java", expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) ExpectedDependencies(com.github.sevntu.checkstyle.domain.ExpectedDependencies) Test(org.junit.Test)

Example 4 with ExpectedDependencies

use of com.github.sevntu.checkstyle.domain.ExpectedDependencies in project methods-distance by sevntu-checkstyle.

the class MethodCallDependencyCheckstyleModuleTest method testOverloadedMethods2.

@Test
public void testOverloadedMethods2() throws Exception {
    final DefaultConfiguration dc = createCheckConfig(MethodCallDependencyCheckstyleModule.class);
    final ExpectedDependencies expected = ExpectedDependencies.build().method("b1()").method("b1(String)").method("b1(String,String)").method("b1(String,String,String...)").method("a1()").callsTo(0).at(14, 10).method("a2()").callsTo(1).at(18, 10).method("a3()").callsTo(2).at(22, 10).method("a4()").callsTo(3).at(26, 10).method("c1()").method("c1(String...)").method("d1()").callsTo(9).at(34, 10).get();
    verifyInfo(dc, "InputOverloadedMethods2.java", expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) ExpectedDependencies(com.github.sevntu.checkstyle.domain.ExpectedDependencies) Test(org.junit.Test)

Example 5 with ExpectedDependencies

use of com.github.sevntu.checkstyle.domain.ExpectedDependencies in project methods-distance by sevntu-checkstyle.

the class MethodCallDependencyCheckstyleModuleTest method testAppearanceOrder.

@Test
public void testAppearanceOrder() throws Exception {
    final DefaultConfiguration dc = createCheckConfig(MethodCallDependencyCheckstyleModule.class);
    final ExpectedDependencies expected = ExpectedDependencies.build().method("b1()").method("b2()").method("b3()").method("a()").callsTo(2).at(12, 10).callsTo(1).at(13, 10).callsTo(0).at(15, 10).method("c1(String)").method("c2()").method("d()").callsTo(5).at(24, 13).callsTo(4).at(24, 10).method("e1(String)").method("e2(Integer)").method("e3()").method("f()").callsTo(9).at(34, 16).callsTo(8).at(34, 13).callsTo(7).at(34, 10).get();
    verifyInfo(dc, "InputAppearanceOrder.java", expected);
}
Also used : DefaultConfiguration(com.puppycrawl.tools.checkstyle.DefaultConfiguration) ExpectedDependencies(com.github.sevntu.checkstyle.domain.ExpectedDependencies) Test(org.junit.Test)

Aggregations

ExpectedDependencies (com.github.sevntu.checkstyle.domain.ExpectedDependencies)11 DefaultConfiguration (com.puppycrawl.tools.checkstyle.DefaultConfiguration)11 Test (org.junit.Test)10 DependencyInformationConsumerInjector (com.github.sevntu.checkstyle.common.DependencyInformationConsumerInjector)1 BaseCheckTestSupport (com.github.sevntu.checkstyle.domain.BaseCheckTestSupport)1 Dependencies (com.github.sevntu.checkstyle.domain.Dependencies)1 DependencyInformationConsumer (com.github.sevntu.checkstyle.module.DependencyInformationConsumer)1 MethodCallDependencyCheckstyleModule (com.github.sevntu.checkstyle.module.MethodCallDependencyCheckstyleModule)1 Method (com.github.sevntu.checkstyle.ordering.Method)1 MethodOrder (com.github.sevntu.checkstyle.ordering.MethodOrder)1 Checker (com.puppycrawl.tools.checkstyle.Checker)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertTrue (org.junit.Assert.assertTrue)1