Skip to content

Commit 850d3f6

Browse files
committed
Added signIn to local tests.
Added mocks for local tests
1 parent 8aa9b72 commit 850d3f6

File tree

5 files changed

+153
-4
lines changed

5 files changed

+153
-4
lines changed

app/src/androidTest/java/com/codemitry/wearer/mvp/presenters/SignInCheckerMock.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ class SignInCheckerMock(val signedIn: Boolean = false) : SplashContract.SignInCh
1212
override fun userId(): String? {
1313
return if (signedIn) "mocked_uid" else null
1414
}
15+
16+
override fun saveUserId(uid: String) = Unit
1517
}

app/src/androidTest/java/com/codemitry/wearer/mvp/presenters/SignInInteractorMock.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
package com.codemitry.wearer.mvp.presenters
22

3-
import com.codemitry.wearer.db.DBManager
43
import com.codemitry.wearer.mvp.contracts.signin.SignInContract
54

6-
class SignInInteractorMock(val successSignIn: Boolean = false) : SignInContract.SignInInteractor {
5+
class SignInInteractorMock(var successSignIn: Boolean = false) : SignInContract.SignInInteractor {
76

87
override var onSignInListener: SignInContract.SignInInteractor.OnSignInListener? = null
98

109
override fun performFirebaseThroughGoogleSignIn(idToken: String) {
1110
if (successSignIn) {
12-
DBManager.uid = "mock_uid"
1311
onSignInListener?.onSuccess()
1412
} else {
1513
// Sign in fails
@@ -19,7 +17,6 @@ class SignInInteractorMock(val successSignIn: Boolean = false) : SignInContract.
1917

2018
override fun performFirebaseThroughAnonymousSignIn() {
2119
if (successSignIn) {
22-
DBManager.uid = "mock_uid"
2320
onSignInListener?.onSuccess()
2421
} else {
2522
// Sign in fails
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.codemitry.wearer.mocks
2+
3+
import com.codemitry.wearer.mvp.contracts.splash.SplashContract
4+
5+
class SignInCheckerMock(val signedIn: Boolean = false) : SplashContract.SignInChecker {
6+
7+
8+
override fun signedIn(): Boolean {
9+
return signedIn
10+
}
11+
12+
override fun userId(): String? {
13+
return if (signedIn) "mocked_uid" else null
14+
}
15+
16+
override fun saveUserId(uid: String) = Unit
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.codemitry.wearer.mocks
2+
3+
import com.codemitry.wearer.mvp.contracts.signin.SignInContract
4+
5+
class SignInInteractorMock(var successSignIn: Boolean = false) : SignInContract.SignInInteractor {
6+
7+
override var onSignInListener: SignInContract.SignInInteractor.OnSignInListener? = null
8+
9+
override fun performFirebaseThroughGoogleSignIn(idToken: String) {
10+
if (successSignIn) {
11+
onSignInListener?.onSuccess()
12+
} else {
13+
// Sign in fails
14+
onSignInListener?.onFailure()
15+
}
16+
}
17+
18+
override fun performFirebaseThroughAnonymousSignIn() {
19+
if (successSignIn) {
20+
onSignInListener?.onSuccess()
21+
} else {
22+
// Sign in fails
23+
onSignInListener?.onFailure()
24+
}
25+
}
26+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
package com.codemitry.wearer.signin
2+
3+
import com.codemitry.wearer.mocks.SignInInteractorMock
4+
import com.codemitry.wearer.mvp.contracts.signin.SignInContract
5+
import com.codemitry.wearer.mvp.presenters.SignInPresenter
6+
import junit.framework.Assert.assertTrue
7+
import org.junit.Before
8+
import org.junit.Test
9+
10+
class PresenterTest {
11+
12+
private class ViewMock : SignInContract.SignInView {
13+
14+
var shouldShowSignInErrorCalled = false
15+
var shouldShowMainActivityCalled = false
16+
var shouldStartGoogleSignInFlowCalled = false
17+
18+
override fun showSignInError() {
19+
assertTrue(shouldShowSignInErrorCalled)
20+
}
21+
22+
override fun showMainActivity() {
23+
assertTrue(shouldShowMainActivityCalled)
24+
25+
}
26+
27+
override fun startGoogleSignInFlow() {
28+
assertTrue(shouldStartGoogleSignInFlowCalled)
29+
}
30+
}
31+
32+
private val presenter = SignInPresenter()
33+
private val view = ViewMock()
34+
private val signInInteractor = SignInInteractorMock(false)
35+
36+
init {
37+
presenter.onViewAttached(view)
38+
presenter.signInInteractor = signInInteractor
39+
presenter.signInInteractor.onSignInListener = presenter
40+
}
41+
42+
@Before
43+
fun init() {
44+
view.shouldStartGoogleSignInFlowCalled = false
45+
view.shouldShowMainActivityCalled = false
46+
view.shouldShowSignInErrorCalled = false
47+
48+
signInInteractor.successSignIn = false
49+
}
50+
51+
@Test
52+
fun googleSuccessSignIn() {
53+
signInInteractor.successSignIn = true
54+
55+
view.shouldStartGoogleSignInFlowCalled = true
56+
57+
presenter.onGoogleSignInClick()
58+
59+
view.shouldStartGoogleSignInFlowCalled = false
60+
view.shouldShowMainActivityCalled = true
61+
62+
presenter.onGoogleSignInSuccessful("mock")
63+
}
64+
65+
@Test
66+
fun googleFailureFirstSignIn() {
67+
view.shouldStartGoogleSignInFlowCalled = true
68+
69+
presenter.onGoogleSignInClick()
70+
71+
view.shouldStartGoogleSignInFlowCalled = false
72+
view.shouldShowSignInErrorCalled = true
73+
}
74+
75+
@Test
76+
fun googleFailureSecondSignIn() {
77+
signInInteractor.successSignIn = true
78+
view.shouldStartGoogleSignInFlowCalled = true
79+
80+
presenter.onGoogleSignInClick()
81+
82+
view.shouldStartGoogleSignInFlowCalled = false
83+
84+
signInInteractor.successSignIn = false
85+
86+
view.shouldShowSignInErrorCalled = true
87+
presenter.onGoogleSignInSuccessful("mock")
88+
89+
}
90+
91+
92+
@Test
93+
fun anonSuccessSignIn() {
94+
signInInteractor.successSignIn = true
95+
96+
view.shouldShowMainActivityCalled = true
97+
98+
presenter.onAnonymousSignInClick()
99+
}
100+
101+
@Test
102+
fun anonFailureSignIn() {
103+
view.shouldShowSignInErrorCalled = true
104+
105+
presenter.onAnonymousSignInClick()
106+
}
107+
}

0 commit comments

Comments
 (0)