From 9c8e43e8f8529dbefe8fb922bef8c13af2b87468 Mon Sep 17 00:00:00 2001 From: Ankit Yadav <49056780+avenger2597@users.noreply.github.com> Date: Thu, 7 Nov 2024 11:07:13 -0800 Subject: [PATCH] Added JUnits for annotation insertion/deletion on array component name (#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. --- .../riple/injector/TypeUseAnnotationTest.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/injector/src/test/java/edu/ucr/cs/riple/injector/TypeUseAnnotationTest.java b/injector/src/test/java/edu/ucr/cs/riple/injector/TypeUseAnnotationTest.java index 64896e5d..fe1fb799 100644 --- a/injector/src/test/java/edu/ucr/cs/riple/injector/TypeUseAnnotationTest.java +++ b/injector/src/test/java/edu/ucr/cs/riple/injector/TypeUseAnnotationTest.java @@ -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 h2;", + " List 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 h2;", + " List 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(); + } }