From 5d4b3e3567824445588d7263a4c27d8ba2afc6d5 Mon Sep 17 00:00:00 2001 From: Robert Ros Date: Thu, 12 Feb 2026 12:36:03 +0100 Subject: [PATCH 1/4] Add junit dependency --- app/build.gradle.kts | 1 + gradle/libs.versions.toml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 83c03500f..7b1f855bd 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -147,6 +147,7 @@ dependencies { implementation(libs.androidx.print) implementation(libs.bundles.room) implementation(libs.androidx.work.runtime.ktx) + testImplementation(libs.junit) ksp(libs.androidx.room.compiler) detektPlugins(libs.compose.detekt) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e93f7ccfb..da754f86f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,6 +13,8 @@ swiperefreshlayout = "1.2.0" work = "2.11.1" #Room room = "2.8.4" +#junit +junit = "4.13.2" #Fossify commons = "6.1.5" #Gradle @@ -35,6 +37,8 @@ androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" } androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "room" } #Compose compose-detekt = { module = "io.nlopez.compose.rules:detekt", version.ref = "detektCompose" } +#junit +junit = { group = "junit", name = "junit", version.ref = "junit" } #Fossify fossify-commons = { module = "org.fossify:commons", version.ref = "commons" } [bundles] From 8d7fed8d7a86e28790153e1411262ec2c8bd4fd5 Mon Sep 17 00:00:00 2001 From: Robert Ros Date: Sun, 22 Feb 2026 14:36:25 +0100 Subject: [PATCH 2/4] Add more test libraries for androidTest classes. --- app/build.gradle.kts | 5 +++++ gradle/libs.versions.toml | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 7b1f855bd..265ecb738 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -148,6 +148,11 @@ dependencies { implementation(libs.bundles.room) implementation(libs.androidx.work.runtime.ktx) testImplementation(libs.junit) + androidTestImplementation(libs.androidx.test.core) + androidTestImplementation(libs.androidx.test.runner) + androidTestImplementation(libs.androidx.test.rules) + androidTestImplementation(libs.androidx.test.ext.junit) + androidTestImplementation(libs.androidx.test.ext.truth) ksp(libs.androidx.room.compiler) detektPlugins(libs.compose.detekt) } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index da754f86f..721b115e7 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -15,6 +15,11 @@ work = "2.11.1" room = "2.8.4" #junit junit = "4.13.2" +androidx-test-core = "1.7.0" +androidx-test-runner = "1.7.0" +androidx-test-rules = "1.7.0" +androidx-test-ext-junit = "1.3.0" +androidx-test-ext-truth = "1.7.0" #Fossify commons = "6.1.5" #Gradle @@ -39,6 +44,11 @@ androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = compose-detekt = { module = "io.nlopez.compose.rules:detekt", version.ref = "detektCompose" } #junit junit = { group = "junit", name = "junit", version.ref = "junit" } +androidx-test-core = { group = "androidx.test", name = "core", version.ref = "androidx-test-core" } +androidx-test-runner = { group = "androidx.test", name = "runner", version.ref = "androidx-test-runner" } +androidx-test-rules = { group = "androidx.test", name = "rules", version.ref = "androidx-test-rules" } +androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidx-test-ext-junit" } +androidx-test-ext-truth = { group = "androidx.test.ext", name = "truth", version.ref = "androidx-test-ext-truth" } #Fossify fossify-commons = { module = "org.fossify:commons", version.ref = "commons" } [bundles] From c6c7eb515d4626f0e84d48130d0d6806e4fd2340 Mon Sep 17 00:00:00 2001 From: Robert Ros Date: Sun, 22 Feb 2026 14:37:02 +0100 Subject: [PATCH 3/4] Add an expected failure util to catch assertion error for known bugs without failing the tests. --- .../calendar/testing/ExpectedFailureUtils.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 app/src/androidTest/kotlin/org/fossify/calendar/testing/ExpectedFailureUtils.kt diff --git a/app/src/androidTest/kotlin/org/fossify/calendar/testing/ExpectedFailureUtils.kt b/app/src/androidTest/kotlin/org/fossify/calendar/testing/ExpectedFailureUtils.kt new file mode 100644 index 000000000..94de4fc7a --- /dev/null +++ b/app/src/androidTest/kotlin/org/fossify/calendar/testing/ExpectedFailureUtils.kt @@ -0,0 +1,13 @@ +package org.fossify.calendar.testing + +fun expectedFailure(testName: String = "", block: () -> Unit) { + try { + block() + println("WARNING: Expected failure test '$testName' passed unexpectedly.") + } catch (e: Throwable) { + println("Expected failure in test '$testName': ${e.javaClass.simpleName}: ${e.message}") + return + } + + throw AssertionError("Expected failure test '$testName' passed unexpectedly. Investigate: bug may be fixed.") +} From 39c339e1c098b0bf210366b6fe7bb1458edce2c8 Mon Sep 17 00:00:00 2001 From: Robert Ros Date: Sun, 22 Feb 2026 14:38:28 +0100 Subject: [PATCH 4/4] Add some tests for known bugs. --- ...tOneTimeEventsFromToWithCalendarIdsTest.kt | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 app/src/androidTest/kotlin/org/fossify/calendar/interfaces/EventsDaoGetOneTimeEventsFromToWithCalendarIdsTest.kt diff --git a/app/src/androidTest/kotlin/org/fossify/calendar/interfaces/EventsDaoGetOneTimeEventsFromToWithCalendarIdsTest.kt b/app/src/androidTest/kotlin/org/fossify/calendar/interfaces/EventsDaoGetOneTimeEventsFromToWithCalendarIdsTest.kt new file mode 100644 index 000000000..e11e1234f --- /dev/null +++ b/app/src/androidTest/kotlin/org/fossify/calendar/interfaces/EventsDaoGetOneTimeEventsFromToWithCalendarIdsTest.kt @@ -0,0 +1,85 @@ +package org.fossify.calendar.interfaces + +import android.content.Context +import androidx.room.Room +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.fossify.calendar.databases.EventsDatabase +import org.fossify.calendar.extensions.seconds +import org.fossify.calendar.models.Event +import org.fossify.calendar.testing.expectedFailure +import org.joda.time.DateTime +import org.junit.After +import org.junit.Assert +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import java.io.IOException + +@RunWith(AndroidJUnit4::class) +class EventsDaoGetOneTimeEventsFromToWithCalendarIdsTest { + + private lateinit var eventsDao: EventsDao + private lateinit var db: EventsDatabase + + private val calendarId = 1L + + @Before + fun createDb() { + val context = ApplicationProvider.getApplicationContext() + db = Room.inMemoryDatabaseBuilder( + context, EventsDatabase::class.java).build() + eventsDao = db.EventsDao() + } + + @After + @Throws(IOException::class) + fun closeDb() { + db.close() + } + + @Test + @Throws(Exception::class) + fun bug255_EventEndingAtMidnightShouldNotShowOnNextDay() { + expectedFailure("https://github.com/FossifyOrg/Calendar/issues/255") { + val startDay = DateTime(2026, 1, 1, 0, 0) + val startEvent = startDay.plusHours(23) + val event = Event(id = 0, startTS = startEvent.seconds(), endTS = startEvent.plusHours(1).seconds(), calendarId = calendarId) + eventsDao.insertOrUpdate(event) + + val eventsDayOne = eventsDao.getOneTimeEventsFromToWithCalendarIds(startDay.plusDays(1).seconds(), startDay.seconds(), listOf(calendarId)) + val eventsDayTwo = eventsDao.getOneTimeEventsFromToWithCalendarIds(startDay.plusDays(2).seconds(), startDay.plusDays(1).seconds(), listOf(calendarId)) + + Assert.assertEquals(1, eventsDayOne.count()) + Assert.assertEquals(emptyList(), eventsDayTwo) + } + } + + @Test + @Throws(Exception::class) + fun bug255_EventStartingAtMidnightWithoutDurationShouldOnlyShowOnSingleDay() { + expectedFailure("https://github.com/FossifyOrg/Calendar/issues/255") { + val startDay = DateTime(2026, 1, 10, 0, 0) + val event = Event(id = 0, startTS = startDay.seconds(), endTS = startDay.seconds(), calendarId = calendarId) + eventsDao.insertOrUpdate(event) + + val eventsDayOne = eventsDao.getOneTimeEventsFromToWithCalendarIds(startDay.seconds(), startDay.plusDays(-1).seconds(), listOf(calendarId)) + val eventsDayTwo = eventsDao.getOneTimeEventsFromToWithCalendarIds(startDay.plusDays(1).seconds(), startDay.seconds(), listOf(calendarId)) + + Assert.assertEquals(1, eventsDayTwo.count()) + Assert.assertEquals(emptyList(), eventsDayOne) + } + } + + @Test + @Throws(Exception::class) + fun bug440_EventAtMidnightOnFirstJan1970() { + expectedFailure("https://github.com/FossifyOrg/Calendar/issues/440") { + eventsDao.insertOrUpdate(Event(id = 0, startTS = 0, endTS = 3600, calendarId = calendarId)) + + val eventsOnFirstJan1970 = eventsDao.getOneTimeEventsFromToWithCalendarIds(86400, 0, listOf(calendarId)) + + Assert.assertEquals(1, eventsOnFirstJan1970.count()) + } + } +}