Skip to content

Commit

Permalink
Refactor PmdValidatorTest#understandsMethodReferences test
Browse files Browse the repository at this point in the history
  • Loading branch information
k3p7i3 committed Jan 21, 2024
1 parent 95a1097 commit 6410361
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
29 changes: 6 additions & 23 deletions qulice-pmd/src/test/java/com/qulice/pmd/PmdValidatorTest.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String>().forEach(Other::other);",
" }",
" private static void other(String some) {",
" // body",
" }",
"}"
Matchers.is(true),
Matchers.not(
Matchers.containsString("(UnusedPrivateMethod)")
)
);
final Collection<Violation> violations = new PmdValidator(env).validate(
Collections.singletonList(new File(env.basedir(), file))
);
MatcherAssert.assertThat(
violations,
Matchers.not(Matchers.<Violation>empty())
);
).validate();
}

/**
Expand Down
@@ -0,0 +1,14 @@
package foo;

import java.util.ArrayList;

public final class UnderstandsMethodReferences {
public void test() {
new ArrayList<String>().forEach(
UnderstandsMethodReferences::other
);
}
private static void other() {
// body
}
}

1 comment on commit 6410361

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 6410361 Feb 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 1129-a60b2495 disappeared from qulice-pmd/src/test/java/com/qulice/pmd/PmdValidatorTest.java), that's why I closed #1193. Please, remember that the puzzle was not necessarily removed in this particular commit. Maybe it happened earlier, but we discovered this fact only now.

Please sign in to comment.