Refactor timetable module (#160)

This commit is contained in:
Mikołaj Pich
2018-10-06 10:53:34 +02:00
committed by Rafał Borcz
parent f2b7c0e781
commit 5cd8ed88c0
33 changed files with 945 additions and 593 deletions

View File

@ -0,0 +1,54 @@
package io.github.wulkanowy.data.repositories.remote
import io.github.wulkanowy.api.Api
import io.github.wulkanowy.api.timetable.Timetable
import io.github.wulkanowy.data.db.entities.Semester
import io.mockk.MockKAnnotations
import io.mockk.every
import io.mockk.impl.annotations.MockK
import io.reactivex.Single
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.threeten.bp.LocalDate
import org.threeten.bp.LocalDateTime
import java.sql.Date
class TimetableRemoteTest {
@MockK
private lateinit var mockApi: Api
@MockK
private lateinit var semesterMock: Semester
@Before
fun initApi() {
MockKAnnotations.init(this)
}
@Test
fun getExamsTest() {
every { mockApi.getTimetable(
LocalDate.of(2018, 9, 10),
LocalDate.of(2018, 9, 15)
) } returns Single.just(listOf(
getTimetable("2018-09-10"),
getTimetable("2018-09-17")
))
every { mockApi.diaryId } returns "1"
every { semesterMock.studentId } returns "1"
every { semesterMock.diaryId } returns "1"
val timetable = TimetableRemote(mockApi).getLessons(semesterMock,
LocalDate.of(2018, 9, 10),
LocalDate.of(2018, 9, 15)
).blockingGet()
assertEquals(2, timetable.size)
}
private fun getTimetable(dateString: String): Timetable {
return Timetable(date = Date.valueOf(dateString))
}
}

View File

@ -3,6 +3,7 @@ package io.github.wulkanowy.utils
import org.junit.Assert.*
import org.junit.Test
import org.threeten.bp.LocalDate
import org.threeten.bp.LocalDateTime
import java.util.*
class TimeExtensionTest {
@ -18,6 +19,12 @@ class TimeExtensionTest {
assertEquals("2018-10.01", LocalDate.of(2018, 10, 1).toFormattedString("yyyy-MM.dd"))
}
@Test
fun toFormat_LocalDateTime() {
assertEquals("2018-10-01", LocalDateTime.of(2018, 10, 1, 10, 0, 0).toFormattedString())
assertEquals("2018-10-01 10:00:00", LocalDateTime.of(2018, 10, 1, 10, 0, 0).toFormattedString("uuuu-MM-dd HH:mm:ss"))
}
@Test
fun weekFirstDayAlwaysCurrentTest() {
assertEquals(LocalDate.of(2018, 10, 1), LocalDate.of(2018, 10, 2).weekFirstDayAlwaysCurrent)