-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: add kover for test coverage * test: enforce coverage percentage * test: increase test coverage
- Loading branch information
Showing
7 changed files
with
282 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
Provider/src/test/java/com/spotify/confidence/openfeature/ConfidenceValueMappingsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package com.spotify.confidence.openfeature | ||
|
||
import com.spotify.confidence.ConfidenceValue | ||
import dev.openfeature.sdk.Value | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertNull | ||
import org.junit.Test | ||
|
||
class ConfidenceValueMappingsTest { | ||
|
||
@Test | ||
fun confidenceStringToValueString() { | ||
val confidenceValue = ConfidenceValue.String("test") | ||
val value = confidenceValue.toValue() | ||
assertEquals("test", value.asString()) | ||
assertNull(value.asInteger()) | ||
assertNull(value.asDate()) | ||
assertNull(value.asBoolean()) | ||
assertNull(value.asStructure()) | ||
} | ||
|
||
@Test | ||
fun confidenceDoubleToValueDouble() { | ||
val confidenceValue = ConfidenceValue.Double(1.23) | ||
val value = confidenceValue.toValue() | ||
assertEquals(1.23, value.asDouble()!!, 0.001) | ||
assertNull(value.asString()) | ||
assertNull(value.asInteger()) | ||
assertNull(value.asDate()) | ||
assertNull(value.asBoolean()) | ||
assertNull(value.asStructure()) | ||
} | ||
|
||
@Test | ||
fun confidenceBooleanToValueBoolean() { | ||
val confidenceValue = ConfidenceValue.Boolean(true) | ||
val value = confidenceValue.toValue() | ||
assertEquals(true, value.asBoolean()) | ||
assertNull(value.asString()) | ||
assertNull(value.asDouble()) | ||
assertNull(value.asDate()) | ||
assertNull(value.asInteger()) | ||
assertNull(value.asStructure()) | ||
} | ||
|
||
@Test | ||
fun confidenceIntegerToValueInteger() { | ||
val confidenceValue = ConfidenceValue.Integer(42) | ||
val value = confidenceValue.toValue() | ||
assertEquals(42, value.asInteger()) | ||
assertNull(value.asString()) | ||
assertNull(value.asDouble()) | ||
assertNull(value.asDate()) | ||
assertNull(value.asBoolean()) | ||
assertNull(value.asStructure()) | ||
} | ||
|
||
@Test | ||
fun confidenceStructToValueStructure() { | ||
val confidenceValue = ConfidenceValue.Struct(mapOf("key" to ConfidenceValue.String("value"))) | ||
val value = confidenceValue.toValue() | ||
assertEquals(mapOf("key" to dev.openfeature.sdk.Value.String("value")), value.asStructure()) | ||
assertNull(value.asString()) | ||
assertNull(value.asDouble()) | ||
assertNull(value.asDate()) | ||
assertNull(value.asBoolean()) | ||
assertNull(value.asList()) | ||
} | ||
|
||
@Test | ||
fun confidenceListToValueList() { | ||
val confidenceValue = ConfidenceValue.List(listOf(ConfidenceValue.String("item"))) | ||
val value = confidenceValue.toValue() | ||
assertEquals(listOf(dev.openfeature.sdk.Value.String("item")), value.asList()) | ||
assertNull(value.asString()) | ||
assertNull(value.asDouble()) | ||
assertNull(value.asDate()) | ||
assertNull(value.asBoolean()) | ||
assertNull(value.asStructure()) | ||
} | ||
|
||
@Test | ||
fun confidenceDateToValueDate() { | ||
val date = java.util.Date() | ||
val confidenceValue = ConfidenceValue.Date(date) | ||
val value = confidenceValue.toValue() | ||
assertEquals(date, value.asDate()) | ||
assertNull(value.asString()) | ||
assertNull(value.asDouble()) | ||
assertNull(value.asBoolean()) | ||
assertNull(value.asInteger()) | ||
assertNull(value.asStructure()) | ||
} | ||
|
||
@Test | ||
fun confidenceTimestampToValueTimestamp() { | ||
val timestamp = java.util.Date() | ||
val confidenceValue = ConfidenceValue.Timestamp(timestamp) | ||
val value = confidenceValue.toValue() | ||
assertEquals(timestamp.time, value.asDate()!!.time) | ||
assertNull(value.asString()) | ||
assertNull(value.asDouble()) | ||
assertNull(value.asBoolean()) | ||
assertNull(value.asInteger()) | ||
assertNull(value.asStructure()) | ||
} | ||
|
||
@Test | ||
fun confidenceNullToValueNull() { | ||
val confidenceValue = ConfidenceValue.Null | ||
val value = confidenceValue.toValue() | ||
assertEquals(Value.Null, value) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
Provider/src/test/java/com/spotify/confidence/openfeature/ValueMappingsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.spotify.confidence.openfeature | ||
|
||
import com.spotify.confidence.ConfidenceValue | ||
import dev.openfeature.sdk.Value | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class ValueMappingsTest { | ||
|
||
@Test | ||
fun openFeatureStringValueToConfidenceValueString() { | ||
val value = Value.String("test") | ||
val confidenceValue: ConfidenceValue = value.toConfidenceValue() | ||
assertEquals("test", confidenceValue.asString()?.string) | ||
} | ||
|
||
@Test | ||
fun openFeatureDoubleValueToConfidenceValueDouble() { | ||
val value = Value.Double(1.23) | ||
val confidenceValue: ConfidenceValue = value.toConfidenceValue() | ||
assertEquals(1.23, confidenceValue.asDouble()?.double!!, 0.001) | ||
} | ||
|
||
@Test | ||
fun openFeatureBooleanValueToConfidenceValueBoolean() { | ||
val value = Value.Boolean(true) | ||
val confidenceValue: ConfidenceValue = value.toConfidenceValue() | ||
assertEquals(true, confidenceValue.asBoolean()?.boolean) | ||
} | ||
|
||
@Test | ||
fun openFeatureIntegerValueToConfidenceValueInteger() { | ||
val value = Value.Integer(42) | ||
val confidenceValue: ConfidenceValue = value.toConfidenceValue() | ||
assertEquals(42, confidenceValue.asInteger()?.integer) | ||
} | ||
|
||
@Test | ||
fun openFeatureStructureValueToConfidenceValueStruct() { | ||
val value = Value.Structure(mapOf("key" to Value.String("value"))) | ||
val confidenceValue: ConfidenceValue = value.toConfidenceValue() | ||
assertEquals("value", confidenceValue.asStructure()?.map?.get("key")?.asString()?.string) | ||
} | ||
|
||
@Test | ||
fun openFeatureListValueToConfidenceValueList() { | ||
val value = Value.List(listOf(Value.String("value"))) | ||
val confidenceValue: ConfidenceValue = value.toConfidenceValue() | ||
assertEquals("value", confidenceValue.asList()?.list?.get(0)?.asString()?.string) | ||
} | ||
|
||
@Test | ||
fun mixedListShouldReturnEmptyConfidenceList() { | ||
val value = Value.List(listOf(Value.String("value"), Value.Integer(42))) | ||
val confidenceValue: ConfidenceValue = value.toConfidenceValue() | ||
assertEquals(0, confidenceValue.asList()?.list?.size) | ||
} | ||
|
||
private fun ConfidenceValue.asString(): ConfidenceValue.String? { | ||
return this as? ConfidenceValue.String | ||
} | ||
|
||
private fun ConfidenceValue.asDouble(): ConfidenceValue.Double? { | ||
return this as? ConfidenceValue.Double | ||
} | ||
|
||
private fun ConfidenceValue.asBoolean(): ConfidenceValue.Boolean? { | ||
return this as? ConfidenceValue.Boolean | ||
} | ||
|
||
private fun ConfidenceValue.asInteger(): ConfidenceValue.Integer? { | ||
return this as? ConfidenceValue.Integer | ||
} | ||
|
||
private fun ConfidenceValue.asStructure(): ConfidenceValue.Struct? { | ||
return this as? ConfidenceValue.Struct | ||
} | ||
|
||
private fun ConfidenceValue.asList(): ConfidenceValue.List? { | ||
return this as? ConfidenceValue.List | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters