forked from github/wulkanowy-mirror
Add account manager (#183)
This commit is contained in:

committed by
Mikołaj Pich

parent
1f30deb36e
commit
7a3c0de7ad
@ -6,6 +6,7 @@ import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.every
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.impl.annotations.SpyK
|
||||
import io.reactivex.Single
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
@ -15,8 +16,8 @@ import java.sql.Date
|
||||
|
||||
class AttendanceRemoteTest {
|
||||
|
||||
@MockK
|
||||
private lateinit var mockApi: Api
|
||||
@SpyK
|
||||
private var mockApi = Api()
|
||||
|
||||
@MockK
|
||||
private lateinit var semesterMock: Semester
|
||||
@ -27,7 +28,7 @@ class AttendanceRemoteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getExamsTest() {
|
||||
fun getAttendanceTest() {
|
||||
every { mockApi.getAttendance(
|
||||
LocalDate.of(2018, 9, 10),
|
||||
LocalDate.of(2018, 9, 15)
|
||||
|
@ -6,6 +6,7 @@ import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.every
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.impl.annotations.SpyK
|
||||
import io.reactivex.Single
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
@ -15,8 +16,8 @@ import java.sql.Date
|
||||
|
||||
class ExamRemoteTest {
|
||||
|
||||
@MockK
|
||||
private lateinit var mockApi: Api
|
||||
@SpyK
|
||||
private var mockApi = Api()
|
||||
|
||||
@MockK
|
||||
private lateinit var semesterMock: Semester
|
||||
|
@ -10,7 +10,7 @@ import org.mockito.Mock
|
||||
import org.mockito.Mockito.doReturn
|
||||
import org.mockito.MockitoAnnotations
|
||||
|
||||
class SessionRemoteTest {
|
||||
class StudentRemoteTest {
|
||||
|
||||
@Mock
|
||||
private lateinit var mockApi: Api
|
||||
@ -23,9 +23,9 @@ class SessionRemoteTest {
|
||||
@Test
|
||||
fun testRemoteAll() {
|
||||
doReturn(Single.just(listOf(Pupil("", "", 1, "test", "", "", Api.LoginType.AUTO))))
|
||||
.`when`(mockApi).getPupils()
|
||||
.`when`(mockApi).getPupils()
|
||||
|
||||
val students = SessionRemote(mockApi).getConnectedStudents("", "", "", "http://fakelog.cf").blockingGet()
|
||||
val students = StudentRemote(mockApi).getStudents("", "", "").blockingGet()
|
||||
assertEquals(1, students.size)
|
||||
assertEquals("test", students.first().studentName)
|
||||
}
|
@ -6,6 +6,7 @@ import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.mockk.MockKAnnotations
|
||||
import io.mockk.every
|
||||
import io.mockk.impl.annotations.MockK
|
||||
import io.mockk.impl.annotations.SpyK
|
||||
import io.reactivex.Single
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Before
|
||||
@ -15,8 +16,8 @@ import java.sql.Date
|
||||
|
||||
class TimetableRemoteTest {
|
||||
|
||||
@MockK
|
||||
private lateinit var mockApi: Api
|
||||
@SpyK
|
||||
private var mockApi = Api()
|
||||
|
||||
@MockK
|
||||
private lateinit var semesterMock: Semester
|
||||
@ -27,7 +28,7 @@ class TimetableRemoteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun getExamsTest() {
|
||||
fun getTimetableTest() {
|
||||
every { mockApi.getTimetable(
|
||||
LocalDate.of(2018, 9, 10),
|
||||
LocalDate.of(2018, 9, 15)
|
||||
|
@ -2,7 +2,7 @@ package io.github.wulkanowy.ui.modules.login.form
|
||||
|
||||
import io.github.wulkanowy.TestSchedulersProvider
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.SessionRepository
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
|
||||
import io.reactivex.Single
|
||||
import org.junit.Before
|
||||
@ -22,7 +22,7 @@ class LoginFormPresenterTest {
|
||||
lateinit var loginFormView: LoginFormView
|
||||
|
||||
@Mock
|
||||
lateinit var repository: SessionRepository
|
||||
lateinit var repository: StudentRepository
|
||||
|
||||
@Mock
|
||||
lateinit var errorHandler: LoginErrorHandler
|
||||
@ -75,7 +75,7 @@ class LoginFormPresenterTest {
|
||||
@Test
|
||||
fun emptySymbolLoginTest() {
|
||||
doReturn(Single.just(emptyList<Student>()))
|
||||
.`when`(repository).getConnectedStudents(anyString(), anyString(), anyString(), anyString())
|
||||
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
||||
presenter.attemptLogin("@", "123456", "", "https://fakelog.cf")
|
||||
presenter.attemptLogin("@", "123456", "", "https://fakelog.cf")
|
||||
|
||||
@ -86,7 +86,7 @@ class LoginFormPresenterTest {
|
||||
fun loginTest() {
|
||||
val studentTest = Student(email = "test@", password = "123", endpoint = "https://fakelog.cf", loginType = "AUTO")
|
||||
doReturn(Single.just(listOf(studentTest)))
|
||||
.`when`(repository).getConnectedStudents(anyString(), anyString(), anyString(), anyString())
|
||||
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
||||
presenter.attemptLogin("@", "123456", "test", "https://fakelog.cf")
|
||||
|
||||
verify(loginFormView).hideSoftKeyboard()
|
||||
@ -100,7 +100,7 @@ class LoginFormPresenterTest {
|
||||
@Test
|
||||
fun loginEmptyTest() {
|
||||
doReturn(Single.just(emptyList<Student>()))
|
||||
.`when`(repository).getConnectedStudents(anyString(), anyString(), anyString(), anyString())
|
||||
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
||||
presenter.attemptLogin("@", "123456", "test", "https://fakelog.cf")
|
||||
|
||||
verify(loginFormView).hideSoftKeyboard()
|
||||
@ -114,7 +114,7 @@ class LoginFormPresenterTest {
|
||||
@Test
|
||||
fun loginEmptyTwiceTest() {
|
||||
doReturn(Single.just(emptyList<Student>()))
|
||||
.`when`(repository).getConnectedStudents(anyString(), anyString(), anyString(), anyString())
|
||||
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
||||
presenter.attemptLogin("@", "123456", "", "https://fakelog.cf")
|
||||
presenter.attemptLogin("@", "123456", "test", "https://fakelog.cf")
|
||||
|
||||
@ -132,7 +132,7 @@ class LoginFormPresenterTest {
|
||||
fun loginErrorTest() {
|
||||
val testException = RuntimeException("test")
|
||||
doReturn(Single.error<List<Student>>(testException))
|
||||
.`when`(repository).getConnectedStudents(anyString(), anyString(), anyString(), anyString())
|
||||
.`when`(repository).getStudents(anyString(), anyString(), anyString(), anyString())
|
||||
presenter.attemptLogin("@", "123456", "test", "https://fakelog.cf")
|
||||
|
||||
verify(loginFormView).hideSoftKeyboard()
|
||||
|
@ -1,9 +1,11 @@
|
||||
package io.github.wulkanowy.ui.modules.login.options
|
||||
|
||||
import io.github.wulkanowy.TestSchedulersProvider
|
||||
import io.github.wulkanowy.data.ErrorHandler
|
||||
import io.github.wulkanowy.data.db.entities.Semester
|
||||
import io.github.wulkanowy.data.db.entities.Student
|
||||
import io.github.wulkanowy.data.repositories.SessionRepository
|
||||
import io.github.wulkanowy.data.repositories.SemesterRepository
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
import io.github.wulkanowy.ui.modules.login.LoginErrorHandler
|
||||
import io.reactivex.Completable
|
||||
import io.reactivex.Single
|
||||
import org.junit.Before
|
||||
@ -17,13 +19,16 @@ import org.mockito.MockitoAnnotations
|
||||
class LoginOptionsPresenterTest {
|
||||
|
||||
@Mock
|
||||
lateinit var errorHandler: ErrorHandler
|
||||
lateinit var errorHandler: LoginErrorHandler
|
||||
|
||||
@Mock
|
||||
lateinit var loginOptionsView: LoginOptionsView
|
||||
|
||||
@Mock
|
||||
lateinit var repository: SessionRepository
|
||||
lateinit var studentRepository: StudentRepository
|
||||
|
||||
@Mock
|
||||
lateinit var semesterRepository: SemesterRepository
|
||||
|
||||
private lateinit var presenter: LoginOptionsPresenter
|
||||
|
||||
@ -34,8 +39,9 @@ class LoginOptionsPresenterTest {
|
||||
@Before
|
||||
fun initPresenter() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
clearInvocations(repository, loginOptionsView)
|
||||
presenter = LoginOptionsPresenter(errorHandler, repository, TestSchedulersProvider())
|
||||
clearInvocations(studentRepository, loginOptionsView)
|
||||
clearInvocations(semesterRepository, loginOptionsView)
|
||||
presenter = LoginOptionsPresenter(errorHandler, studentRepository, semesterRepository, TestSchedulersProvider())
|
||||
presenter.onAttachView(loginOptionsView)
|
||||
}
|
||||
|
||||
@ -46,7 +52,7 @@ class LoginOptionsPresenterTest {
|
||||
|
||||
@Test
|
||||
fun refreshDataTest() {
|
||||
doReturn(Single.just(listOf(testStudent))).`when`(repository).cachedStudents
|
||||
doReturn(Single.just(listOf(testStudent))).`when`(studentRepository).cachedStudents
|
||||
presenter.onParentViewLoadData()
|
||||
verify(loginOptionsView).showActionBar(true)
|
||||
verify(loginOptionsView).updateData(listOf(LoginOptionsItem(testStudent)))
|
||||
@ -54,7 +60,7 @@ class LoginOptionsPresenterTest {
|
||||
|
||||
@Test
|
||||
fun refreshDataErrorTest() {
|
||||
doReturn(Single.error<List<Student>>(testException)).`when`(repository).cachedStudents
|
||||
doReturn(Single.error<List<Student>>(testException)).`when`(studentRepository).cachedStudents
|
||||
presenter.onParentViewLoadData()
|
||||
verify(loginOptionsView).showActionBar(true)
|
||||
verify(errorHandler).proceed(testException)
|
||||
@ -62,8 +68,9 @@ class LoginOptionsPresenterTest {
|
||||
|
||||
@Test
|
||||
fun onSelectedStudentTest() {
|
||||
doReturn(Completable.complete()).`when`(repository).saveStudent(testStudent)
|
||||
presenter.onSelectItem(LoginOptionsItem(testStudent))
|
||||
doReturn(Completable.complete()).`when`(studentRepository).saveStudent(testStudent)
|
||||
doReturn(Single.just(emptyList<Semester>())).`when`(semesterRepository).getSemesters(testStudent, true)
|
||||
presenter.onItemSelected(LoginOptionsItem(testStudent))
|
||||
verify(loginOptionsView).showContent(false)
|
||||
verify(loginOptionsView).showProgress(true)
|
||||
verify(loginOptionsView).openMainView()
|
||||
@ -71,8 +78,10 @@ class LoginOptionsPresenterTest {
|
||||
|
||||
@Test
|
||||
fun onSelectedStudentErrorTest() {
|
||||
doReturn(Completable.error(testException)).`when`(repository).saveStudent(testStudent)
|
||||
presenter.onSelectItem(LoginOptionsItem(testStudent))
|
||||
doReturn(Completable.error(testException)).`when`(studentRepository).saveStudent(testStudent)
|
||||
doReturn(Single.just(emptyList<Semester>())).`when`(semesterRepository).getSemesters(testStudent, true)
|
||||
doReturn(Completable.complete()).`when`(studentRepository).logoutCurrentStudent()
|
||||
presenter.onItemSelected(LoginOptionsItem(testStudent))
|
||||
verify(loginOptionsView).showContent(false)
|
||||
verify(loginOptionsView).showProgress(true)
|
||||
verify(errorHandler).proceed(testException)
|
||||
|
@ -1,7 +1,7 @@
|
||||
package io.github.wulkanowy.ui.modules.splash
|
||||
|
||||
import io.github.wulkanowy.data.ErrorHandler
|
||||
import io.github.wulkanowy.data.repositories.SessionRepository
|
||||
import io.github.wulkanowy.data.repositories.StudentRepository
|
||||
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 sessionRepository: SessionRepository
|
||||
lateinit var studentRepository: StudentRepository
|
||||
|
||||
@Mock
|
||||
lateinit var errorHandler: ErrorHandler
|
||||
@ -25,19 +25,19 @@ class SplashPresenterTest {
|
||||
@Before
|
||||
fun initPresenter() {
|
||||
MockitoAnnotations.initMocks(this)
|
||||
presenter = SplashPresenter(sessionRepository, errorHandler)
|
||||
presenter = SplashPresenter(studentRepository, errorHandler)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOpenLoginView() {
|
||||
doReturn(false).`when`(sessionRepository).isSessionSaved
|
||||
doReturn(false).`when`(studentRepository).isStudentSaved
|
||||
presenter.onAttachView(splashView)
|
||||
verify(splashView).openLoginView()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMainMainView() {
|
||||
doReturn(true).`when`(sessionRepository).isSessionSaved
|
||||
doReturn(true).`when`(studentRepository).isStudentSaved
|
||||
presenter.onAttachView(splashView)
|
||||
verify(splashView).openMainView()
|
||||
}
|
||||
|
Reference in New Issue
Block a user