From 9460d8be21befc677c4c688c54d095032923b5b7 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Sat, 18 Jan 2025 11:40:36 -0800 Subject: [PATCH] Add test for element References #313. --- .../ModernizerTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/modernizer-maven-plugin/src/test/java/org/gaul/modernizer_maven_plugin/ModernizerTest.java b/modernizer-maven-plugin/src/test/java/org/gaul/modernizer_maven_plugin/ModernizerTest.java index bc87b55..0424c10 100644 --- a/modernizer-maven-plugin/src/test/java/org/gaul/modernizer_maven_plugin/ModernizerTest.java +++ b/modernizer-maven-plugin/src/test/java/org/gaul/modernizer_maven_plugin/ModernizerTest.java @@ -396,6 +396,20 @@ public void testAnnotationViolation() throws Exception { .isEqualTo(name); } + @Test + public void testUntil() throws Exception { + ClassReader cr = new ClassReader(UntilTest.class.getName()); + Collection occurrences = createModernizer("10").check(cr); + assertThat(occurrences).hasSize(1); + assertThat(occurrences.iterator().next().getViolation().getComment()) + .isEqualTo("Prefer java.nio.file.Files.newInputStream(java.nio.file.Paths.get(String))"); + + occurrences = createModernizer("11").check(cr); + assertThat(occurrences).hasSize(1); + assertThat(occurrences.iterator().next().getViolation().getComment()) + .isEqualTo("Prefer java.nio.file.Files.newInputStream(java.nio.file.Path.of(String))"); + } + @Test public void testAllViolations() throws Exception { Modernizer modernizer = createModernizer("24"); @@ -583,6 +597,12 @@ public Object get() { } } + private static class UntilTest { + public static void method() throws Exception { + new FileInputStream(""); + } + } + private static class AllViolations { @SuppressWarnings(value = { "BoxedPrimitiveConstructor",