Skip to content

Commit

Permalink
Migrate Tests from javax.inject to jakarta.inject annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Nov 4, 2023
1 parent 2778f6d commit 2e15df5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.jdt.core.tests.compiler/META-INF/MANIFEST.MF
Expand Up @@ -23,7 +23,7 @@ Require-Bundle: org.junit;bundle-version="3.8.1",
org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
org.eclipse.jdt.annotation;bundle-version="[1.1.0,2.0.0)";resolution:=optional,
org.eclipse.jdt.annotation;bundle-version="[2.0.0,3.0.0)";resolution:=optional
Import-Package: javax.annotation;version="[1.3.0,2.0.0)",
Import-Package: jakarta.annotation;version="[2.1.0,3.0.0)",
org.eclipse.jdt.internal.compiler.apt.dispatch
Bundle-RequiredExecutionEnvironment: JavaSE-17
Eclipse-BundleShape: dir
Expand Down
Expand Up @@ -44,7 +44,7 @@ public class AbstractComparableTest extends AbstractRegressionTest {

protected static final String JAVAX_INJECT_NAME = "javax/inject/Inject.java";
protected static final String JAVAX_INJECT_CONTENT =
"package javax.inject;\n" +
"package jakarta.inject;\n" +
"import static java.lang.annotation.ElementType.*;\n" +
"import java.lang.annotation.Retention;\n" +
"import static java.lang.annotation.RetentionPolicy.RUNTIME;\n" +
Expand Down
Expand Up @@ -10732,7 +10732,7 @@ public void testBug376590a() {
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
// https://bugs.eclipse.org/376590 - Private fields with @Inject are ignored by unused field validation
// using javax.inject.Inject - slight variation
// using jakarta.inject.Inject - slight variation
public void testBug376590b() {
Map customOptions = getCompilerOptions();
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
Expand All @@ -10744,17 +10744,17 @@ public void testBug376590b() {
JAVAX_INJECT_CONTENT,
"Example.java",
"class Example {\n" +
" private @javax.inject.Inject Object o;\n" +
" private @jakarta.inject.Inject Object o;\n" +
" private Example() {} // also warn here: no @Inject\n" +
" public Example(Object o) { this.o = o; }\n" +
" private @javax.inject.Inject void setO(Object o) { this.o = o;}\n" +
" private @jakarta.inject.Inject void setO(Object o) { this.o = o;}\n" +
"}\n"
},
null, customOptions,
"----------\n" +
"1. ERROR in Example.java (at line 2)\n" +
" private @javax.inject.Inject Object o;\n" +
" ^\n" +
" private @jakarta.inject.Inject Object o;\n" +
" ^\n" +
"The value of the field Example.o is not used\n" +
"----------\n" +
"2. ERROR in Example.java (at line 3)\n" +
Expand All @@ -10765,7 +10765,7 @@ public void testBug376590b() {
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
// https://bugs.eclipse.org/376590 - Private fields with @Inject are ignored by unused field validation
// using javax.inject.Inject, combined with standard as well as custom annotations
// using jakarta.inject.Inject, combined with standard as well as custom annotations
public void testBug376590c() {
Map customOptions = getCompilerOptions();
customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
Expand All @@ -10778,7 +10778,7 @@ public void testBug376590c() {
JAVAX_INJECT_NAME,
JAVAX_INJECT_CONTENT,
"Example.java",
"import javax.inject.Inject;\n" +
"import jakarta.inject.Inject;\n" +
"class Example {\n" +
" private @Inject @p.NonNull Object o; // do warn, annotations don't signal a read\n" +
" private @Deprecated @Inject String old; // do warn, annotations don't signal a read\n" +
Expand Down
Expand Up @@ -4567,7 +4567,7 @@ public void test_nonnull_field_16() {
"----------\n");
}

// Using javax.inject.Inject, slight variations
// Using jakarta.inject.Inject, slight variations
// [compiler] Null analysis for fields does not take @com.google.inject.Inject into account
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=400421
public void test_nonnull_field_17() {
Expand All @@ -4577,7 +4577,7 @@ public void test_nonnull_field_17() {
JAVAX_INJECT_CONTENT,
"X.java",
"import org.eclipse.jdt.annotation.*;\n" +
"import javax.inject.Inject;\n" +
"import jakarta.inject.Inject;\n" +
"public class X {\n" +
" @NonNull @Inject static String s; // warn since injection of static field is less reliable\n" + // variation: static field
" @NonNull @Inject @Deprecated Object o;\n" +
Expand Down Expand Up @@ -8764,29 +8764,29 @@ public void testBug418236() {
}
public void testBug461878() {
Map compilerOptions = getCompilerOptions();
compilerOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "javax.annotation.Nonnull");
compilerOptions.put(JavaCore.COMPILER_NONNULL_ANNOTATION_NAME, "jakarta.annotation.Nonnull");
runNegativeTest(
true, /*flush*/
new String[] {
"javax/annotation/Nonnull.java",
"package javax.annotation;\n" +
"jakarta/annotation/Nonnull.java",
"package jakarta.annotation;\n" +
"import java.lang.annotation.Retention;\n" +
"import java.lang.annotation.RetentionPolicy;\n" +
"@Retention(RetentionPolicy.RUNTIME)\n" +
"public @interface Nonnull {\n" +
"}\n",
"edu/umd/cs/findbugs/annotations/PossiblyNull.java",
"package edu.umd.cs.findbugs.annotations;\n" +
"@javax.annotation.Nonnull // <-- error!!!\n" +
"@jakarta.annotation.Nonnull // <-- error!!!\n" +
"public @interface PossiblyNull {\n" +
"}\n"
},
null, /*libs*/
compilerOptions,
"----------\n" +
"1. WARNING in edu\\umd\\cs\\findbugs\\annotations\\PossiblyNull.java (at line 2)\n" +
" @javax.annotation.Nonnull // <-- error!!!\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
" @jakarta.annotation.Nonnull // <-- error!!!\n" +
" ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"The nullness annotation \'Nonnull\' is not applicable at this location\n" +
"----------\n",
JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings);
Expand Down

0 comments on commit 2e15df5

Please sign in to comment.