summaryrefslogtreecommitdiff
path: root/guide/test/PolymorphismTest.kt
blob: e82dd6892e30649d9b09acc1ca943b299ff4b828 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// This file was automatically generated from polymorphism.md by Knit tool. Do not edit.
package example.test

import org.junit.Test
import kotlinx.knit.test.*

class PolymorphismTest {
    @Test
    fun testExamplePoly01() {
        captureOutput("ExamplePoly01") { example.examplePoly01.main() }.verifyOutputLines(
            "{\"name\":\"kotlinx.coroutines\"}"
        )
    }

    @Test
    fun testExamplePoly02() {
        captureOutput("ExamplePoly02") { example.examplePoly02.main() }.verifyOutputLinesStart(
            "Exception in thread \"main\" kotlinx.serialization.SerializationException: Serializer for class 'OwnedProject' is not found.",
            "Mark the class as @Serializable or provide the serializer explicitly."
        )
    }

    @Test
    fun testExamplePoly03() {
        captureOutput("ExamplePoly03") { example.examplePoly03.main() }.verifyOutputLinesStart(
            "Exception in thread \"main\" kotlinx.serialization.SerializationException: Class 'OwnedProject' is not registered for polymorphic serialization in the scope of 'Project'.",
            "Mark the base class as 'sealed' or register the serializer explicitly."
        )
    }

    @Test
    fun testExamplePoly04() {
        captureOutput("ExamplePoly04") { example.examplePoly04.main() }.verifyOutputLines(
            "{\"type\":\"example.examplePoly04.OwnedProject\",\"name\":\"kotlinx.coroutines\",\"owner\":\"kotlin\"}"
        )
    }

    @Test
    fun testExamplePoly05() {
        captureOutput("ExamplePoly05") { example.examplePoly05.main() }.verifyOutputLines(
            "{\"name\":\"kotlinx.coroutines\",\"owner\":\"kotlin\"}"
        )
    }

    @Test
    fun testExamplePoly06() {
        captureOutput("ExamplePoly06") { example.examplePoly06.main() }.verifyOutputLines(
            "{\"type\":\"owned\",\"name\":\"kotlinx.coroutines\",\"owner\":\"kotlin\"}"
        )
    }

    @Test
    fun testExamplePoly07() {
        captureOutput("ExamplePoly07") { example.examplePoly07.main() }.verifyOutputLines(
            "{\"type\":\"owned\",\"status\":\"open\",\"name\":\"kotlinx.coroutines\",\"owner\":\"kotlin\"}"
        )
    }

    @Test
    fun testExamplePoly08() {
        captureOutput("ExamplePoly08") { example.examplePoly08.main() }.verifyOutputLines(
            "[{\"type\":\"example.examplePoly08.EmptyResponse\"},{\"type\":\"example.examplePoly08.TextResponse\",\"text\":\"OK\"}]"
        )
    }

    @Test
    fun testExamplePoly09() {
        captureOutput("ExamplePoly09") { example.examplePoly09.main() }.verifyOutputLines(
            "{\"type\":\"owned\",\"name\":\"kotlinx.coroutines\",\"owner\":\"kotlin\"}"
        )
    }

    @Test
    fun testExamplePoly10() {
        captureOutput("ExamplePoly10") { example.examplePoly10.main() }.verifyOutputLinesStart(
            "{\"type\":\"owned\",\"name\":\"kotlinx.coroutines\",\"owner\":\"kotlin\"}"
        )
    }

    @Test
    fun testExamplePoly11() {
        captureOutput("ExamplePoly11") { example.examplePoly11.main() }.verifyOutputLines(
            "{\"project\":{\"type\":\"owned\",\"name\":\"kotlinx.coroutines\",\"owner\":\"kotlin\"}}"
        )
    }

    @Test
    fun testExamplePoly12() {
        captureOutput("ExamplePoly12") { example.examplePoly12.main() }.verifyOutputLinesStart(
            "Exception in thread \"main\" kotlinx.serialization.SerializationException: Serializer for class 'Any' is not found.",
            "Mark the class as @Serializable or provide the serializer explicitly."
        )
    }

    @Test
    fun testExamplePoly13() {
        captureOutput("ExamplePoly13") { example.examplePoly13.main() }.verifyOutputLinesStart(
            "Exception in thread \"main\" kotlinx.serialization.SerializationException: Serializer for class 'Any' is not found.",
            "Mark the class as @Serializable or provide the serializer explicitly."
        )
    }

    @Test
    fun testExamplePoly14() {
        captureOutput("ExamplePoly14") { example.examplePoly14.main() }.verifyOutputLines(
            "{\"type\":\"owned\",\"name\":\"kotlinx.coroutines\",\"owner\":\"kotlin\"}"
        )
    }

    @Test
    fun testExamplePoly15() {
        captureOutput("ExamplePoly15") { example.examplePoly15.main() }.verifyOutputLines(
            "{\"project\":{\"type\":\"owned\",\"name\":\"kotlinx.coroutines\",\"owner\":\"kotlin\"}}"
        )
    }

    @Test
    fun testExamplePoly16() {
        captureOutput("ExamplePoly16") { example.examplePoly16.main() }.verifyOutputLines(
            "{\"project\":{\"type\":\"owned\",\"name\":\"kotlinx.coroutines\",\"owner\":\"kotlin\"},\"any\":{\"type\":\"owned\",\"name\":\"kotlinx.coroutines\",\"owner\":\"kotlin\"}}"
        )
    }

    @Test
    fun testExamplePoly17() {
        captureOutput("ExamplePoly17") { example.examplePoly17.main() }.verifyOutputLines(
            "{\"type\":\"OkResponse\",\"data\":{\"type\":\"OwnedProject\",\"name\":\"kotlinx.serialization\",\"owner\":\"kotlin\"}}",
            "OkResponse(data=OwnedProject(name=kotlinx.serialization, owner=kotlin))"
        )
    }

    @Test
    fun testExamplePoly18() {
        captureOutput("ExamplePoly18") { example.examplePoly18.main() }.verifyOutputLinesStart(
            "Exception in thread \"main\" kotlinx.serialization.json.internal.JsonDecodingException: Polymorphic serializer was not found for class discriminator 'unknown'"
        )
    }

    @Test
    fun testExamplePoly19() {
        captureOutput("ExamplePoly19") { example.examplePoly19.main() }.verifyOutputLines(
            "[BasicProject(name=example, type=unknown), OwnedProject(name=kotlinx.serialization, owner=kotlin)]"
        )
    }

    @Test
    fun testExamplePoly20() {
        captureOutput("ExamplePoly20") { example.examplePoly20.main() }.verifyOutputLines(
            "{\"type\":\"Cat\",\"catType\":\"Tabby\"}"
        )
    }
}