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 test cases for annotation insertion/deletion on array component type. #258

Merged
Merged
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
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();
}
}
Loading