Skip to content

Commit

Permalink
Added JUnits for annotation insertion/deletion on array component name (
Browse files Browse the repository at this point in the history
#258)

This PR adds test cases for the addition and deletion of annotations on the component type of arrays. It includes tests to verify successful annotation updates for arrays containing both primitive types and wrapper class types.
  • Loading branch information
avenger2597 authored Nov 7, 2024
1 parent afda6c6 commit 9c8e43e
Showing 1 changed file with 74 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -845,4 +845,78 @@ public void nullableArrayAdditionOnComponentWithArrayOfPrimitiveType() {
ImmutableList.of(ImmutableList.of(1, 1, 0))))
.start();
}

@Test
public void nullableArrayAdditionOnComponentType() {
injectorTestHelper
.addInput(
"Foo.java",
"package test;",
"import javax.annotation.Nullable;",
"public class Foo {",
" Object[] h1 = new Object[4];",
" Map<String, String[]> h2;",
" List<char[]> h3 = new ArrayList<>();",
"}")
.expectOutput(
"package test;",
"import javax.annotation.Nullable;",
"public class Foo {",
" @Nullable Object[] h1 = new Object[4];",
" @Nullable Map<@Nullable String, @Nullable String[]> h2;",
" @Nullable List<@Nullable char[]> h3 = new ArrayList<>();",
"}")
.addChanges(
new AddTypeUseMarkerAnnotation(
new OnField("Foo.java", "test.Foo", Collections.singleton("h1")),
"javax.annotation.Nullable",
ImmutableList.of(ImmutableList.of(1, 0))),
new AddTypeUseMarkerAnnotation(
new OnField("Foo.java", "test.Foo", Collections.singleton("h2")),
"javax.annotation.Nullable",
ImmutableList.of(
ImmutableList.of(0), ImmutableList.of(1, 0), ImmutableList.of(2, 1, 0))),
new AddTypeUseMarkerAnnotation(
new OnField("Foo.java", "test.Foo", Collections.singleton("h3")),
"javax.annotation.Nullable",
ImmutableList.of(ImmutableList.of(0), ImmutableList.of(1, 1, 0))))
.start();
}

@Test
public void nullableArrayDeletionOnComponentType() {
injectorTestHelper
.addInput(
"Foo.java",
"package test;",
"import javax.annotation.Nullable;",
"public class Foo {",
" @Nullable Object[] h1 = new Object[4];",
" @Nullable Map<@Nullable String, @Nullable String[]> h2;",
" @Nullable List<@Nullable char[]> h3 = new ArrayList<>();",
"}")
.expectOutput(
"package test;",
"import javax.annotation.Nullable;",
"public class Foo {",
" Object[] h1 = new Object[4];",
" Map<String, String[]> h2;",
" List<char[]> h3 = new ArrayList<>();",
"}")
.addChanges(
new RemoveTypeUseMarkerAnnotation(
new OnField("Foo.java", "test.Foo", Collections.singleton("h1")),
"javax.annotation.Nullable",
ImmutableList.of(ImmutableList.of(0))),
new RemoveTypeUseMarkerAnnotation(
new OnField("Foo.java", "test.Foo", Collections.singleton("h2")),
"javax.annotation.Nullable",
ImmutableList.of(
ImmutableList.of(0), ImmutableList.of(1, 0), ImmutableList.of(2, 1, 0))),
new RemoveTypeUseMarkerAnnotation(
new OnField("Foo.java", "test.Foo", Collections.singleton("h3")),
"javax.annotation.Nullable",
ImmutableList.of(ImmutableList.of(0), ImmutableList.of(1, 1, 0))))
.start();
}
}

0 comments on commit 9c8e43e

Please sign in to comment.