Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stack to legacy apis #183

Merged
merged 1 commit into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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