You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/test/kotlin/com/github/ivy/explicit/rule/DataClassTypedIDsRuleRuleTest.kt
+81
Original file line number
Diff line number
Diff line change
@@ -26,4 +26,85 @@ internal class DataClassTypedIDsRuleRuleTest(private val env: KotlinCoreEnvironm
26
26
Data class 'A' should use type-safe IDs instead of UUID for property 'id'. Typed-IDs like `value class SomeId(val id: UUID)` provide compile-time safety and prevent mixing IDs of different entities.
27
27
""".trimIndent()
28
28
}
29
+
30
+
@Test
31
+
fun`reports data class having String as id`() {
32
+
val code ="""
33
+
data class A(
34
+
val id: String,
35
+
)
36
+
"""
37
+
val findings =DataClassTypedIDsRule(Config.empty).compileAndLintWithContext(env, code)
38
+
findings shouldHaveSize 1
39
+
}
40
+
41
+
@Test
42
+
fun`reports data class having transactionId Int`() {
43
+
val code ="""
44
+
data class A(
45
+
val name: String,
46
+
val transactionId: Int
47
+
)
48
+
"""
49
+
val findings =DataClassTypedIDsRule(Config.empty).compileAndLintWithContext(env, code)
50
+
findings shouldHaveSize 1
51
+
}
52
+
53
+
@Test
54
+
fun`doesn't report data class without ids`() {
55
+
val code ="""
56
+
data class Person(
57
+
val firstName: String,
58
+
val lastName: String,
59
+
)
60
+
"""
61
+
val findings =DataClassTypedIDsRule(Config.empty).compileAndLintWithContext(env, code)
62
+
findings shouldHaveSize 0
63
+
}
64
+
65
+
@Test
66
+
fun`doesn't report Dto classes`() {
67
+
val code ="""
68
+
data class SomeDto(
69
+
val id: UUID
70
+
)
71
+
"""
72
+
val findings =DataClassTypedIDsRule(Config.empty).compileAndLintWithContext(env, code)
73
+
findings shouldHaveSize 0
74
+
}
75
+
76
+
@Test
77
+
fun`doesn't report Entity classes`() {
78
+
val code ="""
79
+
data class SomeEntity(
80
+
val id: UUID
81
+
)
82
+
"""
83
+
val findings =DataClassTypedIDsRule(Config.empty).compileAndLintWithContext(env, code)
84
+
findings shouldHaveSize 0
85
+
}
86
+
87
+
@Test
88
+
fun`doesn't report classes annotated with @Entity`() {
89
+
val code ="""
90
+
@Entity(tableName = "budgets")
91
+
data class A(
92
+
val id: UUID
93
+
)
94
+
"""
95
+
val findings =DataClassTypedIDsRule(Config.empty).compileAndLintWithContext(env, code)
96
+
findings shouldHaveSize 0
97
+
}
98
+
99
+
@Test
100
+
fun`doesn't report classes annotated with @Serializable`() {
101
+
val code ="""
102
+
@Serializable
103
+
data class A(
104
+
val id: UUID
105
+
)
106
+
"""
107
+
val findings =DataClassTypedIDsRule(Config.empty).compileAndLintWithContext(env, code)
0 commit comments