16
16
package com.toasttab.protokt.testing.options
17
17
18
18
import com.google.common.truth.Truth.assertThat
19
+ import com.toasttab.protokt.testing.options.OneofWrappers.WrappedOneof
19
20
import java.net.InetAddress
20
21
import java.net.InetSocketAddress
21
22
import java.time.Duration
22
23
import java.time.Instant
24
+ import java.time.LocalDate
23
25
import java.util.UUID
24
26
import org.junit.jupiter.api.Test
25
27
import org.junit.jupiter.api.assertThrows
@@ -34,6 +36,7 @@ class WrapperTypesTest {
34
36
socketAddress = InetSocketAddress (InetAddress .getLocalHost(), 8080 )
35
37
instant = Instant .now()
36
38
duration = Duration .ofSeconds(5 )
39
+ localDate = LocalDate .of(1950 , 10 , 4 )
37
40
}
38
41
39
42
@Test
@@ -84,70 +87,116 @@ class WrapperTypesTest {
84
87
}
85
88
86
89
@Test
87
- fun `round trip should preserve generic wrapper oneof` () {
90
+ fun `round trip should preserve localdate` () {
91
+ val deserialized = Wrappers .deserialize(model.serialize())
92
+
93
+ assertThat(deserialized.localDate).isEqualTo(model.localDate)
94
+ }
95
+
96
+ @Test
97
+ fun `round trip should preserve id oneof` () {
88
98
val deserialized = OneofWrappers .deserialize(
89
99
OneofWrappers {
90
- wrappedOneof = OneofWrappers . WrappedOneof .IdOneof (model.id)
100
+ wrappedOneof = WrappedOneof .IdOneof (model.id)
91
101
}.serialize()
92
102
)
93
103
94
104
assertThat(
95
- (deserialized.wrappedOneof as OneofWrappers . WrappedOneof .IdOneof ).idOneof
105
+ (deserialized.wrappedOneof as WrappedOneof .IdOneof ).idOneof
96
106
).isEqualTo(model.id)
97
107
}
98
108
99
109
@Test
100
110
fun `round trip should preserve uuid oneof` () {
101
111
val deserialized = OneofWrappers .deserialize(
102
112
OneofWrappers {
103
- wrappedOneof = OneofWrappers . WrappedOneof .UuidOneof (model.uuid)
113
+ wrappedOneof = WrappedOneof .UuidOneof (model.uuid)
104
114
}.serialize()
105
115
)
106
116
107
117
assertThat(
108
- (deserialized.wrappedOneof as OneofWrappers . WrappedOneof .UuidOneof ).uuidOneof
118
+ (deserialized.wrappedOneof as WrappedOneof .UuidOneof ).uuidOneof
109
119
).isEqualTo(model.uuid)
110
120
}
111
121
112
122
@Test
113
123
fun `round trip should preserve ip address oneof` () {
114
124
val deserialized = OneofWrappers .deserialize(
115
125
OneofWrappers {
116
- wrappedOneof = OneofWrappers . WrappedOneof .IpAddressOneof (model.ipAddress)
126
+ wrappedOneof = WrappedOneof .IpAddressOneof (model.ipAddress)
117
127
}.serialize()
118
128
)
119
129
120
130
assertThat(
121
- (deserialized.wrappedOneof as OneofWrappers . WrappedOneof .IpAddressOneof ).ipAddressOneof
131
+ (deserialized.wrappedOneof as WrappedOneof .IpAddressOneof ).ipAddressOneof
122
132
).isEqualTo(model.ipAddress)
123
133
}
124
134
125
135
@Test
126
- fun `round trip should preserve instant oneof` () {
136
+ fun `round trip should preserve caching id oneof` () {
127
137
val deserialized = OneofWrappers .deserialize(
128
138
OneofWrappers {
129
- wrappedOneof = OneofWrappers . WrappedOneof .InstantOneof (model.instant )
139
+ wrappedOneof = WrappedOneof .CachingIdOneof (model.cachingId )
130
140
}.serialize()
131
141
)
132
142
133
143
assertThat(
134
- (deserialized.wrappedOneof as OneofWrappers . WrappedOneof .InstantOneof ).instantOneof
135
- ).isEqualTo(model.instant )
144
+ (deserialized.wrappedOneof as WrappedOneof .CachingIdOneof ).cachingIdOneof
145
+ ).isEqualTo(model.cachingId )
136
146
}
137
147
138
148
@Test
139
149
fun `round trip should preserve socket address oneof` () {
140
150
val deserialized = OneofWrappers .deserialize(
141
151
OneofWrappers {
142
- wrappedOneof = OneofWrappers . WrappedOneof .SocketAddressOneof (model.socketAddress)
152
+ wrappedOneof = WrappedOneof .SocketAddressOneof (model.socketAddress)
143
153
}.serialize()
144
154
)
145
155
146
156
assertThat(
147
- (deserialized.wrappedOneof as OneofWrappers . WrappedOneof .SocketAddressOneof ).socketAddressOneof
157
+ (deserialized.wrappedOneof as WrappedOneof .SocketAddressOneof ).socketAddressOneof
148
158
).isEqualTo(model.socketAddress)
149
159
}
150
160
161
+ @Test
162
+ fun `round trip should preserve instant oneof` () {
163
+ val deserialized = OneofWrappers .deserialize(
164
+ OneofWrappers {
165
+ wrappedOneof = WrappedOneof .InstantOneof (model.instant)
166
+ }.serialize()
167
+ )
168
+
169
+ assertThat(
170
+ (deserialized.wrappedOneof as WrappedOneof .InstantOneof ).instantOneof
171
+ ).isEqualTo(model.instant)
172
+ }
173
+
174
+ @Test
175
+ fun `round trip should preserve duration oneof` () {
176
+ val deserialized = OneofWrappers .deserialize(
177
+ OneofWrappers {
178
+ wrappedOneof = WrappedOneof .DurationOneof (model.duration)
179
+ }.serialize()
180
+ )
181
+
182
+ assertThat(
183
+ (deserialized.wrappedOneof as WrappedOneof .DurationOneof ).durationOneof
184
+ ).isEqualTo(model.duration)
185
+ }
186
+
187
+ @Test
188
+ fun `round trip should preserve localdate oneof` () {
189
+ val deserialized = OneofWrappers .deserialize(
190
+ OneofWrappers {
191
+ wrappedOneof = WrappedOneof .LocalDateOneof (model.localDate)
192
+ }.serialize()
193
+ )
194
+
195
+ assertThat(
196
+ (deserialized.wrappedOneof as WrappedOneof .LocalDateOneof ).localDateOneof
197
+ ).isEqualTo(model.localDate)
198
+ }
199
+
151
200
@Test
152
201
fun `wrapped message should not be nullable` () {
153
202
val thrown = assertThrows<IllegalArgumentException > {
0 commit comments