forked from github/wulkanowy-mirror
Refactor exam module (#157)
This commit is contained in:

committed by
Rafał Borcz

parent
b617957891
commit
a1f64baca4
@ -0,0 +1,56 @@
|
||||
package io.github.wulkanowy.data.repositories.remote
|
||||
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.api.exams.Exam
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.reactivex.Single
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.ArgumentMatchers.any
|
||||
import org.mockito.Mock
|
||||
import org.mockito.Mockito.doReturn
|
||||
import org.mockito.MockitoAnnotations
|
||||
import org.threeten.bp.LocalDate
|
||||
import java.sql.Date
|
||||
|
||||
class ExamRemoteTest {
|
||||
|
||||
@Mock
|
||||
private lateinit var mockApi: Api
|
||||
|
||||
@Mock
|
||||
private lateinit var semesterMock: Semester
|
||||
|
||||
@Before
|
||||
fun initApi() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getExamsTest() {
|
||||
doReturn(Single.just(listOf(
|
||||
getExam("2018-09-10"),
|
||||
getExam("2018-09-17")
|
||||
))).`when`(mockApi).getExams(any())
|
||||
|
||||
doReturn("1").`when`(semesterMock).studentId
|
||||
doReturn("1").`when`(semesterMock).diaryId
|
||||
|
||||
val exams = ExamRemote(mockApi).getExams(semesterMock, LocalDate.of(2018, 9, 10)).blockingGet()
|
||||
assertEquals(2, exams.size)
|
||||
}
|
||||
|
||||
private fun getExam(dateString: String): Exam {
|
||||
return Exam().apply {
|
||||
subject = ""
|
||||
group = ""
|
||||
type = ""
|
||||
description = ""
|
||||
teacher = ""
|
||||
teacherSymbol = ""
|
||||
date = Date.valueOf(dateString)
|
||||
entryDate = Date.valueOf(dateString)
|
||||
}
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ class StudentRemoteTest {
|
||||
doReturn(Single.just(listOf(Pupil("", "", "", "test", "", ""))))
|
||||
.`when`(mockApi).getPupils()
|
||||
|
||||
val students = StudentRemote(mockApi).getConnectedStudents("", "", "").blockingGet()
|
||||
val students = SessionRemote(mockApi).getConnectedStudents("", "", "").blockingGet()
|
||||
assertEquals(1, students.size)
|
||||
assertEquals("test", students.first().studentName)
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package io.github.wulkanowy.ui.login.form
|
||||
|
||||
import io.github.wulkanowy.TestSchedulers
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.data.repositories.SessionRepository
|
||||
import io.github.wulkanowy.ui.login.LoginErrorHandler
|
||||
import io.reactivex.Single
|
||||
import org.junit.Before
|
||||
@ -18,7 +18,7 @@ class LoginFormPresenterTest {
|
||||
lateinit var loginFormView: LoginFormView
|
||||
|
||||
@Mock
|
||||
lateinit var repository: StudentRepository
|
||||
lateinit var repository: SessionRepository
|
||||
|
||||
@Mock
|
||||
lateinit var errorHandler: LoginErrorHandler
|
||||
|
@ -3,7 +3,7 @@ package io.github.wulkanowy.ui.login.options
|
||||
import io.github.wulkanowy.TestSchedulers
|
||||
import io.github.wulkanowy.data.ErrorHandler
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.data.repositories.SessionRepository
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Single
|
||||
import org.junit.Before
|
||||
@ -21,7 +21,7 @@ class LoginOptionsPresenterTest {
|
||||
lateinit var loginOptionsView: LoginOptionsView
|
||||
|
||||
@Mock
|
||||
lateinit var repository: StudentRepository
|
||||
lateinit var repository: SessionRepository
|
||||
|
||||
private lateinit var presenter: LoginOptionsPresenter
|
||||
|
||||
@ -62,7 +62,7 @@ class LoginOptionsPresenterTest {
|
||||
|
||||
@Test
|
||||
fun onSelectedStudentTest() {
|
||||
doReturn(Completable.complete()).`when`(repository).save(testStudent)
|
||||
doReturn(Completable.complete()).`when`(repository).saveStudent(testStudent)
|
||||
presenter.onSelectStudent(testStudent)
|
||||
verify(loginOptionsView).showLoginProgress(true)
|
||||
verify(loginOptionsView).openMainView()
|
||||
@ -71,9 +71,9 @@ class LoginOptionsPresenterTest {
|
||||
|
||||
@Test
|
||||
fun onSelectedStudentErrorTest() {
|
||||
doReturn(Completable.error(testException)).`when`(repository).save(testStudent)
|
||||
doReturn(Completable.error(testException)).`when`(repository).saveStudent(testStudent)
|
||||
presenter.onSelectStudent(testStudent)
|
||||
verify(loginOptionsView).showLoginProgress(true)
|
||||
verify(errorHandler).proceed(testException)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package io.github.wulkanowy.ui.splash
|
||||
|
||||
import io.github.wulkanowy.data.ErrorHandler
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.data.repositories.SessionRepository
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mock
|
||||
@ -15,7 +15,7 @@ class SplashPresenterTest {
|
||||
lateinit var splashView: SplashView
|
||||
|
||||
@Mock
|
||||
lateinit var studentRepository: StudentRepository
|
||||
lateinit var studentRepository: SessionRepository
|
||||
|
||||
@Mock
|
||||
lateinit var errorHandler: ErrorHandler
|
||||
@ -30,15 +30,15 @@ class SplashPresenterTest {
|
||||
|
||||
@Test
|
||||
fun testOpenLoginView() {
|
||||
doReturn(false).`when`(studentRepository).isStudentLoggedIn
|
||||
doReturn(false).`when`(studentRepository).isSessionSaved
|
||||
presenter.attachView(splashView)
|
||||
verify(splashView).openLoginActivity()
|
||||
verify(splashView).openLoginView()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMainMainView() {
|
||||
doReturn(true).`when`(studentRepository).isStudentLoggedIn
|
||||
doReturn(true).`when`(studentRepository).isSessionSaved
|
||||
presenter.attachView(splashView)
|
||||
verify(splashView).openMainActivity()
|
||||
verify(splashView).openMainView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -86,55 +86,55 @@ class TimeUtilsTest {
|
||||
}
|
||||
|
||||
@Test fun isHolidaysInSchoolEndTest() {
|
||||
assertFalse(isHolidays(LocalDate.of(2017, 6, 23), 2017))
|
||||
assertFalse(isHolidays(LocalDate.of(2018, 6, 22), 2018))
|
||||
assertFalse(isHolidays(LocalDate.of(2019, 6, 21), 2019))
|
||||
assertFalse(isHolidays(LocalDate.of(2020, 6, 26), 2020))
|
||||
assertFalse(isHolidays(LocalDate.of(2021, 6, 25), 2021))
|
||||
assertFalse(isHolidays(LocalDate.of(2022, 6, 24), 2022))
|
||||
assertFalse(isHolidays(LocalDate.of(2023, 6, 23), 2023))
|
||||
assertFalse(isHolidays(LocalDate.of(2024, 6, 21), 2024))
|
||||
assertFalse(isHolidays(LocalDate.of(2025, 6, 27), 2025))
|
||||
assertFalse(isHolidays(LocalDate.of(2017, 6, 23)))
|
||||
assertFalse(isHolidays(LocalDate.of(2018, 6, 22)))
|
||||
assertFalse(isHolidays(LocalDate.of(2019, 6, 21)))
|
||||
assertFalse(isHolidays(LocalDate.of(2020, 6, 26)))
|
||||
assertFalse(isHolidays(LocalDate.of(2021, 6, 25)))
|
||||
assertFalse(isHolidays(LocalDate.of(2022, 6, 24)))
|
||||
assertFalse(isHolidays(LocalDate.of(2023, 6, 23)))
|
||||
assertFalse(isHolidays(LocalDate.of(2024, 6, 21)))
|
||||
assertFalse(isHolidays(LocalDate.of(2025, 6, 27)))
|
||||
}
|
||||
|
||||
@Test fun isHolidaysInHolidaysStartTest() {
|
||||
assertTrue(isHolidays(LocalDate.of(2017, 6, 24), 2017))
|
||||
assertTrue(isHolidays(LocalDate.of(2018, 6, 23), 2018))
|
||||
assertTrue(isHolidays(LocalDate.of(2019, 6, 22), 2019))
|
||||
assertTrue(isHolidays(LocalDate.of(2020, 6, 27), 2020))
|
||||
assertTrue(isHolidays(LocalDate.of(2021, 6, 26), 2021))
|
||||
assertTrue(isHolidays(LocalDate.of(2022, 6, 25), 2022))
|
||||
assertTrue(isHolidays(LocalDate.of(2023, 6, 24), 2023))
|
||||
assertTrue(isHolidays(LocalDate.of(2024, 6, 22), 2024))
|
||||
assertTrue(isHolidays(LocalDate.of(2025, 6, 28), 2025))
|
||||
assertTrue(isHolidays(LocalDate.of(2017, 6, 24)))
|
||||
assertTrue(isHolidays(LocalDate.of(2018, 6, 23)))
|
||||
assertTrue(isHolidays(LocalDate.of(2019, 6, 22)))
|
||||
assertTrue(isHolidays(LocalDate.of(2020, 6, 27)))
|
||||
assertTrue(isHolidays(LocalDate.of(2021, 6, 26)))
|
||||
assertTrue(isHolidays(LocalDate.of(2022, 6, 25)))
|
||||
assertTrue(isHolidays(LocalDate.of(2023, 6, 24)))
|
||||
assertTrue(isHolidays(LocalDate.of(2024, 6, 22)))
|
||||
assertTrue(isHolidays(LocalDate.of(2025, 6, 28)))
|
||||
}
|
||||
|
||||
@Test fun isHolidaysInHolidaysEndTest() {
|
||||
assertTrue(isHolidays(LocalDate.of(2017, 9, 1), 2017)) // friday
|
||||
assertTrue(isHolidays(LocalDate.of(2017, 9, 2), 2017)) // saturday
|
||||
assertTrue(isHolidays(LocalDate.of(2017, 9, 3), 2017)) // sunday
|
||||
assertTrue(isHolidays(LocalDate.of(2018, 9, 1), 2018)) // saturday
|
||||
assertTrue(isHolidays(LocalDate.of(2018, 9, 2), 2018)) // sunday
|
||||
assertTrue(isHolidays(LocalDate.of(2019, 9, 1), 2019)) // sunday
|
||||
assertTrue(isHolidays(LocalDate.of(2020, 8, 31), 2020)) // monday
|
||||
assertTrue(isHolidays(LocalDate.of(2021, 8, 31), 2021)) // tuesday
|
||||
assertTrue(isHolidays(LocalDate.of(2022, 8, 31), 2022)) // wednesday
|
||||
assertTrue(isHolidays(LocalDate.of(2023, 9, 1), 2023)) // friday
|
||||
assertTrue(isHolidays(LocalDate.of(2023, 9, 2), 2023)) // saturday
|
||||
assertTrue(isHolidays(LocalDate.of(2023, 9, 3), 2023)) // sunday
|
||||
assertTrue(isHolidays(LocalDate.of(2024, 9, 1), 2024)) // sunday
|
||||
assertTrue(isHolidays(LocalDate.of(2025, 8, 31), 2025)) // sunday
|
||||
assertTrue(isHolidays(LocalDate.of(2017, 9, 1))) // friday
|
||||
assertTrue(isHolidays(LocalDate.of(2017, 9, 2))) // saturday
|
||||
assertTrue(isHolidays(LocalDate.of(2017, 9, 3))) // sunday
|
||||
assertTrue(isHolidays(LocalDate.of(2018, 9, 1))) // saturday
|
||||
assertTrue(isHolidays(LocalDate.of(2018, 9, 2))) // sunday
|
||||
assertTrue(isHolidays(LocalDate.of(2019, 9, 1))) // sunday
|
||||
assertTrue(isHolidays(LocalDate.of(2020, 8, 31))) // monday
|
||||
assertTrue(isHolidays(LocalDate.of(2021, 8, 31))) // tuesday
|
||||
assertTrue(isHolidays(LocalDate.of(2022, 8, 31))) // wednesday
|
||||
assertTrue(isHolidays(LocalDate.of(2023, 9, 1))) // friday
|
||||
assertTrue(isHolidays(LocalDate.of(2023, 9, 2))) // saturday
|
||||
assertTrue(isHolidays(LocalDate.of(2023, 9, 3))) // sunday
|
||||
assertTrue(isHolidays(LocalDate.of(2024, 9, 1))) // sunday
|
||||
assertTrue(isHolidays(LocalDate.of(2025, 8, 31))) // sunday
|
||||
}
|
||||
|
||||
@Test fun isHolidaysInSchoolStartTest() {
|
||||
assertFalse(isHolidays(LocalDate.of(2017, 9, 4), 2017)) // monday
|
||||
assertFalse(isHolidays(LocalDate.of(2018, 9, 3), 2018)) // monday
|
||||
assertFalse(isHolidays(LocalDate.of(2019, 9, 2), 2019)) // monday
|
||||
assertFalse(isHolidays(LocalDate.of(2020, 9, 1), 2020)) // tuesday
|
||||
assertFalse(isHolidays(LocalDate.of(2021, 9, 1), 2021)) // wednesday
|
||||
assertFalse(isHolidays(LocalDate.of(2022, 9, 1), 2022)) // thursday
|
||||
assertFalse(isHolidays(LocalDate.of(2023, 9, 4), 2023)) // monday
|
||||
assertFalse(isHolidays(LocalDate.of(2024, 9, 2), 2024)) // monday
|
||||
assertFalse(isHolidays(LocalDate.of(2025, 9, 1), 2025)) // monday
|
||||
assertFalse(isHolidays(LocalDate.of(2017, 9, 4))) // monday
|
||||
assertFalse(isHolidays(LocalDate.of(2018, 9, 3))) // monday
|
||||
assertFalse(isHolidays(LocalDate.of(2019, 9, 2))) // monday
|
||||
assertFalse(isHolidays(LocalDate.of(2020, 9, 1))) // tuesday
|
||||
assertFalse(isHolidays(LocalDate.of(2021, 9, 1))) // wednesday
|
||||
assertFalse(isHolidays(LocalDate.of(2022, 9, 1))) // thursday
|
||||
assertFalse(isHolidays(LocalDate.of(2023, 9, 4))) // monday
|
||||
assertFalse(isHolidays(LocalDate.of(2024, 9, 2))) // monday
|
||||
assertFalse(isHolidays(LocalDate.of(2025, 9, 1))) // monday
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user