Add integration tests for 1adc2426

#KT-29346 Fixed
This commit is contained in:
Aleksei.Cherepanov
2022-11-14 18:29:22 +01:00
parent 504fcd5b71
commit fb38ab3cbb
16 changed files with 306 additions and 0 deletions
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jetbrains.kotlin.examples</groupId>
<artifactId>test-enable-extensions-kapt-allopen</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<junit.version>4.13.1</junit.version>
<main.class>coffee.CoffeeApp</main.class>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.version>1.8.255-SNAPSHOT</kotlin.version>
</properties>
<dependencies>
<dependency>
<groupId>com.google.dagger</groupId>
<artifactId>dagger</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<extensions>true</extensions>
<configuration>
<compilerPlugins>
<plugin>all-open</plugin>
</compilerPlugins>
<pluginOptions>
<option>all-open:annotation=coffee.AllOpen</option>
</pluginOptions>
<annotationProcessorPaths>
<annotationProcessorPath>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.9</version>
</annotationProcessorPath>
</annotationProcessorPaths>
<sourceDirs>
<sourceDir>src/main/kotlin</sourceDir>
<sourceDir>src/main/java</sourceDir>
</sourceDirs>
</configuration>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<proc>none</proc>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,8 @@
package coffee
annotation class AllOpen
@AllOpen
class MyClass
class MyClass2 : MyClass()
@@ -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<String>) {
val coffee = DaggerCoffeeApp_Coffee.builder().build()
coffee.maker().brew()
}
}
@@ -0,0 +1,17 @@
package coffee
import dagger.Lazy
import javax.inject.Inject
class CoffeeMaker @Inject constructor(
private val heater: Lazy<Heater>,
private val pump: Pump
) {
fun brew() {
heater.get().on()
pump.pump()
println(" [_]P coffee! [_]P ")
heater.get().off()
}
}
@@ -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()
}
}
@@ -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
}
}
@@ -0,0 +1,7 @@
package coffee
interface Heater {
fun on()
fun off()
val isHot: Boolean
}
@@ -0,0 +1,5 @@
package coffee
interface Pump {
fun pump()
}
@@ -0,0 +1,10 @@
package coffee
import dagger.Binds
import dagger.Module
@Module
abstract class PumpModule {
@Binds
abstract fun providePump(pump: Thermosiphon): Pump
}
@@ -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 => =>")
}
}
}
@@ -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)
}
}
@@ -0,0 +1,11 @@
import java.io.*;
File file = new File(basedir, "target/test-enable-extensions-kapt-allopen-1.0-SNAPSHOT.jar");
if (!file.exists() || !file.isFile()) {
throw new FileNotFoundException("Could not find generated JAR: " + file);
}
File generatedFile = new File(basedir, "target/generated-sources/kapt/compile/coffee/CoffeeMaker_Factory.java");
if (!generatedFile.exists() || !generatedFile.isFile()) {
throw new FileNotFoundException("Kapt was not executed, file is absent: " + generatedFile);
}
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>test-enable-extensions</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<extensions>true</extensions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,10 @@
package org.jetbrains
fun main(args : Array<String>) {
System.out?.println(getGreeting())
}
fun getGreeting() : String {
return "Hello, World!"
}
@@ -0,0 +1,13 @@
package org.jetbrains;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
public class HelloWorldJavaTest {
@Test
public void greeting() {
assertEquals("Hello, World!", org.jetbrains.HelloWorldKt.getGreeting());
}
}
@@ -0,0 +1,6 @@
import java.io.*;
File file = new File(basedir, "target/test-enable-extensions-1.0-SNAPSHOT.jar");
if (!file.exists() || !file.isFile()) {
throw new FileNotFoundException("Could not find generated JAR: " + file);
}