Skip to content

Commit

Permalink
Adding test cases for different scenarios of generic type method refe…
Browse files Browse the repository at this point in the history
…rences
  • Loading branch information
akulk022 committed Oct 18, 2023
1 parent dea0d60 commit b22da52
Showing 1 changed file with 76 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,28 @@ public void testForMethodReferenceInAnAssignment() {
}

@Test
public void testForMethodReferenceReturnType() {
public void testForMethodReferenceForClassFieldAssignment() {
makeHelper()
.addSourceLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"class Test {",
" interface A<T1 extends @Nullable Object> {",
" T1 function(Object o);",
" }",
" static @Nullable String foo(Object o) {",
" return o.toString();",
" }",
" // BUG: Diagnostic contains: referenced method returns @Nullable",
" A<String> positiveField = Test::foo;",
" A<@Nullable String> negativeField = Test::foo;",
"}")
.doTest();
}

@Test
public void testForMethodReferenceReturnTypeInAnAssignment() {
makeHelper()
.addSourceLines(
"Test.java",
Expand All @@ -464,6 +485,60 @@ public void testForMethodReferenceReturnType() {
.doTest();
}

@Test
public void testForMethodReferenceWhenReturned() {
makeHelper()
.addSourceLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"class Test {",
" interface A<T1 extends @Nullable Object> {",
" T1 function(Object o);",
" }",
" static @Nullable String foo(Object o) {",
" return o.toString();",
" }",
" static A<String> testPositive() {",
" // BUG: Diagnostic contains: referenced method returns @Nullable",
" return Test::foo;",
" }",
" static A<@Nullable String> testNegative() {",
" return Test::foo;",
" }",
"}")
.doTest();
}

@Test
public void testForMethodReferenceAsMethodParameter() {
makeHelper()
.addSourceLines(
"Test.java",
"package com.uber;",
"import org.jspecify.annotations.Nullable;",
"class Test {",
" interface A<T1 extends @Nullable Object> {",
" T1 function(Object o);",
" }",
" static @Nullable String foo(Object o) {",
" return o.toString();",
" }",
" static void fooPositive(A<String> a) {",
" }",
" static void fooNegative(A<@Nullable String> a) {",
" }",
" static void testPositive() {",
" // BUG: Diagnostic contains: referenced method returns @Nullable",
" fooPositive(Test::foo);",
" }",
" static void testNegative() {",
" fooNegative(Test::foo);",
" }",
"}")
.doTest();
}

@Test
public void testForLambdasInAnAssignment() {
makeHelper()
Expand Down

0 comments on commit b22da52

Please sign in to comment.