Skip to content

Commit

Permalink
Add Stack to legacy apis
Browse files Browse the repository at this point in the history
  • Loading branch information
delanym authored and gaul committed Apr 4, 2023
1 parent 6490294 commit 718cfec
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
6 changes: 6 additions & 0 deletions modernizer-maven-plugin/src/main/resources/modernizer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,12 @@ violation names use the same format that javap emits.
<comment>Prefer java.util.HashMap</comment>
</violation>

<violation>
<name>java/util/Stack."&lt;init&gt;":()V</name>
<version>6</version>
<comment>Prefer java.util.Deque</comment>
</violation>

<violation>
<name>java/util/Vector."&lt;init&gt;":()V</name>
<version>2</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -149,16 +150,34 @@ public void testConstructorCurrentApi() throws Exception {
assertThat(occurrences).hasSize(0);
}

@Test
public void testStackConstructorLegacyApiLegacyJava() throws Exception {
ClassReader cr = new ClassReader(StackTestClass.class.getName());
Collection<ViolationOccurrence> occurrences =
createModernizer("1.0").check(cr);
assertThat(occurrences).hasSize(0);
}

@Test
public void testStackConstructorLegacyApiCurrentJava() throws Exception {
ClassReader cr = new ClassReader(StackTestClass.class.getName());
Collection<ViolationOccurrence> occurrences =
createModernizer("1.6").check(cr);
assertThat(occurrences).hasSize(1);
assertThat(occurrences.iterator().next().getViolation().getName())
.isEqualTo("java/util/Stack.\"<init>\":()V");
}

@Test
public void testConstructorLegacyApiLegacyJava() throws Exception {
public void testVectorConstructorLegacyApiLegacyJava() throws Exception {
ClassReader cr = new ClassReader(VectorTestClass.class.getName());
Collection<ViolationOccurrence> occurrences =
createModernizer("1.0").check(cr);
assertThat(occurrences).hasSize(0);
}

@Test
public void testConstructorLegacyApiCurrentJava() throws Exception {
public void testVectorConstructorLegacyApiCurrentJava() throws Exception {
ClassReader cr = new ClassReader(VectorTestClass.class.getName());
Collection<ViolationOccurrence> occurrences =
createModernizer("1.2").check(cr);
Expand Down Expand Up @@ -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<ViolationOccurrence> occurrences =
createModernizer("6").check(cr);
assertThat(occurrences).hasSize(1);
assertThat(occurrences.iterator().next().getViolation().getName())
.isEqualTo("java/util/Stack.\"<init>\":()V");
}

@Test
public void testConstructorLegacyApiCurrentJavaWithVersionShorthand()
public void testVectorConstructorLegacyApiCurrentJavaWithVersionShorthand()
throws Exception {
ClassReader cr = new ClassReader(VectorTestClass.class.getName());
Collection<ViolationOccurrence> occurrences =
Expand Down Expand Up @@ -466,6 +496,11 @@ private static class ArrayListTestClass {
private final Object object = new ArrayList<Object>();
}

private static class StackTestClass {
@SuppressWarnings("JdkObsolete")
private final Object object = new Stack<Object>();
}

private static class VectorTestClass {
@SuppressWarnings("JdkObsolete")
private final Object object = new Vector<Object>();
Expand Down Expand Up @@ -623,6 +658,7 @@ private static void method() throws Exception {
new Hashtable<Object, Object>(0);
new Hashtable<Object, Object>();
new Hashtable<Object, Object>((Map<Object, Object>) null);
new Stack<Object>();
new Vector<Object>();
new Vector<Object>(1);
new Vector<Object>(0, 0);
Expand Down

0 comments on commit 718cfec

Please sign in to comment.