From b4fabddb2f60567cad13bb708b41e1ab3bf7d3c0 Mon Sep 17 00:00:00 2001 From: Leonardo Colman Lopes Date: Fri, 27 Jan 2023 22:06:08 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=85=20Update=20PauseTest?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When running Kover (related: #198), PauseTest showed as not having one of the branches properly covered. While addressing this issue directly (and bringing coverage on this class to 100%), this commit also rearranges the test class so assertions are clearer and less repetitive. Signed-off-by: Leonardo Colman Lopes --- .../petals/use/pause/repository/PauseTest.kt | 43 ++++++++++++------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/app/src/test/kotlin/br/com/colman/petals/use/pause/repository/PauseTest.kt b/app/src/test/kotlin/br/com/colman/petals/use/pause/repository/PauseTest.kt index 14e18b7e..7d271ed1 100644 --- a/app/src/test/kotlin/br/com/colman/petals/use/pause/repository/PauseTest.kt +++ b/app/src/test/kotlin/br/com/colman/petals/use/pause/repository/PauseTest.kt @@ -6,36 +6,49 @@ import io.kotest.property.Arb import io.kotest.property.arbitrary.localTime import io.kotest.property.checkAll import java.time.LocalTime +import java.time.LocalTime.MAX +import java.time.LocalTime.MIN import java.time.LocalTime.NOON class PauseTest : FunSpec({ - context("Is active calculation") { - test("Full time pause") { - val pause = Pause(LocalTime.MIN, LocalTime.MAX) + val pause = Pause(startTime = MIN, endTime = MAX) - Arb.localTime().checkAll { - pause.isActive(it) shouldBe true - } + Arb.localTime().checkAll { pause shouldBeActiveAt it } } test("Immediately after end") { - val pause = Pause(LocalTime.MIN, NOON) + val pause = Pause(startTime = MIN, endTime = NOON) - pause.isActive(NOON.plusSeconds(1)) shouldBe false + pause shouldNotBeActiveAt NOON.plusSeconds(1) } test("Immediately before start") { - val pause = Pause(LocalTime.NOON, LocalTime.MAX) - pause.isActive(NOON.minusSeconds(1)) shouldBe false + val pause = Pause(startTime = NOON, endTime = MAX) + pause shouldNotBeActiveAt NOON.minusSeconds(1) } - test("Goes through midnight") { - val pause = Pause(LocalTime.of(23, 30), LocalTime.of(1, 30)) - pause.isActive(LocalTime.of(0, 25)) shouldBe true - pause.isActive(LocalTime.of(1, 31)) shouldBe false - pause.isActive(LocalTime.of(23, 29)) shouldBe false + context("Passing through midnight") { + val pause = Pause(startTime = MAX, endTime = NOON) + + test("Start time") { + pause shouldBeActiveAt MAX.plusSeconds(1) + pause shouldNotBeActiveAt MAX.minusSeconds(1) + } + + test("End time") { + pause shouldBeActiveAt NOON.minusSeconds(1) + pause shouldNotBeActiveAt NOON.plusSeconds(1) + } } } }) + +private infix fun Pause.shouldBeActiveAt(localTime: LocalTime) { + isActive(localTime) shouldBe true +} + +private infix fun Pause.shouldNotBeActiveAt(localTime: LocalTime) { + isActive(localTime) shouldBe false +}