Skip to content

Commit

Permalink
Ported tests from bson-kotlinx to bson-kotlin (#1434)
Browse files Browse the repository at this point in the history
JAVA-5342

Co-authored-by: Cliffred van Velzen <cliffred@cliffred.nl>
  • Loading branch information
rozza and cliffred committed Jul 1, 2024
1 parent d59abbf commit 440deb2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.bson.codecs.DecoderContext
import org.bson.codecs.EncoderContext
import org.bson.codecs.configuration.CodecConfigurationException
import org.bson.codecs.configuration.CodecRegistries.fromProviders
import org.bson.codecs.kotlin.samples.Box
import org.bson.codecs.kotlin.samples.DataClassEmbedded
import org.bson.codecs.kotlin.samples.DataClassListOfDataClasses
import org.bson.codecs.kotlin.samples.DataClassListOfListOfDataClasses
Expand Down Expand Up @@ -55,6 +56,7 @@ import org.bson.codecs.kotlin.samples.DataClassWithMutableMap
import org.bson.codecs.kotlin.samples.DataClassWithMutableSet
import org.bson.codecs.kotlin.samples.DataClassWithNestedParameterized
import org.bson.codecs.kotlin.samples.DataClassWithNestedParameterizedDataClass
import org.bson.codecs.kotlin.samples.DataClassWithNullableGeneric
import org.bson.codecs.kotlin.samples.DataClassWithNulls
import org.bson.codecs.kotlin.samples.DataClassWithObjectIdAndBsonDocument
import org.bson.codecs.kotlin.samples.DataClassWithPair
Expand Down Expand Up @@ -131,6 +133,25 @@ class DataClassCodecTest {
assertDecodesTo(withStoredNulls, dataClass)
}

@Test
fun testDataClassWithNullableGenericsNotNull() {
val expected =
"""{
| "box": {"boxed": "String"}
|}"""
.trimMargin()

val dataClass = DataClassWithNullableGeneric(Box("String"))
assertRoundTrips(expected, dataClass)
}

@Test
fun testDataClassWithNullableGenericsNull() {
val expected = """{"box": {}}"""
val dataClass = DataClassWithNullableGeneric(Box(null))
assertRoundTrips(expected, dataClass)
}

@Test
fun testDataClassSelfReferential() {
val expected =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.bson.codecs.kotlin.samples

import kotlinx.serialization.Serializable
import kotlin.time.Duration
import org.bson.BsonDocument
import org.bson.BsonMaxKey
Expand Down Expand Up @@ -162,3 +163,7 @@ data class DataClassWithFailingInit(val id: String) {
data class DataClassWithSequence(val value: Sequence<String>)

data class DataClassWithJVMErasure(val duration: Duration, val ints: List<Int>)

data class Box<T>(val boxed: T)

data class DataClassWithNullableGeneric(val box: Box<String?>)

0 comments on commit 440deb2

Please sign in to comment.