From ce892d7f7134141ce02ea674b5b28aaa971a117d Mon Sep 17 00:00:00 2001 From: Manu Sridharan Date: Tue, 26 Mar 2024 11:15:37 -0700 Subject: [PATCH] Add test for boolean contract with extra message argument (#945) This just tests an additional scenario; no logic changes. --- .../com/uber/nullaway/NullAwayContractsBooleanTests.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/nullaway/src/test/java/com/uber/nullaway/NullAwayContractsBooleanTests.java b/nullaway/src/test/java/com/uber/nullaway/NullAwayContractsBooleanTests.java index b04189a34e..9eabae8504 100644 --- a/nullaway/src/test/java/com/uber/nullaway/NullAwayContractsBooleanTests.java +++ b/nullaway/src/test/java/com/uber/nullaway/NullAwayContractsBooleanTests.java @@ -19,6 +19,10 @@ public void nonNullCheckIsTrueIsNotNullable() { " Validation.checkTrue(o1 != null);", " return o1.toString();", " }", + " String test1WithMsg(@Nullable Object o1) {", + " Validation.checkTrue(o1 != null, \"o1 should not be null!\");", + " return o1.toString();", + " }", " String test2(Map map) {", " Validation.checkTrue(map.get(\"key\") != null);", " return map.get(\"key\").toString();", @@ -553,6 +557,10 @@ private CompilationTestHelper helper() { " static void checkTrue(boolean value) {", " if (!value) throw new RuntimeException();", " }", + " @Contract(\"false, _ -> fail\")", + " static void checkTrue(boolean value, String msg) {", + " if (!value) throw new RuntimeException(msg);", + " }", " @Contract(\"true -> fail\")", " static void checkFalse(boolean value) {", " if (value) throw new RuntimeException();",