Skip to content

Commit

Permalink
Add a test to confirm that qualifyType won't qualify java.lang.
Browse files Browse the repository at this point in the history
I thought this was a bug. It wasn't, but a test is nice to have.

PiperOrigin-RevId: 639816617
  • Loading branch information
graememorgan authored and Error Prone Team committed Jun 3, 2024
1 parent fefaf67 commit 3e772f7
Showing 1 changed file with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,10 @@ public void qualifyType_alreadyImported() {
public void qualifyType_importType() {
AddAnnotation.testHelper(getClass())
.addInputLines(
"in/AddAnnotation.java", "class AddAnnotation {", " Void foo() { return null; }", "}")
"in/AddAnnotation.java", //
"class AddAnnotation {",
" Void foo() { return null; }",
"}")
.addOutputLines(
"out/AddAnnotation.java",
"import some.pkg.SomeAnnotation;",
Expand All @@ -480,7 +483,9 @@ public void qualifyType_importType() {
@Test
public void qualifyType_someOtherNullable() {
AddAnnotation.testHelper(getClass())
.addInputLines("in/SomeAnnotation.java", "@interface SomeAnnotation {}")
.addInputLines(
"in/SomeAnnotation.java", //
"@interface SomeAnnotation {}")
.expectUnchanged()
.addInputLines(
"in/AddAnnotation.java",
Expand Down Expand Up @@ -542,7 +547,9 @@ public void qualifyType_deeplyNestedNullable() {
public void qualifyType_someOtherNullableSomeOtherPackage() {
AddAnnotation.testHelper(getClass())
.addInputLines(
"in/SomeAnnotation.java", "package foo.bar;", "public @interface SomeAnnotation {}")
"in/SomeAnnotation.java", //
"package foo.bar;",
"public @interface SomeAnnotation {}")
.expectUnchanged()
.addInputLines(
"in/AddAnnotation.java",
Expand Down Expand Up @@ -604,6 +611,23 @@ public void qualifyType_deeplyNestedType() {
qualifyDeeplyNestedType(new ReplaceReturnType("pkg.Outer.Inner.Innermost"));
}

@Test
public void qualifyType_javaLang_notImported() {
BugCheckerRefactoringTestHelper.newInstance(
new ReplaceReturnType("java.lang.String"), getClass())
.addInputLines(
"Test.java", //
"class Test {",
" Void foo() { return null; }",
"}")
.addOutputLines(
"Test.java", //
"class Test {",
" String foo() { return null; }",
"}")
.doTest();
}

/** A test check that replaces all methods' return types with a given type. */
@BugPattern(summary = "Change the method return type", severity = ERROR)
public static class ReplaceReturnTypeString extends BugChecker
Expand Down

0 comments on commit 3e772f7

Please sign in to comment.