Skip to content

Commit

Permalink
Failing test example for ForbidJavaxParameterType (#2367)
Browse files Browse the repository at this point in the history
  • Loading branch information
carterkozak authored Aug 24, 2022
1 parent 5e26ec0 commit 44a763c
Showing 1 changed file with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.palantir.baseline.errorprone;

import com.google.errorprone.CompilationTestHelper;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -101,18 +103,16 @@ void failsIfIncorrectTypeIsSuppliedViaMethodReturn() {

@Test
void stillFailsIfInnerIsSeparateClass() {
CompilationTestHelper helper = helper();

helper.addSourceLines(
"Outer.java",
"import javax.ws.rs.Path;",
"import javax.ws.rs.GET;",
" public class Outer {",
" @Path(\"foo\")",
" @GET",
" public String doGet() { return \"hi\"; }",
" }");
helper.addSourceLines(
helper().addSourceLines(
"Outer.java",
"import javax.ws.rs.Path;",
"import javax.ws.rs.GET;",
" public class Outer {",
" @Path(\"foo\")",
" @GET",
" public String doGet() { return \"hi\"; }",
" }")
.addSourceLines(
"Test.java",
"import com.palantir.errorprone.ForbidJavax;",
"class Test {",
Expand All @@ -127,6 +127,28 @@ void stillFailsIfInnerIsSeparateClass() {
.doTest();
}

public interface JaxrsAnnotatedIface {
@Path("foo")
@GET
String doGet();
}

@Test
void stillFailsIfInnerIsSeparateJar() {
helper().addSourceLines(
"Test.java",
"import com.palantir.errorprone.ForbidJavax;",
"import " + JaxrsAnnotatedIface.class.getCanonicalName() + ';',
"class Test {",
" public static void requiresJakarta(@ForbidJavax Object o) {}",
" public static void f(JaxrsAnnotatedIface arg) {",
" // BUG: Diagnostic contains: ForbidJavaxParameterType",
" requiresJakarta(arg);",
" }",
"}")
.doTest();
}

@Test
@Disabled("Unfortunately disabled because we can't have both annotation types on the classpath")
void succeedsIfGivenJakartaType() {
Expand Down

0 comments on commit 44a763c

Please sign in to comment.