|
1 | 1 | package io.sentry |
2 | 2 |
|
| 3 | +import com.nhaarman.mockitokotlin2.inOrder |
3 | 4 | import com.nhaarman.mockitokotlin2.mock |
| 5 | +import com.nhaarman.mockitokotlin2.times |
4 | 6 | import com.nhaarman.mockitokotlin2.verify |
5 | 7 | import org.junit.Test |
| 8 | +import java.net.URI |
| 9 | +import java.util.Calendar |
| 10 | +import java.util.Currency |
| 11 | +import java.util.Locale |
6 | 12 | import java.util.TimeZone |
| 13 | +import java.util.UUID |
| 14 | +import java.util.concurrent.atomic.AtomicBoolean |
| 15 | +import java.util.concurrent.atomic.AtomicIntegerArray |
7 | 16 |
|
8 | 17 | internal class JsonObjectSerializerTest { |
9 | 18 |
|
@@ -114,9 +123,9 @@ internal class JsonObjectSerializerTest { |
114 | 123 |
|
115 | 124 | @Test |
116 | 125 | fun `serialize unknown object without data`() { |
117 | | - fixture.getSUT().serialize(fixture.writer, fixture.logger, object {}) |
118 | | - verify(fixture.writer).beginObject() |
119 | | - verify(fixture.writer).endObject() |
| 126 | + val value = object {} |
| 127 | + fixture.getSUT().serialize(fixture.writer, fixture.logger, value) |
| 128 | + verify(fixture.writer).value(value.toString()) |
120 | 129 | } |
121 | 130 |
|
122 | 131 | @Test |
@@ -166,10 +175,107 @@ internal class JsonObjectSerializerTest { |
166 | 175 | verify(fixture.writer).endObject() |
167 | 176 | } |
168 | 177 |
|
| 178 | + @Test |
| 179 | + fun `serialize locale`() { |
| 180 | + val inOrder = inOrder(fixture.writer) |
| 181 | + fixture.getSUT().serialize(fixture.writer, fixture.logger, Locale.US) |
| 182 | + |
| 183 | + inOrder.verify(fixture.writer).value("en_US") |
| 184 | + } |
| 185 | + |
| 186 | + @Test |
| 187 | + fun `serialize locale in map`() { |
| 188 | + val map = mapOf<String, Locale>("one" to Locale.US) |
| 189 | + val inOrder = inOrder(fixture.writer) |
| 190 | + fixture.getSUT().serialize(fixture.writer, fixture.logger, map) |
| 191 | + inOrder.verify(fixture.writer).beginObject() |
| 192 | + inOrder.verify(fixture.writer).name("one") |
| 193 | + inOrder.verify(fixture.writer).value("en_US") |
| 194 | + inOrder.verify(fixture.writer).endObject() |
| 195 | + } |
| 196 | + |
| 197 | + @Test |
| 198 | + fun `serialize locale in list`() { |
| 199 | + val list = listOf<Locale>(Locale.US, Locale.GERMAN) |
| 200 | + val inOrder = inOrder(fixture.writer) |
| 201 | + fixture.getSUT().serialize(fixture.writer, fixture.logger, list) |
| 202 | + inOrder.verify(fixture.writer).beginArray() |
| 203 | + inOrder.verify(fixture.writer).value("en_US") |
| 204 | + inOrder.verify(fixture.writer).value("de") |
| 205 | + inOrder.verify(fixture.writer).endArray() |
| 206 | + } |
| 207 | + |
| 208 | + @Test |
| 209 | + fun `serialize locale in object`() { |
| 210 | + val obj = ClassWithLocaleProperty(Locale.US) |
| 211 | + val inOrder = inOrder(fixture.writer) |
| 212 | + fixture.getSUT().serialize(fixture.writer, fixture.logger, obj) |
| 213 | + inOrder.verify(fixture.writer).beginObject() |
| 214 | + inOrder.verify(fixture.writer).name("localeProperty") |
| 215 | + inOrder.verify(fixture.writer).value("en_US") |
| 216 | + inOrder.verify(fixture.writer).endObject() |
| 217 | + } |
| 218 | + |
| 219 | + @Test |
| 220 | + fun `serializing AtomicIntegerArray`() { |
| 221 | + fixture.getSUT().serialize(fixture.writer, fixture.logger, AtomicIntegerArray(arrayOf(1, 2, 3).toIntArray())) |
| 222 | + verify(fixture.writer).beginArray() |
| 223 | + verify(fixture.writer).value(1 as Number) |
| 224 | + verify(fixture.writer).value(2 as Number) |
| 225 | + verify(fixture.writer).value(3 as Number) |
| 226 | + verify(fixture.writer).endArray() |
| 227 | + } |
| 228 | + |
| 229 | + @Test |
| 230 | + fun `serializing AtomicBoolean`() { |
| 231 | + fixture.getSUT().serialize(fixture.writer, fixture.logger, AtomicBoolean(true)) |
| 232 | + verify(fixture.writer).value(true) |
| 233 | + } |
| 234 | + |
| 235 | + @Test |
| 236 | + fun `serializing URI`() { |
| 237 | + fixture.getSUT().serialize(fixture.writer, fixture.logger, URI("http://localhost:8081/api/product?id=99")) |
| 238 | + verify(fixture.writer).value("http://localhost:8081/api/product?id=99") |
| 239 | + } |
| 240 | + |
| 241 | + @Test |
| 242 | + fun `serializing UUID`() { |
| 243 | + fixture.getSUT().serialize(fixture.writer, fixture.logger, UUID.fromString("828900a5-15dc-413f-8c17-6ef04d74e074")) |
| 244 | + verify(fixture.writer).value("828900a5-15dc-413f-8c17-6ef04d74e074") |
| 245 | + } |
| 246 | + |
| 247 | + @Test |
| 248 | + fun `serializing Currency`() { |
| 249 | + fixture.getSUT().serialize(fixture.writer, fixture.logger, Currency.getInstance("USD")) |
| 250 | + verify(fixture.writer).value("USD") |
| 251 | + } |
| 252 | + |
| 253 | + @Test |
| 254 | + fun `serializing Calendar`() { |
| 255 | + val calendar = Calendar.getInstance() |
| 256 | + calendar.set(2022, 0, 1, 11, 59, 58) |
| 257 | + fixture.getSUT().serialize(fixture.writer, fixture.logger, calendar) |
| 258 | + verify(fixture.writer).beginObject() |
| 259 | + verify(fixture.writer).name("year") |
| 260 | + verify(fixture.writer).value(2022 as java.lang.Integer) |
| 261 | + verify(fixture.writer).name("month") |
| 262 | + verify(fixture.writer).value(0 as java.lang.Integer) |
| 263 | + verify(fixture.writer).name("dayOfMonth") |
| 264 | + verify(fixture.writer).value(1 as java.lang.Integer) |
| 265 | + verify(fixture.writer).name("hourOfDay") |
| 266 | + verify(fixture.writer).value(11 as java.lang.Integer) |
| 267 | + verify(fixture.writer).name("minute") |
| 268 | + verify(fixture.writer).value(59 as java.lang.Integer) |
| 269 | + verify(fixture.writer).name("second") |
| 270 | + verify(fixture.writer).value(58 as java.lang.Integer) |
| 271 | + verify(fixture.writer).endObject() |
| 272 | + } |
| 273 | + |
169 | 274 | class UnknownClassWithData( |
170 | 275 | private val integer: Int, |
171 | 276 | private val string: String |
172 | 277 | ) |
173 | 278 | } |
174 | 279 |
|
175 | 280 | data class ClassWithEnumProperty(val enumProperty: DataCategory) |
| 281 | +data class ClassWithLocaleProperty(val localeProperty: Locale) |
0 commit comments