Skip to content

Commit

Permalink
Support for Kotlin tests (#949)
Browse files Browse the repository at this point in the history
  • Loading branch information
theigl committed Apr 5, 2023
1 parent e7c37a9 commit 96259c7
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
61 changes: 61 additions & 0 deletions pom.xml
Expand Up @@ -52,6 +52,8 @@
<javac.target>1.8</javac.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.9.2</junit.version>
<kotlin.version>1.8.20</kotlin.version>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
</properties>

<modules>
Expand Down Expand Up @@ -339,6 +341,63 @@
</plugins>
</build>
</profile>
<!-- Include any tests that require kotlin -->
<profile>
<id>kotlin</id>
<activation>
<property>
<name>!skipKotlin</name>
</property>
</activation>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>test-kotlin</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<!-- Include any tests that require JDK11+ -->
<profile>
<id>jdk11ge</id>
Expand All @@ -360,6 +419,7 @@
</goals>
<configuration>
<sources>
<source>test-kotlin</source>
<source>test-jdk11</source>
</sources>
</configuration>
Expand Down Expand Up @@ -406,6 +466,7 @@
</goals>
<configuration>
<sources>
<source>test-kotlin</source>
<source>test-jdk11</source>
<source>test-jdk14</source>
</sources>
Expand Down
37 changes: 37 additions & 0 deletions test-kotlin/com.esotericsoftware.kryo/LambdaTest.kt
@@ -0,0 +1,37 @@
package com.esotericsoftware.kryo

import com.esotericsoftware.kryo.io.Input
import com.esotericsoftware.kryo.io.Output
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotSame
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test

class LambdaTest {
class Example(private val p: (Long) -> String) {
constructor() : this({ it.toString() })
}

@Test
@Disabled("Expected to fail")
fun testLambda() {
val kryo = Kryo().apply {
isRegistrationRequired = false
}

val example = Example()

val bytes = Output(1024).use { output ->
kryo.writeClassAndObject(output, example)
output.toBytes()
}

val deserialized = Input(bytes).use { input ->
kryo.readClassAndObject(input)
}

assertEquals(example::class.java, deserialized::class.java)
assertNotSame(example, deserialized)
}
}

0 comments on commit 96259c7

Please sign in to comment.