From e20a490238d6f93e48c759650aa179cbabd6f670 Mon Sep 17 00:00:00 2001 From: Daniel Gomez Date: Thu, 30 Jan 2025 05:24:58 -0500 Subject: [PATCH] Add task tests (#2039) --- .../android/habitica/models/TaskTest.kt | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Habitica/src/test/java/com/habitrpg/android/habitica/models/TaskTest.kt diff --git a/Habitica/src/test/java/com/habitrpg/android/habitica/models/TaskTest.kt b/Habitica/src/test/java/com/habitrpg/android/habitica/models/TaskTest.kt new file mode 100644 index 0000000000..42b8e3dda1 --- /dev/null +++ b/Habitica/src/test/java/com/habitrpg/android/habitica/models/TaskTest.kt @@ -0,0 +1,63 @@ +package com.habitrpg.android.habitica.models + +import com.habitrpg.android.habitica.models.tasks.Task +import io.kotest.core.spec.style.WordSpec +import io.kotest.matchers.shouldBe +import java.util.Date +import java.time.ZonedDateTime +import java.util.Calendar + +class TaskTest : WordSpec({ + val task = Task() + + fun date( + year: Int = 1989, + month: Int = 1, + day: Int = 2, + hourOfDay: Int = 3, + minute: Int = 4, + second: Int = 5 + ) : Date { + val calendar = Calendar.getInstance() + calendar.set(year, month, day, hourOfDay, minute, second) + + return calendar.time + } + + "isDueToday" should { + "false if the day of year is before today" { + val now = ZonedDateTime.now() + task.dueDate = date(day= now.dayOfYear - 1, year = now.year) + + task.isDueToday() shouldBe false + } + + "false if the year is before today" { + val now = ZonedDateTime.now() + task.dueDate = date(day= now.dayOfYear, year = now.year - 1) + + task.isDueToday() shouldBe false + } + + "true if the day of year is after today" { + val now = ZonedDateTime.now() + task.dueDate = date(day= now.dayOfYear + 1, year = now.year) + + task.isDueToday() shouldBe true + } + + "true if the year is after today" { + val now = ZonedDateTime.now() + task.dueDate = date(day= now.dayOfYear, year = now.year + 1) + + task.isDueToday() shouldBe true + } + + "true if it is today" { + val now = ZonedDateTime.now() + task.dueDate = date(day= now.dayOfYear, year = now.year) + + task.isDueToday() shouldBe true + } + } +}) \ No newline at end of file