forked from github/wulkanowy-mirror
Migrate to new api (#155)
This commit is contained in:

committed by
Mikołaj Pich

parent
0e962c17c2
commit
b617957891
@ -1,64 +1,32 @@
|
||||
package io.github.wulkanowy.data.repositories.remote
|
||||
|
||||
import io.github.wulkanowy.api.StudentAndParent
|
||||
import io.github.wulkanowy.api.Vulcan
|
||||
import io.github.wulkanowy.api.generic.School
|
||||
import io.github.wulkanowy.api.login.AccountPermissionException
|
||||
import io.github.wulkanowy.api.Api
|
||||
import io.github.wulkanowy.api.register.Pupil
|
||||
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.*
|
||||
import org.mockito.Mockito.doReturn
|
||||
import org.mockito.MockitoAnnotations
|
||||
import io.github.wulkanowy.api.generic.Student as StudentApi
|
||||
|
||||
class StudentRemoteTest {
|
||||
|
||||
@Mock
|
||||
private lateinit var mockApi: Vulcan
|
||||
private lateinit var mockApi: Api
|
||||
|
||||
@Before
|
||||
fun initApi() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
doNothing().`when`(mockApi).setCredentials(any(), any(), any(), any(), any(), any())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testRemoteAll() {
|
||||
`when`(mockApi.symbols).thenReturn(mutableListOf("przeworsk", "jaroslaw", "zarzecze"))
|
||||
`when`(mockApi.schools).thenReturn(mutableListOf(
|
||||
School("ZSTIO", "123", false),
|
||||
School("ZSZ", "998", true)))
|
||||
|
||||
val mockSnP = mock(StudentAndParent::class.java)
|
||||
`when`(mockSnP.students).thenReturn(mutableListOf(
|
||||
StudentApi().apply {
|
||||
id = "20"
|
||||
name = "Włodzimierz"
|
||||
isCurrent = false
|
||||
}))
|
||||
`when`(mockApi.studentAndParent).thenReturn(mockSnP)
|
||||
doReturn(Single.just(listOf(Pupil("", "", "", "test", "", ""))))
|
||||
.`when`(mockApi).getPupils()
|
||||
|
||||
val students = StudentRemote(mockApi).getConnectedStudents("", "", "").blockingGet()
|
||||
assert(students.size == 6)
|
||||
assert(students[3].studentName == "Włodzimierz")
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOneEmptySymbol() {
|
||||
doReturn(mutableListOf("przeworsk")).`when`(mockApi).symbols
|
||||
doThrow(AccountPermissionException::class.java).`when`(mockApi).schools
|
||||
|
||||
val students = StudentRemote(mockApi).getConnectedStudents("", "", "").blockingGet()
|
||||
assert(students.isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDefaultSymbol() {
|
||||
doReturn(listOf("Default")).`when`(mockApi).symbols
|
||||
|
||||
val students = StudentRemote(mockApi).getConnectedStudents("", "", "").blockingGet()
|
||||
assert(students.isEmpty())
|
||||
assertEquals(1, students.size)
|
||||
assertEquals("test", students.first().studentName)
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ 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.reactivex.Completable
|
||||
import io.reactivex.Single
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
@ -61,8 +62,8 @@ class LoginOptionsPresenterTest {
|
||||
|
||||
@Test
|
||||
fun onSelectedStudentTest() {
|
||||
doReturn(Completable.complete()).`when`(repository).save(testStudent)
|
||||
presenter.onSelectStudent(testStudent)
|
||||
verify(repository).save(testStudent)
|
||||
verify(loginOptionsView).showLoginProgress(true)
|
||||
verify(loginOptionsView).openMainView()
|
||||
|
||||
@ -70,7 +71,7 @@ class LoginOptionsPresenterTest {
|
||||
|
||||
@Test
|
||||
fun onSelectedStudentErrorTest() {
|
||||
doThrow(testException).`when`(repository).save(testStudent)
|
||||
doReturn(Completable.error(testException)).`when`(repository).save(testStudent)
|
||||
presenter.onSelectStudent(testStudent)
|
||||
verify(loginOptionsView).showLoginProgress(true)
|
||||
verify(errorHandler).proceed(testException)
|
||||
|
Reference in New Issue
Block a user