Skip to content

Commit 6410361

Browse files
committed
Refactor PmdValidatorTest#understandsMethodReferences test
1 parent 95a1097 commit 6410361

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

qulice-pmd/src/test/java/com/qulice/pmd/PmdValidatorTest.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import com.qulice.spi.Environment;
3737
import com.qulice.spi.Violation;
3838
import java.io.File;
39-
import java.util.Collection;
4039
import java.util.Collections;
4140
import org.hamcrest.MatcherAssert;
4241
import org.hamcrest.Matchers;
@@ -127,34 +126,18 @@ public void findsProblemsInJavaFiles() throws Exception {
127126

128127
/**
129128
* PmdValidator can understand method references.
130-
* @todo #1129 Replace not+empty() with more precise containsInAnyOrder
131129
* @throws Exception If something wrong happens inside.
132130
*/
133131
@Test
134-
@SuppressWarnings("PMD.AvoidDuplicateLiterals")
135132
public void understandsMethodReferences() throws Exception {
136-
final String file = "src/main/java/Other.java";
137-
final Environment env = new Environment.Mock().withFile(
133+
final String file = "UnderstandsMethodReferences.java";
134+
new PmdAssert(
138135
file,
139-
Joiner.on('\n').join(
140-
"import java.util.ArrayList;",
141-
"class Other {",
142-
" public static void test() {",
143-
" new ArrayList<String>().forEach(Other::other);",
144-
" }",
145-
" private static void other(String some) {",
146-
" // body",
147-
" }",
148-
"}"
136+
Matchers.is(true),
137+
Matchers.not(
138+
Matchers.containsString("(UnusedPrivateMethod)")
149139
)
150-
);
151-
final Collection<Violation> violations = new PmdValidator(env).validate(
152-
Collections.singletonList(new File(env.basedir(), file))
153-
);
154-
MatcherAssert.assertThat(
155-
violations,
156-
Matchers.not(Matchers.<Violation>empty())
157-
);
140+
).validate();
158141
}
159142

160143
/**
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package foo;
2+
3+
import java.util.ArrayList;
4+
5+
public final class UnderstandsMethodReferences {
6+
public void test() {
7+
new ArrayList<String>().forEach(
8+
UnderstandsMethodReferences::other
9+
);
10+
}
11+
private static void other() {
12+
// body
13+
}
14+
}

0 commit comments

Comments
 (0)