From 6410361c34d2ae49e376021db9672c2d1302fc99 Mon Sep 17 00:00:00 2001 From: Polina Kopyrina Date: Sun, 21 Jan 2024 21:57:28 +0300 Subject: [PATCH] Refactor PmdValidatorTest#understandsMethodReferences test --- .../java/com/qulice/pmd/PmdValidatorTest.java | 29 ++++--------------- .../pmd/UnderstandsMethodReferences.java | 14 +++++++++ 2 files changed, 20 insertions(+), 23 deletions(-) create mode 100644 qulice-pmd/src/test/resources/com/qulice/pmd/UnderstandsMethodReferences.java diff --git a/qulice-pmd/src/test/java/com/qulice/pmd/PmdValidatorTest.java b/qulice-pmd/src/test/java/com/qulice/pmd/PmdValidatorTest.java index f7fe0e85d..b323620f5 100644 --- a/qulice-pmd/src/test/java/com/qulice/pmd/PmdValidatorTest.java +++ b/qulice-pmd/src/test/java/com/qulice/pmd/PmdValidatorTest.java @@ -36,7 +36,6 @@ import com.qulice.spi.Environment; import com.qulice.spi.Violation; import java.io.File; -import java.util.Collection; import java.util.Collections; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -127,34 +126,18 @@ public void findsProblemsInJavaFiles() throws Exception { /** * PmdValidator can understand method references. - * @todo #1129 Replace not+empty() with more precise containsInAnyOrder * @throws Exception If something wrong happens inside. */ @Test - @SuppressWarnings("PMD.AvoidDuplicateLiterals") public void understandsMethodReferences() throws Exception { - final String file = "src/main/java/Other.java"; - final Environment env = new Environment.Mock().withFile( + final String file = "UnderstandsMethodReferences.java"; + new PmdAssert( file, - Joiner.on('\n').join( - "import java.util.ArrayList;", - "class Other {", - " public static void test() {", - " new ArrayList().forEach(Other::other);", - " }", - " private static void other(String some) {", - " // body", - " }", - "}" + Matchers.is(true), + Matchers.not( + Matchers.containsString("(UnusedPrivateMethod)") ) - ); - final Collection violations = new PmdValidator(env).validate( - Collections.singletonList(new File(env.basedir(), file)) - ); - MatcherAssert.assertThat( - violations, - Matchers.not(Matchers.empty()) - ); + ).validate(); } /** diff --git a/qulice-pmd/src/test/resources/com/qulice/pmd/UnderstandsMethodReferences.java b/qulice-pmd/src/test/resources/com/qulice/pmd/UnderstandsMethodReferences.java new file mode 100644 index 000000000..bc2b2a695 --- /dev/null +++ b/qulice-pmd/src/test/resources/com/qulice/pmd/UnderstandsMethodReferences.java @@ -0,0 +1,14 @@ +package foo; + +import java.util.ArrayList; + +public final class UnderstandsMethodReferences { + public void test() { + new ArrayList().forEach( + UnderstandsMethodReferences::other + ); + } + private static void other() { + // body + } +} \ No newline at end of file