@@ -136,4 +136,42 @@ class OpenFeatureClientTests {
136136
137137 assertEquals(OpenFeatureStatus .Stale , client.providerStatus)
138138 }
139+
140+ @Test
141+ fun testClientEvaluationShouldReturnProviderNotReadyWhenEvaluatingBeforeProviderIsReady () = runTest {
142+ val client = OpenFeatureAPI .getClient()
143+ val details = client.getBooleanDetails(" test-flag" , false )
144+ assertEquals(dev.openfeature.kotlin.sdk.exceptions.ErrorCode .PROVIDER_NOT_READY , details.errorCode)
145+ }
146+
147+ @Test
148+ fun testClientEvaluationShouldReturnProviderFatalWhenEvaluatingWithFatalProvider () = runTest {
149+ val fatalProvider = object : FeatureProvider by NoOpProvider () {
150+ override suspend fun initialize (initialContext : EvaluationContext ? ) {
151+ throw OpenFeatureError .ProviderFatalError (" test fatal error" )
152+ }
153+ }
154+ OpenFeatureAPI .setProviderAndWait(fatalProvider)
155+ val client = OpenFeatureAPI .getClient()
156+ val details = client.getBooleanDetails(" test-flag" , false )
157+ assertEquals(dev.openfeature.kotlin.sdk.exceptions.ErrorCode .PROVIDER_FATAL , details.errorCode)
158+ }
159+
160+ @Test
161+ fun testClientEvaluationShouldMapGeneralExceptionsToGeneralErrorCode () = runTest {
162+ val throwingProvider = object : FeatureProvider by NoOpProvider () {
163+ override fun getBooleanEvaluation (
164+ key : String ,
165+ defaultValue : Boolean ,
166+ context : EvaluationContext ?
167+ ): ProviderEvaluation <Boolean > {
168+ throw IllegalStateException (" Generic unexpected crash" )
169+ }
170+ }
171+ OpenFeatureAPI .setProviderAndWait(throwingProvider)
172+ val client = OpenFeatureAPI .getClient()
173+ val details = client.getBooleanDetails(" test-flag" , false )
174+ assertEquals(dev.openfeature.kotlin.sdk.exceptions.ErrorCode .GENERAL , details.errorCode)
175+ assertEquals(" Generic unexpected crash" , details.errorMessage)
176+ }
139177}
0 commit comments