hi :wink: I have a problem with test my sealed cla...
# kotest
ł
hi 😉 I have a problem with test my sealed class.
Copy code
sealed class EmbeddedRule : NormalizationRule {
    object SingleSpaceRule : EmbeddedRule() {
        override val ruleName: String
            get() = "single_space_rule"

        override fun normalize(value: String): Result<String> {
            val charIterator = value.iterator()
            val output = StringBuilder("")

            while (charIterator.hasNext()) {
                val currentChar = charIterator.nextChar()

                if (output.isEmpty())
                    output.append(currentChar)
                else
                    if (output.last().code != CharDirectionality.WHITESPACE.value && currentChar.code != CharDirectionality.WHITESPACE.value)
                        output.append(currentChar)
            }

            return Result.success(output.toString())
        }
    }

    companion object {
        fun values(): List<EmbeddedRule> {
            return EmbeddedRule::class.sealedSubclasses.mapNotNull { it.objectInstance }
        }

        fun findByRuleName(name: String): Result<EmbeddedRule> {
            return when (name) {
                UpperCase.ruleName -> Result.success(UpperCase)
                else -> Result.failure(IllegalArgumentException(name))
            }
        }
    }
}
My test code and exception:
Copy code
context("SingleSpaceRule") {
        describe(".normalize") {
            it("returns only 1 spaces") {
                val result = EmbeddedRule.SingleSpaceRule.normalize("   ")

                result.isSuccess
                result.getOrThrow() == " "

            }
        }
    }

io.kotest.core.SpecInstantiationException: Could not create instance of class com.vascoelectronics.nlptool.normalizetext.domain.models.rules.EmbeddedRuleSpec
s
what's the constructor for EmbeddedRuleSpec
l
Also, if possible, is there any more to that stacktrace?
ł
I decided to change sealed class to interface 😉 I don't have any problem now