From 174f53247ed3efcc32a70a177d2a79189865609a Mon Sep 17 00:00:00 2001 From: Carter Kozak Date: Thu, 16 Feb 2023 05:57:07 -0500 Subject: [PATCH] Add test coverage for annotated return types (#2494) Add test coverage for annotated return types --- .../IllegalSafeLoggingArgumentTest.java | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/baseline-error-prone/src/test/java/com/palantir/baseline/errorprone/IllegalSafeLoggingArgumentTest.java b/baseline-error-prone/src/test/java/com/palantir/baseline/errorprone/IllegalSafeLoggingArgumentTest.java index e81933ae7..a88610387 100644 --- a/baseline-error-prone/src/test/java/com/palantir/baseline/errorprone/IllegalSafeLoggingArgumentTest.java +++ b/baseline-error-prone/src/test/java/com/palantir/baseline/errorprone/IllegalSafeLoggingArgumentTest.java @@ -221,6 +221,69 @@ public void testSafeReturn() { .doTest(); } + @Test + public void testDoNotLogReturnTypeAnnotation() { + helper().addSourceLines( + "Test.java", + "import com.palantir.logsafe.*;", + "class Test {", + " static @DoNotLog Object doNotLogMethod() { return null; }", + " static @Safe Object safeMethod() { return null; }", + " static @Unsafe Object unsafeMethod() { return null; }", + " void f() {", + " fun(doNotLogMethod());", + " fun(safeMethod());", + " fun(unsafeMethod());", + " }", + " private static void fun(@DoNotLog Object obj) {}", + "}") + .doTest(); + } + + @Test + public void testUnsafeReturnTypeAnnotation() { + helper().addSourceLines( + "Test.java", + "import com.palantir.logsafe.*;", + "class Test {", + " static @DoNotLog Object doNotLogMethod() { return null; }", + " static @Safe Object safeMethod() { return null; }", + " static @Unsafe Object unsafeMethod() { return null; }", + " void f() {", + " // BUG: Diagnostic contains: Dangerous argument value: arg is 'DO_NOT_LOG' " + + "but the parameter requires 'UNSAFE'.", + " fun(doNotLogMethod());", + " fun(safeMethod());", + " fun(unsafeMethod());", + " }", + " private static void fun(@Unsafe Object obj) {}", + "}") + .doTest(); + } + + @Test + public void testSafeReturnTypeAnnotation() { + helper().addSourceLines( + "Test.java", + "import com.palantir.logsafe.*;", + "class Test {", + " static @DoNotLog Object doNotLogMethod() { return null; }", + " static @Safe Object safeMethod() { return null; }", + " static @Unsafe Object unsafeMethod() { return null; }", + " void f() {", + " // BUG: Diagnostic contains: Dangerous argument value: arg is 'DO_NOT_LOG' " + + "but the parameter requires 'SAFE'.", + " fun(doNotLogMethod());", + " fun(safeMethod());", + " // BUG: Diagnostic contains: Dangerous argument value: arg is 'UNSAFE' " + + "but the parameter requires 'SAFE'.", + " fun(unsafeMethod());", + " }", + " private static void fun(@Safe Object obj) {}", + "}") + .doTest(); + } + @Test public void testUnsafeTypeParameterProvidesSafety() { helper().addSourceLines(