Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ dependencies {
implementation(libs.androidx.print)
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)
}
Original file line number Diff line number Diff line change
@@ -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<Context>()
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<Event>(), 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<Event>(), 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())
}
}
}
Original file line number Diff line number Diff line change
@@ -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.")
}
14 changes: 14 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ swiperefreshlayout = "1.2.0"
work = "2.11.1"
#Room
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
Expand All @@ -35,6 +42,13 @@ 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" }
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]
Expand Down
Loading