diff --git a/test/DocTests.java b/test/DocTests.java index 181d6b0..71982da 100644 --- a/test/DocTests.java +++ b/test/DocTests.java @@ -19,6 +19,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; +import com.facebook.infer.annotation.Nullsafe; import com.facebook.soloader.nativeloader.NativeLoader; import java.nio.ByteBuffer; import java.util.Arrays; @@ -29,6 +30,7 @@ import org.junit.BeforeClass; import org.junit.Test; +@Nullsafe(Nullsafe.Mode.LOCAL) public class DocTests extends BaseFBJniTests { @BeforeClass public static void setup() { @@ -42,9 +44,13 @@ public String toString() { // SECTION basic_methods native void nativeVoidMethod(); + static native void staticNativeVoidMethod(); + void voidMethod() {} + static void staticVoidMethod() {} + // END @Test @@ -55,19 +61,29 @@ public void testVoids() { // SECTION primitives static native long addSomeNumbers(byte b, short s, int i); - static long doubler(int i) { return i + i; } + + static long doubler(int i) { + return i + i; + } + // END @Test public void testNumbers() { + // NULLSAFE_FIXME[Not Vetted Third-Party] assertThat(addSomeNumbers((byte) 1, (short) 2, 3)).isEqualTo(14); } // SECTION strings // Java methods used by the C++ code below. static native String fancyCat(String s1, String s2); + static native String getCString(); - static String doubler(String s) { return s + s; } + + static String doubler(String s) { + return s + s; + } + // END @Test @@ -78,10 +94,12 @@ public void testStrings() { // SECTION primitive_arrays static native int[] primitiveArrays(int[] arr); + // END @Test public void testPrimitiveArrays() { + // NULLSAFE_FIXME[Not Vetted Third-Party] assertThat(primitiveArrays(new int[] {1, 2})).contains(1, 2, 3); } @@ -103,7 +121,9 @@ public void testCastReferences() { castReferences(new MyBaseClass()); failBecauseExceptionWasNotThrown(ClassCastException.class); } catch (ClassCastException e) { + // NULLSAFE_FIXME[Not Vetted Third-Party] assertThat(e).hasMessageContaining("MyBaseClass"); + // NULLSAFE_FIXME[Not Vetted Third-Party] assertThat(e).hasMessageContaining("MyDerivedClass"); } } @@ -124,6 +144,7 @@ public void testCallGetAndSetFields() { synchronized (DataHolder.class) { DataHolder dh1 = new DataHolder(1, "1"); DataHolder dh2 = new DataHolder(3, "3"); + // NULLSAFE_FIXME[Field Not Nullable] DataHolder.someInstance = null; callGetAndSetFields(dh1); assertThat(dh1.i).isEqualTo(2); @@ -133,6 +154,7 @@ public void testCallGetAndSetFields() { assertThat(dh2.i).isEqualTo(4); assertThat(dh2.s).isEqualTo("31"); assertThat(DataHolder.someInstance).isSameAs(dh1); + // NULLSAFE_FIXME[Field Not Nullable] DataHolder.someInstance = null; } } @@ -153,24 +175,27 @@ public void testCatchAndThrow() { catchAndThrow(); failBecauseExceptionWasNotThrown(RuntimeException.class); } catch (RuntimeException e) { + // NULLSAFE_FIXME[Not Vetted Third-Party] assertThat(e) .hasMessageStartingWith("Caught 'java.lang.NoSuchMethodError:") - .hasMessageContaining("doesNotExist") - ; + .hasMessageContaining("doesNotExist"); } } // SECTION boxed static native Double scaleUp(Integer number); + // END @Test public void testScaleUp() { + // NULLSAFE_FIXME[Not Vetted Third-Party] assertThat(scaleUp(5)).isEqualTo(7.5); } // SECTION iterables static native String concatMatches(List values, Map names); + // END @Test @@ -185,22 +210,29 @@ public void testConcatMatches() { // SECTION collections static native Map> buildCollections(); + // END @Test public void testBuildCollections() { Map> ret = buildCollections(); + // NULLSAFE_FIXME[Not Vetted Third-Party] assertThat(ret.keySet()).isEqualTo(new HashSet<>(Arrays.asList("primes"))); + // NULLSAFE_FIXME[Parameter Not Nullable] assertThat(ret.get("primes")).isEqualTo(Arrays.asList(2, 3)); } // SECTION byte_buffer static native ByteBuffer transformBuffer(ByteBuffer data); + static void receiveBuffer(ByteBuffer buffer) { assertThat(buffer.capacity()).isEqualTo(2); - assertThat(buffer.get(0)).isEqualTo((byte)2); - assertThat(buffer.get(1)).isEqualTo((byte)3); + // NULLSAFE_FIXME[Not Vetted Third-Party] + assertThat(buffer.get(0)).isEqualTo((byte) 2); + // NULLSAFE_FIXME[Not Vetted Third-Party] + assertThat(buffer.get(1)).isEqualTo((byte) 3); } + @Test public void testByteBuffers() { ByteBuffer data = ByteBuffer.allocateDirect(2); @@ -213,23 +245,28 @@ public void testByteBuffers() { // SECTION inheritance class MyBaseClass {} + class MyDerivedClass extends MyBaseClass {} + // END // SECTION nested_class class Outer { class Nested {} } + // END // SECTION constructor class DataHolder { int i; String s; + DataHolder(int i, String s) { this.i = i; this.s = s; } + static DataHolder someInstance; } // END