From 51b6ae3b5d349825d6c301a8c7ae542e0ae50ad0 Mon Sep 17 00:00:00 2001 From: Delany Date: Mon, 3 Apr 2023 21:30:44 +0200 Subject: [PATCH] Add Stack to legacy apis --- .../src/main/resources/modernizer.xml | 6 +++ .../ModernizerTest.java | 42 +++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/modernizer-maven-plugin/src/main/resources/modernizer.xml b/modernizer-maven-plugin/src/main/resources/modernizer.xml index 04a9a0a8..f428674c 100644 --- a/modernizer-maven-plugin/src/main/resources/modernizer.xml +++ b/modernizer-maven-plugin/src/main/resources/modernizer.xml @@ -557,6 +557,12 @@ violation names use the same format that javap emits. Prefer java.util.HashMap + + java/util/Stack."<init>":()V + 6 + Prefer java.util.Deque + + java/util/Vector."<init>":()V 2 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 4bec6f0e..0b2a8d44 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 @@ -51,6 +51,7 @@ import java.util.Scanner; import java.util.Set; import java.util.SortedMap; +import java.util.Stack; import java.util.TreeMap; import java.util.TreeSet; import java.util.Vector; @@ -149,8 +150,26 @@ public void testConstructorCurrentApi() throws Exception { assertThat(occurrences).hasSize(0); } + @Test + public void testStackConstructorLegacyApiLegacyJava() throws Exception { + ClassReader cr = new ClassReader(StackTestClass.class.getName()); + Collection occurrences = + createModernizer("1.0").check(cr); + assertThat(occurrences).hasSize(0); + } + + @Test + public void testStackConstructorLegacyApiCurrentJava() throws Exception { + ClassReader cr = new ClassReader(StackTestClass.class.getName()); + Collection occurrences = + createModernizer("1.6").check(cr); + assertThat(occurrences).hasSize(1); + assertThat(occurrences.iterator().next().getViolation().getName()) + .isEqualTo("java/util/Stack.\"\":()V"); + } + @Test - public void testConstructorLegacyApiLegacyJava() throws Exception { + public void testVectorConstructorLegacyApiLegacyJava() throws Exception { ClassReader cr = new ClassReader(VectorTestClass.class.getName()); Collection occurrences = createModernizer("1.0").check(cr); @@ -158,7 +177,7 @@ public void testConstructorLegacyApiLegacyJava() throws Exception { } @Test - public void testConstructorLegacyApiCurrentJava() throws Exception { + public void testVectorConstructorLegacyApiCurrentJava() throws Exception { ClassReader cr = new ClassReader(VectorTestClass.class.getName()); Collection occurrences = createModernizer("1.2").check(cr); @@ -338,8 +357,19 @@ public void testHandlingOfDefaultPackageClass() throws Exception { assertThat(occurrences).hasSize(0); } + @Test + public void testStackConstructorLegacyApiCurrentJavaWithVersionShorthand() + throws Exception { + ClassReader cr = new ClassReader(StackTestClass.class.getName()); + Collection occurrences = + createModernizer("6").check(cr); + assertThat(occurrences).hasSize(1); + assertThat(occurrences.iterator().next().getViolation().getName()) + .isEqualTo("java/util/Stack.\"\":()V"); + } + @Test - public void testConstructorLegacyApiCurrentJavaWithVersionShorthand() + public void testVectorConstructorLegacyApiCurrentJavaWithVersionShorthand() throws Exception { ClassReader cr = new ClassReader(VectorTestClass.class.getName()); Collection occurrences = @@ -466,6 +496,11 @@ private static class ArrayListTestClass { private final Object object = new ArrayList(); } + private static class StackTestClass { + @SuppressWarnings("JdkObsolete") + private final Object object = new Stack(); + } + private static class VectorTestClass { @SuppressWarnings("JdkObsolete") private final Object object = new Vector(); @@ -623,6 +658,7 @@ private static void method() throws Exception { new Hashtable(0); new Hashtable(); new Hashtable((Map) null); + new Stack(); new Vector(); new Vector(1); new Vector(0, 0);