Skip to content

Commit

Permalink
adding test case for void return type and updating the NullUnmarked test
Browse files Browse the repository at this point in the history
  • Loading branch information
akulk022 committed Sep 22, 2024
1 parent d24267c commit 29a902b
Showing 1 changed file with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,7 @@ public void nullableParametersInNullUnmarkedClass() throws IOException {
new String[] {
"import org.jspecify.annotations.NullMarked;",
"import org.jspecify.annotations.Nullable;",
"@NullMarked",
"public class NullableParameters{",
"public class NullUnmarked{",
" public static Object getNewObjectIfNull(@Nullable Object object) {",
" if (object == null) {",
" return new Object();",
Expand All @@ -187,17 +186,9 @@ public void nullableParametersInNullUnmarkedClass() throws IOException {
" }",
"}"
};
ImmutableMap<String, MethodAnnotationsRecord> expectedMethodRecords =
ImmutableMap.of(
"NullableParameters:java.lang.Object getNewObjectIfNull(java.lang.Object)",
MethodAnnotationsRecord.create(
ImmutableSet.of(), ImmutableMap.of(0, ImmutableSet.of("Nullable"))));
ImmutableMap<String, MethodAnnotationsRecord> expectedMethodRecords = ImmutableMap.of();
runTest(
"NullableParameters.java",
lines,
expectedMethodRecords,
ImmutableMap.of(),
ImmutableSet.of("NullableParameters"));
"NullUnmarked.java", lines, expectedMethodRecords, ImmutableMap.of(), ImmutableSet.of());
}

@Test
Expand Down Expand Up @@ -284,4 +275,33 @@ public void primitiveTypeReturn() throws IOException {
ImmutableMap.of(),
ImmutableSet.of("PrimitiveType"));
}

@Test
public void voidReturn() throws IOException {
String[] lines =
new String[] {
"import org.jspecify.annotations.NullMarked;",
"import org.jspecify.annotations.Nullable;",
"@NullMarked",
"public class VoidReturn {",
" public void printMultiply(@Nullable Integer num1, @Nullable Integer num2) {",
" if(num1!=null && num2!=null){",
" System.out.println(num1*num2);",
" }",
" }",
"}"
};
ImmutableMap<String, MethodAnnotationsRecord> expectedMethodRecords =
ImmutableMap.of(
"VoidReturn:void printMultiply(java.lang.Integer, java.lang.Integer)",
MethodAnnotationsRecord.create(
ImmutableSet.of(),
ImmutableMap.of(0, ImmutableSet.of("Nullable"), 1, ImmutableSet.of("Nullable"))));
runTest(
"VoidReturn.java",
lines,
expectedMethodRecords,
ImmutableMap.of(),
ImmutableSet.of("VoidReturn"));
}
}

0 comments on commit 29a902b

Please sign in to comment.