From eba5baa7ff251017c442e24c23abb576920bb24b Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Wed, 26 Apr 2017 16:35:08 +0300 Subject: [PATCH] Kapt3: Add Maven integration test --- .../src/it/test-dagger-maven-example/pom.xml | 146 ++++++++++++++++++ .../src/main/kotlin/CoffeeApp.kt | 18 +++ .../src/main/kotlin/CoffeeMaker.kt | 17 ++ .../src/main/kotlin/DripCoffeeModule.kt | 13 ++ .../src/main/kotlin/ElectricHeater.kt | 14 ++ .../src/main/kotlin/Heater.kt | 7 + .../src/main/kotlin/Pump.kt | 5 + .../src/main/kotlin/PumpModule.kt | 10 ++ .../src/main/kotlin/Thermosiphon.kt | 12 ++ .../test/kotlin/hello/tests/ExampleTest.kt | 39 +++++ .../it/test-dagger-maven-example/verify.bsh | 6 + 11 files changed, 287 insertions(+) create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/pom.xml create mode 100755 libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/CoffeeApp.kt create mode 100755 libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/CoffeeMaker.kt create mode 100755 libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/DripCoffeeModule.kt create mode 100755 libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/ElectricHeater.kt create mode 100755 libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/Heater.kt create mode 100755 libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/Pump.kt create mode 100755 libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/PumpModule.kt create mode 100755 libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/Thermosiphon.kt create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/test/kotlin/hello/tests/ExampleTest.kt create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/verify.bsh diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/pom.xml new file mode 100644 index 00000000000..a82a7302c46 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/pom.xml @@ -0,0 +1,146 @@ + + + + 4.0.0 + + org.jetbrains.kotlin.examples + dagger-maven-example + 1.0-SNAPSHOT + + + 1.1-SNAPSHOT + 4.12 + coffee.CoffeeApp + UTF-8 + + + + + com.google.dagger + dagger + 2.9 + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + junit + junit + ${junit.version} + test + + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + kapt + + kapt + + + + src/main/kotlin + src/main/java + + + + com.google.dagger + dagger-compiler + 2.9 + + + + + + compile + + compile + + + + src/main/kotlin + src/main/java + + + + + test-kapt + + test-kapt + + + + src/test/kotlin + src/test/java + + + + com.google.dagger + dagger-compiler + 2.9 + + + + + + test-compile + + test-compile + + + + src/test/kotlin + src/test/java + target/generated-sources/kapt/test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + none + 1.6 + 1.6 + + + + + default-compile + none + + + + default-testCompile + none + + + java-compile + compile + + compile + + + + java-test-compile + test-compile + testCompile + + + + + + diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/CoffeeApp.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/CoffeeApp.kt new file mode 100755 index 00000000000..9e1d910ef48 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/CoffeeApp.kt @@ -0,0 +1,18 @@ +package coffee + +import dagger.Component +import javax.inject.Singleton + +object CoffeeApp { + @Singleton + @Component(modules = arrayOf(DripCoffeeModule::class)) + interface Coffee { + fun maker(): CoffeeMaker + } + + @JvmStatic + fun main(args: Array) { + val coffee = DaggerCoffeeApp_Coffee.builder().build() + coffee.maker().brew() + } +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/CoffeeMaker.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/CoffeeMaker.kt new file mode 100755 index 00000000000..58e9de6e830 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/CoffeeMaker.kt @@ -0,0 +1,17 @@ +package coffee + +import dagger.Lazy +import javax.inject.Inject + +class CoffeeMaker @Inject constructor( + private val heater: Lazy, + private val pump: Pump +) { + + fun brew() { + heater.get().on() + pump.pump() + println(" [_]P coffee! [_]P ") + heater.get().off() + } +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/DripCoffeeModule.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/DripCoffeeModule.kt new file mode 100755 index 00000000000..a8c1dae2071 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/DripCoffeeModule.kt @@ -0,0 +1,13 @@ +package coffee + +import dagger.Module +import dagger.Provides +import javax.inject.Singleton + +@Module(includes = arrayOf(PumpModule::class)) +class DripCoffeeModule { + @Provides @Singleton + fun provideHeater(): Heater { + return ElectricHeater() + } +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/ElectricHeater.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/ElectricHeater.kt new file mode 100755 index 00000000000..6c1f1586a40 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/ElectricHeater.kt @@ -0,0 +1,14 @@ +package coffee + +open class ElectricHeater : Heater { + override var isHot: Boolean = false + + override fun on() { + println("~ ~ ~ heating ~ ~ ~") + this.isHot = true + } + + override fun off() { + this.isHot = false + } +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/Heater.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/Heater.kt new file mode 100755 index 00000000000..f2ec5dabcc8 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/Heater.kt @@ -0,0 +1,7 @@ +package coffee + +interface Heater { + fun on() + fun off() + val isHot: Boolean +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/Pump.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/Pump.kt new file mode 100755 index 00000000000..5c454538984 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/Pump.kt @@ -0,0 +1,5 @@ +package coffee + +interface Pump { + fun pump() +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/PumpModule.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/PumpModule.kt new file mode 100755 index 00000000000..a892e2b7700 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/PumpModule.kt @@ -0,0 +1,10 @@ +package coffee + +import dagger.Binds +import dagger.Module + +@Module +abstract class PumpModule { + @Binds + abstract fun providePump(pump: Thermosiphon): Pump +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/Thermosiphon.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/Thermosiphon.kt new file mode 100755 index 00000000000..09c84cff056 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/main/kotlin/Thermosiphon.kt @@ -0,0 +1,12 @@ +package coffee + +import javax.inject.Inject + +class Thermosiphon @Inject +constructor(private val heater: Heater) : Pump { + override fun pump() { + if (heater.isHot) { + println("=> => pumping => =>") + } + } +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/test/kotlin/hello/tests/ExampleTest.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/test/kotlin/hello/tests/ExampleTest.kt new file mode 100644 index 00000000000..9b3f523e866 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/src/test/kotlin/hello/tests/ExampleTest.kt @@ -0,0 +1,39 @@ +package hello.tests + +import coffee.* +import dagger.Component +import dagger.Module +import dagger.Provides +import junit.framework.TestCase +import javax.inject.Singleton + +private var executed = false + +class ExampleTest : TestCase() { + @Singleton + @Component(modules = arrayOf(TestCoffeeModule::class)) + interface Coffee { + fun maker(): CoffeeMaker + } + + @Module(includes = arrayOf(PumpModule::class)) + class TestCoffeeModule { + @Provides @Singleton + fun provideHeater(): Heater { + return object: ElectricHeater() { + override fun on() { + println("~ psh ~ psh ~ psh ~") + println("(from tests)") + executed = true + super.on() + } + } + } + } + + fun testAssert() { + val coffee = DaggerExampleTest_Coffee.builder().build() + coffee.maker().brew() + assert(executed) + } +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/verify.bsh new file mode 100644 index 00000000000..d50eab3e1cc --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/test-dagger-maven-example/verify.bsh @@ -0,0 +1,6 @@ +import java.io.*; + +File file = new File(basedir, "target/dagger-maven-example-1.0-SNAPSHOT.jar"); +if (!file.exists() || !file.isFile()) { + throw new FileNotFoundException("Could not find generated JAR: " + file); +}