diff --git a/core/src/main/kotlin/com/monta/library/ocpp/common/profile/OcppRequest.kt b/core/src/main/kotlin/com/monta/library/ocpp/common/profile/OcppRequest.kt index cac7e2a..34caa11 100644 --- a/core/src/main/kotlin/com/monta/library/ocpp/common/profile/OcppRequest.kt +++ b/core/src/main/kotlin/com/monta/library/ocpp/common/profile/OcppRequest.kt @@ -9,7 +9,7 @@ interface OcppRequest { */ fun actionName(): String { val className = this::class.java.simpleName - if (className.endsWith("Request")) { + if ((className.length > 7) && className.endsWith("Request")) { return className.dropLast(7) } return className diff --git a/core/src/test/kotlin/com/monta/library/ocpp/common/profile/OcppRequestTest.kt b/core/src/test/kotlin/com/monta/library/ocpp/common/profile/OcppRequestTest.kt index 2c411e0..4b3d259 100644 --- a/core/src/test/kotlin/com/monta/library/ocpp/common/profile/OcppRequestTest.kt +++ b/core/src/test/kotlin/com/monta/library/ocpp/common/profile/OcppRequestTest.kt @@ -5,7 +5,7 @@ import io.kotest.matchers.shouldBe class OcppRequestTest : StringSpec({ - "action name for request classes following the convention of ending in 'Request" { + "action name for request classes following the convention of ending in 'Request'" { class TestRequest : OcppRequest TestRequest().actionName() shouldBe "Test" } @@ -19,4 +19,9 @@ class OcppRequestTest : StringSpec({ class Test : OcppRequest Test().actionName() shouldBe "Test" } + + "action name for request classes named 'Request'" { + class Request : OcppRequest + Request().actionName() shouldBe "Request" + } })