Search in sources :

Example 1 with MethodOrder

use of com.github.sevntu.checkstyle.ordering.MethodOrder 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 MethodOrder

use of com.github.sevntu.checkstyle.ordering.MethodOrder in project methods-distance by sevntu-checkstyle.

the class MethodDefinitionTest method testGetterSetterRecognition.

@Test
public void testGetterSetterRecognition() throws Exception {
    final MethodOrder dc = withDefaultConfigOrdering("InputMethodDefinition1.java");
    for (final int index : new int[] { 0, 1, 2, 3, 4 }) {
        final Method method = dc.getMethodByInitialIndex(index);
        assertTrue(method.isGetter());
        assertFalse(method.isSetter());
    }
    for (final int index : new int[] { 7 }) {
        final Method method = dc.getMethodByInitialIndex(index);
        assertFalse(method.isGetter());
        assertTrue(method.isSetter());
    }
    for (final int index : new int[] { 5, 6, 8, 9, 10, 11 }) {
        final Method method = dc.getMethodByInitialIndex(index);
        assertFalse(method.isGetter());
        assertFalse(method.isSetter());
    }
}
Also used : MethodOrder(com.github.sevntu.checkstyle.ordering.MethodOrder) Method(com.github.sevntu.checkstyle.ordering.Method) Test(org.junit.Test)

Example 3 with MethodOrder

use of com.github.sevntu.checkstyle.ordering.MethodOrder in project methods-distance by sevntu-checkstyle.

the class MethodOrderReorderTest method testReordering.

@Test
public void testReordering() throws Exception {
    final int screenLinesCount = 5;
    final MethodOrder first = withDefaultConfigOrdering("InputOrderingReordering1.java");
    final Method b = first.getMethodByInitialIndex(3);
    final Method c = first.getMethodByInitialIndex(6);
    final Method d3 = first.getMethodByInitialIndex(9);
    final Method e = first.getMethodByInitialIndex(13);
    final Method f = first.getMethodByInitialIndex(15);
    final Method h = first.getMethodByInitialIndex(17);
    final MethodOrder firstStep1 = first.moveMethodBy(b, -3);
    final MethodOrder firstStep2 = firstStep1.moveMethodBy(c, -1);
    final MethodOrder firstStep3 = firstStep2.moveMethodBy(d3, 2);
    final MethodOrder firstStep4 = firstStep3.moveMethodBy(e, 1);
    final MethodOrder firstStep5 = firstStep4.moveMethodBy(f, 1);
    final MethodOrder firstLikeSecond = firstStep5.moveMethodBy(h, 1);
    final MethodOrder second = withDefaultConfigOrdering("InputOrderingReordering2.java");
    compare(second, firstLikeSecond, screenLinesCount);
}
Also used : MethodOrder(com.github.sevntu.checkstyle.ordering.MethodOrder) Method(com.github.sevntu.checkstyle.ordering.Method) Test(org.junit.Test)

Example 4 with MethodOrder

use of com.github.sevntu.checkstyle.ordering.MethodOrder in project methods-distance by sevntu-checkstyle.

the class MethodOrderTest method testOverloadSplit1.

@Test
public void testOverloadSplit1() throws Exception {
    final MethodOrder ds = withDefaultConfigOrdering("InputDependenciesOverloadSplit1.java");
    assertEquals(5, ds.getOverloadGroupsSplitCases());
}
Also used : MethodOrder(com.github.sevntu.checkstyle.ordering.MethodOrder) Test(org.junit.Test)

Example 5 with MethodOrder

use of com.github.sevntu.checkstyle.ordering.MethodOrder in project methods-distance by sevntu-checkstyle.

the class MethodOrderTest method testOverrideSplit3.

@Test
public void testOverrideSplit3() throws Exception {
    final MethodOrder ds = withDefaultConfigOrdering("InputDependenciesOverrideSplit3.java");
    assertEquals(0, ds.getOverrideGroupSplitCases());
}
Also used : MethodOrder(com.github.sevntu.checkstyle.ordering.MethodOrder) Test(org.junit.Test)

Aggregations

MethodOrder (com.github.sevntu.checkstyle.ordering.MethodOrder)23 Test (org.junit.Test)15 Method (com.github.sevntu.checkstyle.ordering.Method)10 ArrayList (java.util.ArrayList)4 Dependencies (com.github.sevntu.checkstyle.domain.Dependencies)3 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)3 List (java.util.List)3 Map (java.util.Map)3 DependencyInformationConsumer (com.github.sevntu.checkstyle.module.DependencyInformationConsumer)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 DependencyInformationConsumerInjector (com.github.sevntu.checkstyle.common.DependencyInformationConsumerInjector)1 MethodCallDependencyCheckInvoker (com.github.sevntu.checkstyle.common.MethodCallDependencyCheckInvoker)1 BaseCheckTestSupport (com.github.sevntu.checkstyle.domain.BaseCheckTestSupport)1 ExpectedDependencies (com.github.sevntu.checkstyle.domain.ExpectedDependencies)1 AttributeHolder (com.github.sevntu.checkstyle.dot.domain.AttributeHolder)1 Cluster (com.github.sevntu.checkstyle.dot.domain.Cluster)1 Colors (com.github.sevntu.checkstyle.dot.domain.Colors)1 Comment (com.github.sevntu.checkstyle.dot.domain.Comment)1 Edge (com.github.sevntu.checkstyle.dot.domain.Edge)1