Repository: square/AssistedInject
Pull request #104 (2019-08-05 14:39:51)

Add support for testing on JDK 9+


Patch:
diff --git a/assisted-inject-processor-dagger2/build.gradle b/assisted-inject-processor-dagger2/build.gradle
index 1c72c7c..5614b4a 100644
--- a/assisted-inject-processor-dagger2/build.gradle
+++ b/assisted-inject-processor-dagger2/build.gradle
@@ -24,7 +24,9 @@ dependencies {
   testImplementation deps.truth
   testImplementation deps.compileTesting
   testImplementation deps.dagger
-  testImplementation files(Jvm.current().getToolsJar())
+  if (!Jvm.current().javaVersion.isJava9Compatible()) {
+    testImplementation files(Jvm.current().getToolsJar())
+  }
 }
 
 apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
diff --git a/assisted-inject-processor/build.gradle b/assisted-inject-processor/build.gradle
index 2f9bff9..7fe68da 100644
--- a/assisted-inject-processor/build.gradle
+++ b/assisted-inject-processor/build.gradle
@@ -24,7 +24,9 @@ dependencies {
   testImplementation deps.truth
   testImplementation deps.compileTesting
   testImplementation deps.inject
-  testImplementation files(Jvm.current().getToolsJar())
+  if (!Jvm.current().javaVersion.isJava9Compatible()) {
+    testImplementation files(Jvm.current().getToolsJar())
+  }
 }
 
 apply from: rootProject.file('gradle/gradle-mvn-push.gradle')
diff --git a/inflation-inject-processor/build.gradle b/inflation-inject-processor/build.gradle
index 23b702a..e458aa3 100644
--- a/inflation-inject-processor/build.gradle
+++ b/inflation-inject-processor/build.gradle
@@ -21,7 +21,9 @@ dependencies {
   testImplementation deps.compileTesting
   testImplementation deps.android
   testImplementation deps.dagger
-  testImplementation files(Jvm.current().getToolsJar())
+  if (!Jvm.current().javaVersion.isJava9Compatible()) {
+    testImplementation files(Jvm.current().getToolsJar())
+  }
 }
 
 apply from: rootProject.file('gradle/gradle-mvn-push.gradle')


Test patch:
diff --git a/assisted-inject-processor-dagger2/src/test/java/com/squareup/inject/assisted/dagger2/processor/AssistedInjectDagger2ProcessorTest.kt b/assisted-inject-processor-dagger2/src/test/java/com/squareup/inject/assisted/dagger2/processor/AssistedInjectDagger2ProcessorTest.kt
index 8731b35..aea3b43 100644
--- a/assisted-inject-processor-dagger2/src/test/java/com/squareup/inject/assisted/dagger2/processor/AssistedInjectDagger2ProcessorTest.kt
+++ b/assisted-inject-processor-dagger2/src/test/java/com/squareup/inject/assisted/dagger2/processor/AssistedInjectDagger2ProcessorTest.kt
@@ -22,7 +22,13 @@ import com.google.testing.compile.JavaSourcesSubjectFactory.javaSources
 import org.junit.Ignore
 import org.junit.Test
 
-private const val GENERATED_TYPE = "javax.annotation.Generated" // TODO vary once JDK 9 works.
+private val GENERATED_TYPE = try {
+  Class.forName("javax.annotation.processing.Generated")
+  "javax.annotation.processing.Generated"
+} catch (_: ClassNotFoundException) {
+  "javax.annotation.Generated"
+}
+
 private const val GENERATED_ANNOTATION = """
 @Generated(
   value = "com.squareup.inject.assisted.dagger2.processor.AssistedInjectDagger2Processor",
diff --git a/assisted-inject-processor/src/test/java/com/squareup/inject/assisted/processor/AssistedInjectProcessorTest.kt b/assisted-inject-processor/src/test/java/com/squareup/inject/assisted/processor/AssistedInjectProcessorTest.kt
index 255cdd9..49d8d8c 100644
--- a/assisted-inject-processor/src/test/java/com/squareup/inject/assisted/processor/AssistedInjectProcessorTest.kt
+++ b/assisted-inject-processor/src/test/java/com/squareup/inject/assisted/processor/AssistedInjectProcessorTest.kt
@@ -22,7 +22,13 @@ import com.google.testing.compile.JavaSourcesSubjectFactory.javaSources
 import org.junit.Ignore
 import org.junit.Test
 
-private const val GENERATED_TYPE = "javax.annotation.Generated" // TODO vary once JDK 9 works.
+private val GENERATED_TYPE = try {
+  Class.forName("javax.annotation.processing.Generated")
+  "javax.annotation.processing.Generated"
+} catch (_: ClassNotFoundException) {
+  "javax.annotation.Generated"
+}
+
 private const val GENERATED_ANNOTATION = """
 @Generated(
   value = "com.squareup.inject.assisted.processor.AssistedInjectProcessor",
diff --git a/inflation-inject-processor/src/test/java/com/squareup/inject/inflation/processor/InflationInjectProcessorTest.kt b/inflation-inject-processor/src/test/java/com/squareup/inject/inflation/processor/InflationInjectProcessorTest.kt
index 18f8e2f..1263919 100644
--- a/inflation-inject-processor/src/test/java/com/squareup/inject/inflation/processor/InflationInjectProcessorTest.kt
+++ b/inflation-inject-processor/src/test/java/com/squareup/inject/inflation/processor/InflationInjectProcessorTest.kt
@@ -7,7 +7,13 @@ import com.google.testing.compile.JavaSourcesSubjectFactory.javaSources
 import org.junit.Ignore
 import org.junit.Test
 
-private const val GENERATED_TYPE = "javax.annotation.Generated" // TODO vary once JDK 9 works.
+private val GENERATED_TYPE = try {
+  Class.forName("javax.annotation.processing.Generated")
+  "javax.annotation.processing.Generated"
+} catch (_: ClassNotFoundException) {
+  "javax.annotation.Generated"
+}
+
 private const val GENERATED_ANNOTATION = """
 @Generated(
   value = "com.squareup.inject.inflation.processor.InflationInjectProcessor",