From 6023d99bb77e2efd2bee92b15c7cf0b7dd22a958 Mon Sep 17 00:00:00 2001 From: asm0dey Date: Tue, 12 Jan 2021 16:20:45 +0300 Subject: [PATCH] Fixes https://bit.ly/35zc6ZE sonarcloud warning --- src/main/kotlin/staks/base.kt | 14 ++++++-------- src/test/kotlin/staks/BaseKtTest.kt | 11 ++++++----- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/staks/base.kt b/src/main/kotlin/staks/base.kt index 0dcdf98..d54578d 100644 --- a/src/main/kotlin/staks/base.kt +++ b/src/main/kotlin/staks/base.kt @@ -47,15 +47,13 @@ class StaxBuilder(override val reader: XMLEventReader, func: StaxBuilder.( return builder() } - override val value: () -> T get() = throw IllegalStateException("Root builder should not process anything!") - override val isSingular: Boolean - get() = throw IllegalStateException("Root builder should not process anything!") + private fun getDoNotCall() = IllegalStateException("Root builder should not process anything!") - override fun matches(event: XMLEvent): Boolean = - throw IllegalStateException("Root builder should not process anything!") - - override fun process(ev: XMLEvent): Unit = throw IllegalStateException("Root builder should not process anything!") - override fun reset(): Unit = throw IllegalStateException("Root builder should not process anything!") + override val value: () -> T get() = throw getDoNotCall() + override val isSingular: Boolean get() = throw getDoNotCall() + override fun matches(event: XMLEvent): Boolean = throw getDoNotCall() + override fun process(ev: XMLEvent): Unit = throw getDoNotCall() + override fun reset(): Unit = throw getDoNotCall() } diff --git a/src/test/kotlin/staks/BaseKtTest.kt b/src/test/kotlin/staks/BaseKtTest.kt index abb5e00..230a571 100644 --- a/src/test/kotlin/staks/BaseKtTest.kt +++ b/src/test/kotlin/staks/BaseKtTest.kt @@ -70,11 +70,12 @@ class BaseKtTest : FunSpec({ test("handler calls to StaxBuilder should fail") { staks("".byteInputStream()) { val ev = reader.nextEvent() - expect { isSingular }.toThrow().message.toBe("Root builder should not process anything!") - expect { matches(ev) }.toThrow().message.toBe("Root builder should not process anything!") - expect { process(ev) }.toThrow().message.toBe("Root builder should not process anything!") - expect { reset() }.toThrow().message.toBe("Root builder should not process anything!") - expect { value() }.toThrow().message.toBe("Root builder should not process anything!") + val errorMessage = "Root builder should not process anything!" + expect { isSingular }.toThrow().message toBe errorMessage + expect { matches(ev) }.toThrow().message toBe errorMessage + expect { process(ev) }.toThrow().message toBe errorMessage + expect { reset() }.toThrow().message toBe errorMessage + expect { value() }.toThrow().message toBe errorMessage ; {} }