diff --git a/app/src/test/java/com/m57/hermescontrol/util/CronExpressionFormatterTest.kt b/app/src/test/java/com/m57/hermescontrol/util/CronExpressionFormatterTest.kt index cc1dc68e..34816670 100644 --- a/app/src/test/java/com/m57/hermescontrol/util/CronExpressionFormatterTest.kt +++ b/app/src/test/java/com/m57/hermescontrol/util/CronExpressionFormatterTest.kt @@ -1,9 +1,26 @@ package com.m57.hermescontrol.util +import android.util.Log +import io.mockk.every +import io.mockk.mockkStatic +import io.mockk.unmockkAll +import org.junit.After import org.junit.Assert.assertEquals +import org.junit.Before import org.junit.Test class CronExpressionFormatterTest { + @Before + fun setup() { + mockkStatic(Log::class) + every { Log.w(any(), any(), any()) } returns 0 + } + + @After + fun teardown() { + unmockkAll() + } + @Test fun testCronToHumanReadable() { assertEquals("At 09:00 and 21:00 every day", CronExpressionFormatter.cronToHumanReadable("0 9,21 * * *")) @@ -22,4 +39,13 @@ class CronExpressionFormatterTest { assertEquals("invalid cron string", CronExpressionFormatter.cronToHumanReadable("invalid cron string")) assertEquals("0 9 * *", CronExpressionFormatter.cronToHumanReadable("0 9 * *")) } + + @Test + fun testExceptionFallback() { + // This will cause an IndexOutOfBoundsException because 15 is out of bounds for monthNames + assertEquals("Raw: 0 12 1 15 *", CronExpressionFormatter.cronToHumanReadable("0 12 1 15 *")) + + // This will cause an IndexOutOfBoundsException because 8 is out of bounds for dowNames + assertEquals("Raw: 0 9 * * 8", CronExpressionFormatter.cronToHumanReadable("0 9 * * 8")) + } }