Skip to content

Commit

Permalink
test tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
msridhar committed Dec 6, 2024
1 parent 6d806cb commit 223f8ef
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions nullaway/src/test/java/com/uber/nullaway/AccessPathsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public void testAccessUsingExplicitThis() {
}

@Test
public void testValueOfNoReceiver() {
public void mapKeysFromValueOf() {
defaultCompilationHelper
.addSourceLines(
"Foo.java",
Expand All @@ -445,15 +445,40 @@ public void testValueOfNoReceiver() {
"import java.util.Map;",
"public class Foo {",
" private final Map<Integer, Object> map = new HashMap<>();",
" private final Map<Long, Object> longMap = new HashMap<>();",
" static Integer valueOf(int i) { return 0; }",
" public void putThenGetIntegerValueOf() {",
" map.put(Integer.valueOf(10), new Object());",
" map.get(Integer.valueOf(10)).toString();",
" }",
" public void putThenGetLongValueOf() {",
" longMap.put(Long.valueOf(10), new Object());",
" longMap.get(Long.valueOf(10)).toString();",
" }",
" public void putThenGetFooValueOf() {",
" map.put(valueOf(10), new Object());",
" // Unknown valueOf method so we report a warning",
" // BUG: Diagnostic contains: dereferenced expression map.get(valueOf(10)) is @Nullable",
" map.get(valueOf(10)).toString();",
" }",
" public void putThenGetFooIntegerValueOf() {",
" map.put(Integer.valueOf(10), new Object());",
" map.get(Integer.valueOf(10)).toString();",
"}")
.doTest();
}

@Test
public void mapKeyFromIntegerValueOfStaticImport() {
defaultCompilationHelper
.addSourceLines(
"Foo.java",
"package com.uber;",
"import java.util.HashMap;",
"import java.util.Map;",
"import static java.lang.Integer.valueOf;",
"public class Foo {",
" private final Map<Integer, Object> map = new HashMap<>();",
" public void putThenGet() {",
" map.put(valueOf(10), new Object());",
" map.get(valueOf(10)).toString();",
" }",
"}")
.doTest();
Expand Down

0 comments on commit 223f8ef

Please sign in to comment.