-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
<?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> | ||
<parent> | ||
<groupId>nl.jqno.equalsverifier</groupId> | ||
<artifactId>equalsverifier-parent</artifactId> | ||
<version>3.18.1-SNAPSHOT</version> | ||
</parent> | ||
<packaging>jar</packaging> | ||
|
||
<artifactId>equalsverifier-test-kotlin</artifactId> | ||
<name>EqualsVerifier | test Kotlin</name> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-maven-plugin</artifactId> | ||
<version>${version.kotlin}</version> | ||
<executions> | ||
<execution> | ||
<id>compile</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
<configuration> | ||
<sourceDirs> | ||
<source>src/main/kotlin</source> | ||
<source>target/generated-sources/annotations</source> | ||
</sourceDirs> | ||
</configuration> | ||
</execution> | ||
<execution> | ||
<id>test-compile</id> | ||
<phase>test-compile</phase> | ||
<goals> | ||
<goal>test-compile</goal> | ||
</goals> | ||
<configuration> | ||
<sourceDirs> | ||
<source>src/test/kotlin</source> | ||
<source>target/generated-test-sources/test-annotations</source> | ||
</sourceDirs> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<jvmTarget>1.8</jvmTarget> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>default-compile</id> | ||
<phase>none</phase> | ||
</execution> | ||
<execution> | ||
<id>default-testCompile</id> | ||
<phase>none</phase> | ||
</execution> | ||
<execution> | ||
<id>compile</id> | ||
<phase>compile</phase> | ||
<goals> | ||
<goal>compile</goal> | ||
</goals> | ||
</execution> | ||
<execution> | ||
<id>testCompile</id> | ||
<phase>test-compile</phase> | ||
<goals> | ||
<goal>testCompile</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>nl.jqno.equalsverifier</groupId> | ||
<artifactId>equalsverifier-core</artifactId> | ||
<version>${project.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<version>${version.junit-jupiter}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<version>${version.assertj}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-stdlib-jdk8</artifactId> | ||
<version>${version.kotlin}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jetbrains.kotlin</groupId> | ||
<artifactId>kotlin-reflect</artifactId> | ||
<version>${version.kotlin}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
31 changes: 31 additions & 0 deletions
31
...in/src/test/kotlin/nl/jqno/equalsverifier/kotlin/KotlinCompilerGeneratedAnnotationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package nl.jqno.equalsverifier.kotlin | ||
|
||
import nl.jqno.equalsverifier.EqualsVerifier | ||
import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCache | ||
import nl.jqno.equalsverifier.internal.reflection.annotations.AnnotationCacheBuilder | ||
import nl.jqno.equalsverifier.internal.reflection.annotations.SupportedAnnotations | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
|
||
class KotlinCompilerGeneratedAnnotationTest { | ||
|
||
val cache = AnnotationCache() | ||
val cacheBuilder = AnnotationCacheBuilder(SupportedAnnotations.values(), HashSet()) | ||
|
||
@Test | ||
fun `Kotlin classes are recognised as such`() { | ||
assertThat(checkAnnotationFor(KotlinClass::class.java)).isTrue() | ||
} | ||
|
||
@Test | ||
fun `Java classes are not recognised as Kotlin classes`() { | ||
assertThat(checkAnnotationFor(EqualsVerifier::class.java)).isFalse() | ||
} | ||
|
||
private fun checkAnnotationFor(type: Class<*>): Boolean { | ||
cacheBuilder.build(type, cache) | ||
return cache.hasClassAnnotation(type, SupportedAnnotations.KOTLIN) | ||
} | ||
} | ||
|
||
class KotlinClass |
38 changes: 38 additions & 0 deletions
38
...fier-test-kotlin/src/test/kotlin/nl/jqno/equalsverifier/kotlin/KotlinFieldIterableTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package nl.jqno.equalsverifier.kotlin | ||
|
||
import org.junit.jupiter.api.Test | ||
import java.lang.reflect.Field | ||
import nl.jqno.equalsverifier.internal.reflection.FieldIterable | ||
import org.assertj.core.api.Assertions.assertThat | ||
|
||
class KotlinFieldIterableTest { | ||
val actual = HashSet<Field>() | ||
|
||
@Test | ||
fun `FieldIterable ofKotlin ignores superclass backing fields`() { | ||
actual.addAll(FieldIterable.ofKotlin(ImplementingDataClass::class.java).map { it.getField() }) | ||
|
||
assertThat(actual) | ||
.isEqualTo(setOf( | ||
Base::class.java.getDeclaredField("base"), | ||
ImplementingDataClass::class.java.getDeclaredField("toOverride"))) | ||
} | ||
|
||
@Test | ||
fun `FieldIterable of does not ignore superclass backing fields`() { | ||
actual.addAll(FieldIterable.of(ImplementingDataClass::class.java).map { it.getField() }) | ||
|
||
assertThat(actual) | ||
.isEqualTo(setOf( | ||
Base::class.java.getDeclaredField("base"), | ||
Base::class.java.getDeclaredField("toOverride"), | ||
ImplementingDataClass::class.java.getDeclaredField("toOverride"))) | ||
} | ||
|
||
sealed class Base( | ||
internal open val base: Int, | ||
internal open val toOverride: Int, | ||
) | ||
|
||
data class ImplementingDataClass(override val toOverride: Int) : Base(42, toOverride) | ||
} |
39 changes: 39 additions & 0 deletions
39
...rifier-test-kotlin/src/test/kotlin/nl/jqno/equalsverifier/kotlin/KotlinIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package nl.jqno.equalsverifier.kotlin | ||
|
||
import java.util.Objects | ||
import nl.jqno.equalsverifier.EqualsVerifier | ||
import org.junit.jupiter.api.Test | ||
|
||
class KotlinIntegrationTest { | ||
@Test | ||
fun `super's backing field does not affect implementing data class`() { | ||
EqualsVerifier.forClass(ImplementingDataClass::class.java) | ||
.withIgnoredFields("base") | ||
.verify() | ||
} | ||
|
||
@Test | ||
fun `super's backing field does not affect implementing regular class`() { | ||
EqualsVerifier.forClass(ImplementingRegularClass::class.java) | ||
.verify() | ||
} | ||
|
||
sealed class Base( | ||
internal open val base: Int, | ||
internal open val toOverride: Int, | ||
) | ||
|
||
data class ImplementingDataClass(override val toOverride: Int) : Base(42, toOverride) | ||
|
||
class ImplementingRegularClass(override val toOverride: Int) : Base(42, toOverride) { | ||
override fun equals(other: Any?): Boolean { | ||
return other is ImplementingRegularClass | ||
&& base == other.base | ||
&& toOverride == other.toOverride | ||
} | ||
|
||
override fun hashCode(): Int { | ||
return Objects.hash(base, toOverride) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters