Skip to content

ReferencesOnly test

Artyom Lobanov edited this page Jul 11, 2017 · 1 revision

Checks that algorithms consider not only call-expressions, but refereces (like ClassA::methodA1) too.

Expected refactorings
Member Move to
ClassA.doSomething1() ClassB
ClassA.doSomething2() ClassB
or
Member Move to
ClassB.mainF() ClassA
package referencesOnly;

public class ClassA {
    static Object doSomething1(Object o) {
        return "result";
    }

    static Object doSomething2(Object o) {
        return "result";
    }
}
package referencesOnly;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

public class ClassB {
    public void mainF() {
        List<Object> list = new ArrayList<>().stream()
                .map(ClassA::doSomething1)
                .map(ClassA::doSomething1)
                .map(ClassA::doSomething1)
                .map(ClassA::doSomething1)
                .collect(Collectors.toList());
        Function<Object, Object> myFunction = ClassA::doSomething2;
        myFunction = ClassA::doSomething2;
        myFunction = ClassA::doSomething2;
        myFunction = ClassA::doSomething2;
    }

    static void foo() {}
}