Skip to content

Commit 68e8357

Browse files
committed
update tests
1 parent 5cf579f commit 68e8357

File tree

3 files changed

+66
-18
lines changed

3 files changed

+66
-18
lines changed

processor/src/test/kotlin/com/tobrun/datacompat/DataCompatProcessorTest.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,21 @@ import com.tschuchort.compiletesting.SourceFile
99
import com.tschuchort.compiletesting.symbolProcessorProviders
1010
import io.kotest.core.spec.style.BehaviorSpec
1111
import io.kotest.matchers.shouldBe
12+
import java.io.File
1213

1314
private val simpleTest = SourceFile.kotlin(
1415
"PersonData.kt",
1516
"""
1617
import com.tobrun.datacompat.annotation.DataCompat
1718
19+
/**
20+
* Represents a person.
21+
* @property name The full name.
22+
* @property nickname The nickname.
23+
* @property age The age.
24+
*/
1825
@DataCompat
19-
private data class PersonData(
20-
val name: String,
21-
val nickname: String? = null,
22-
val age: Int,
23-
)
26+
private data class PersonData(val name: String, val nickname: String? = null, val age: Int)
2427
""".trimIndent()
2528
)
2629

processor/src/test/kotlin/com/tobrun/datacompat/SimpleTestContent.kt

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,46 +8,86 @@ internal val expectedSimpleTestContent = """
88
import kotlin.String
99
import kotlin.Unit
1010
import kotlin.jvm.JvmSynthetic
11-
11+
12+
/**
13+
* Represents a person.
14+
* @property name The full name.
15+
* @property nickname The nickname.
16+
* @property age The age.
17+
*/
1218
public class Person private constructor(
1319
public val name: String,
1420
public val nickname: String?,
1521
public val age: Int
1622
) {
1723
public override fun toString() = "Person(name=%name, nickname=%nickname, age=%age)"
18-
24+
1925
public override fun equals(other: Any?): Boolean = other is Person
2026
&& name == other.name
2127
&& nickname == other.nickname
2228
&& age == other.age
23-
29+
2430
public override fun hashCode(): Int = Objects.hash(name, nickname, age)
25-
31+
32+
/**
33+
* Composes and builds a [Person] object.
34+
*
35+
* This is a concrete implementation of the builder design pattern.
36+
*
37+
* @property name The full name.
38+
* @property nickname The nickname.
39+
* @property age The age.
40+
*/
2641
public class Builder {
2742
@set:JvmSynthetic
2843
public var name: String? = null
29-
44+
3045
@set:JvmSynthetic
3146
public var nickname: String? = null
32-
47+
3348
@set:JvmSynthetic
3449
public var age: Int? = null
35-
50+
51+
/**
52+
* Set the full name.
53+
*
54+
* @param name the full name.
55+
* @return Builder
56+
*/
3657
public fun setName(name: String?): Builder {
3758
this.name = name
3859
return this
3960
}
40-
61+
62+
/**
63+
* Set the nickname.
64+
*
65+
* @param nickname the nickname.
66+
* @return Builder
67+
*/
4168
public fun setNickname(nickname: String?): Builder {
4269
this.nickname = nickname
4370
return this
4471
}
45-
72+
73+
/**
74+
* Set the age.
75+
*
76+
* @param age the age.
77+
* @return Builder
78+
*/
4679
public fun setAge(age: Int?): Builder {
4780
this.age = age
4881
return this
4982
}
50-
83+
84+
/**
85+
* Returns a [Person] reference to the object being constructed by the builder.
86+
*
87+
* Throws an [IllegalArgumentException] when a non-null property wasn't initialised.
88+
*
89+
* @return Person
90+
*/
5191
public fun build(): Person {
5292
if (name==null) {
5393
throw IllegalArgumentException("Null name found when building Person.")
@@ -59,7 +99,13 @@ internal val expectedSimpleTestContent = """
5999
}
60100
}
61101
}
62-
102+
103+
/**
104+
* Creates a [Person] through a DSL-style builder.
105+
*
106+
* @param initializer the intialisation block
107+
* @return Person
108+
*/
63109
@JvmSynthetic
64110
public fun Person(initializer: Person.Builder.() -> Unit): Person =
65111
Person.Builder().apply(initializer).build()

processor/src/test/kotlin/com/tobrun/datacompat/utils/KotlinCompilationExt.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.tobrun.datacompat.utils
22

33
import com.tschuchort.compiletesting.KotlinCompilation
44
import java.io.File
5-
import java.nio.file.Files
65

76
internal val KotlinCompilation.Result.kspGeneratedSources: List<File>
87
get() {
@@ -14,7 +13,7 @@ internal val KotlinCompilation.Result.kspGeneratedSources: List<File>
1413
}
1514

1615
internal fun KotlinCompilation.Result.getGeneratedSource(index: Int): String {
17-
return Files.readString(kspGeneratedSources[index].toPath())
16+
return File(kspGeneratedSources[index].toPath().toString()).readText()
1817
}
1918

2019
private val KotlinCompilation.Result.workingDir: File

0 commit comments

Comments
 (0)