@@ -6,10 +6,7 @@ import com.nhaarman.mockitokotlin2.argumentCaptor
6
6
import com.nhaarman.mockitokotlin2.mock
7
7
import com.nhaarman.mockitokotlin2.verify
8
8
import com.nhaarman.mockitokotlin2.whenever
9
- import junit.framework.Assert.assertEquals
10
- import junit.framework.Assert.assertNull
11
- import junit.framework.Assert.assertTrue
12
- import kotlinx.coroutines.runBlocking
9
+ import org.assertj.core.api.Assertions.assertThat
13
10
import org.junit.Before
14
11
import org.junit.Rule
15
12
import org.junit.Test
@@ -19,18 +16,16 @@ import org.mockito.junit.MockitoJUnitRunner
19
16
import org.wordpress.android.R
20
17
import org.wordpress.android.fluxc.Dispatcher
21
18
import org.wordpress.android.fluxc.action.JetpackAction
22
- import org.wordpress.android.fluxc.action.JetpackAction.INSTALL_JETPACK
23
19
import org.wordpress.android.fluxc.annotations.action.Action
24
20
import org.wordpress.android.fluxc.model.SiteModel
25
21
import org.wordpress.android.fluxc.store.AccountStore
26
22
import org.wordpress.android.fluxc.store.JetpackStore
27
23
import org.wordpress.android.fluxc.store.JetpackStore.JetpackInstallError
28
- import org.wordpress.android.fluxc.store.JetpackStore.JetpackInstallErrorType.GENERIC_ERROR
24
+ import org.wordpress.android.fluxc.store.JetpackStore.JetpackInstallErrorType
29
25
import org.wordpress.android.fluxc.store.JetpackStore.OnJetpackInstalled
30
26
import org.wordpress.android.fluxc.store.SiteStore
27
+ import org.wordpress.android.test
31
28
import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData
32
- import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.CONNECT
33
- import org.wordpress.android.ui.JetpackRemoteInstallViewModel.JetpackResultActionData.Action.MANUAL_INSTALL
34
29
import org.wordpress.android.ui.JetpackRemoteInstallViewState.Error
35
30
import org.wordpress.android.ui.JetpackRemoteInstallViewState.Installed
36
31
import org.wordpress.android.ui.JetpackRemoteInstallViewState.Installing
@@ -65,7 +60,7 @@ class JetpackRemoteInstallViewModelTest {
65
60
}
66
61
67
62
@Test
68
- fun `on click starts jetpack install` () = runBlocking {
63
+ fun `on click starts jetpack install` () = test {
69
64
viewModel.start(site, null )
70
65
71
66
val startState = viewStates[0 ]
@@ -78,12 +73,12 @@ class JetpackRemoteInstallViewModelTest {
78
73
assertInstallingState(installingState)
79
74
80
75
verify(dispatcher).dispatch(actionCaptor.capture())
81
- assertEquals (actionCaptor.lastValue.type, JetpackAction .INSTALL_JETPACK )
82
- assertEquals (actionCaptor.lastValue.payload, site)
76
+ assertThat (actionCaptor.lastValue.type).isEqualTo( JetpackAction .INSTALL_JETPACK )
77
+ assertThat (actionCaptor.lastValue.payload).isEqualTo( site)
83
78
}
84
79
85
80
@Test
86
- fun `on successful result finishes jetpack install` () = runBlocking {
81
+ fun `on successful result finishes jetpack install` () = test {
87
82
val updatedSite = mock<SiteModel >()
88
83
whenever(siteStore.getSiteByLocalId(siteId)).thenReturn(updatedSite)
89
84
whenever(accountStore.hasAccessToken()).thenReturn(true )
@@ -92,57 +87,61 @@ class JetpackRemoteInstallViewModelTest {
92
87
val startState = viewStates[0 ]
93
88
assertStartState(startState)
94
89
95
- viewModel.onEventsUpdated(OnJetpackInstalled (true , INSTALL_JETPACK ))
90
+ viewModel.onEventsUpdated(OnJetpackInstalled (true , JetpackAction . INSTALL_JETPACK ))
96
91
val installedState = viewStates[1 ]
97
92
assertInstalledState(installedState)
98
93
99
94
// Continue after Jetpack is installed
100
95
installedState.onClick()
101
96
102
97
val connectionData = jetpackResultActionData!!
103
- assertTrue (connectionData.loggedIn)
104
- assertTrue (connectionData.site == updatedSite)
105
- assertTrue (connectionData.action == CONNECT )
98
+ assertThat (connectionData.loggedIn).isTrue
99
+ assertThat (connectionData.site == updatedSite).isTrue
100
+ assertThat (connectionData.action == JetpackResultActionData . Action . CONNECT ).isTrue
106
101
}
107
102
108
103
@Test
109
- fun `on error result shows failure` () = runBlocking {
110
- val installError = JetpackInstallError (GENERIC_ERROR , " error" )
104
+ fun `on error result shows failure` () = test {
105
+ val installError = JetpackInstallError (JetpackInstallErrorType . GENERIC_ERROR , " error" )
111
106
viewModel.start(site, null )
112
107
113
108
val startState = viewStates[0 ]
114
109
assertStartState(startState)
115
110
116
- viewModel.onEventsUpdated(OnJetpackInstalled (installError, INSTALL_JETPACK ))
111
+ viewModel.onEventsUpdated(OnJetpackInstalled (installError, JetpackAction . INSTALL_JETPACK ))
117
112
118
113
val errorState = viewStates[1 ]
119
114
assertErrorState(errorState)
120
115
121
116
errorState.onClick()
122
117
123
118
verify(dispatcher).dispatch(actionCaptor.capture())
124
- assertEquals (actionCaptor.lastValue.type, JetpackAction .INSTALL_JETPACK )
125
- assertEquals (actionCaptor.lastValue.payload, site)
119
+ assertThat (actionCaptor.lastValue.type).isEqualTo( JetpackAction .INSTALL_JETPACK )
120
+ assertThat (actionCaptor.lastValue.payload).isEqualTo( site)
126
121
}
127
122
128
123
@Test
129
- fun `on invalid credentials triggers manual install` () = runBlocking {
130
- val installError = JetpackInstallError (GENERIC_ERROR , " INVALID_CREDENTIALS" , message = " msg" )
124
+ fun `on invalid credentials triggers manual install` () = test {
125
+ val installError = JetpackInstallError (
126
+ JetpackInstallErrorType .GENERIC_ERROR ,
127
+ " INVALID_CREDENTIALS" ,
128
+ message = " msg"
129
+ )
131
130
viewModel.start(site, null )
132
131
133
132
val startState = viewStates[0 ]
134
133
assertStartState(startState)
135
134
136
- viewModel.onEventsUpdated(OnJetpackInstalled (installError, INSTALL_JETPACK ))
135
+ viewModel.onEventsUpdated(OnJetpackInstalled (installError, JetpackAction . INSTALL_JETPACK ))
137
136
138
137
val connectionData = jetpackResultActionData!!
139
- assertTrue (connectionData.action == MANUAL_INSTALL )
140
- assertTrue (connectionData.site == site)
138
+ assertThat (connectionData.action == JetpackResultActionData . Action . MANUAL_INSTALL ).isTrue
139
+ assertThat (connectionData.site == site).isTrue
141
140
}
142
141
143
142
@Test
144
- fun `on login retries jetpack connect with access token` () = runBlocking {
145
- assertNull (jetpackResultActionData)
143
+ fun `on login retries jetpack connect with access token` () = test {
144
+ assertThat (jetpackResultActionData).isNull( )
146
145
147
146
val updatedSite = mock<SiteModel >()
148
147
whenever(siteStore.getSiteByLocalId(siteId)).thenReturn(updatedSite)
@@ -151,47 +150,47 @@ class JetpackRemoteInstallViewModelTest {
151
150
viewModel.onLogin(siteId)
152
151
153
152
val connectionData = jetpackResultActionData!!
154
- assertTrue (connectionData.loggedIn)
155
- assertTrue (connectionData.site == updatedSite)
153
+ assertThat (connectionData.loggedIn).isTrue
154
+ assertThat (connectionData.site == updatedSite).isTrue
156
155
}
157
156
158
157
private fun assertStartState (state : JetpackRemoteInstallViewState ) {
159
- assertTrue (state is Start )
160
- assertEquals (state.type, JetpackRemoteInstallViewState .Type .START )
161
- assertEquals (state.titleResource, R .string.install_jetpack)
162
- assertEquals (state.messageResource, R .string.install_jetpack_message)
163
- assertEquals (state.icon, R .drawable.ic_plans_white_24dp)
164
- assertEquals (state.buttonResource, R .string.install_jetpack_continue)
165
- assertEquals (state.progressBarVisible, false )
158
+ assertThat (state).isInstanceOf( Start :: class .java )
159
+ assertThat (state.type).isEqualTo( JetpackRemoteInstallViewState .Type .START )
160
+ assertThat (state.titleResource).isEqualTo( R .string.install_jetpack)
161
+ assertThat (state.messageResource).isEqualTo( R .string.install_jetpack_message)
162
+ assertThat (state.icon).isEqualTo( R .drawable.ic_plans_white_24dp)
163
+ assertThat (state.buttonResource).isEqualTo( R .string.install_jetpack_continue)
164
+ assertThat (state.progressBarVisible).isEqualTo( false )
166
165
}
167
166
168
167
private fun assertInstallingState (state : JetpackRemoteInstallViewState ) {
169
- assertTrue (state is Installing )
170
- assertEquals (state.type, JetpackRemoteInstallViewState .Type .INSTALLING )
171
- assertEquals (state.titleResource, R .string.installing_jetpack)
172
- assertEquals (state.messageResource, R .string.installing_jetpack_message)
173
- assertEquals (state.icon, R .drawable.ic_plans_white_24dp)
174
- assertNull (state.buttonResource)
175
- assertEquals (state.progressBarVisible, true )
168
+ assertThat (state).isInstanceOf( Installing :: class .java )
169
+ assertThat (state.type).isEqualTo( JetpackRemoteInstallViewState .Type .INSTALLING )
170
+ assertThat (state.titleResource).isEqualTo( R .string.installing_jetpack)
171
+ assertThat (state.messageResource).isEqualTo( R .string.installing_jetpack_message)
172
+ assertThat (state.icon).isEqualTo( R .drawable.ic_plans_white_24dp)
173
+ assertThat (state.buttonResource).isNull( )
174
+ assertThat (state.progressBarVisible).isEqualTo( true )
176
175
}
177
176
178
177
private fun assertInstalledState (state : JetpackRemoteInstallViewState ) {
179
- assertTrue (state is Installed )
180
- assertEquals (state.type, JetpackRemoteInstallViewState .Type .INSTALLED )
181
- assertEquals (state.titleResource, R .string.jetpack_installed)
182
- assertEquals (state.messageResource, R .string.jetpack_installed_message)
183
- assertEquals (state.icon, R .drawable.ic_plans_white_24dp)
184
- assertEquals (state.buttonResource, R .string.install_jetpack_continue)
185
- assertEquals (state.progressBarVisible, false )
178
+ assertThat (state).isInstanceOf( Installed :: class .java )
179
+ assertThat (state.type).isEqualTo( JetpackRemoteInstallViewState .Type .INSTALLED )
180
+ assertThat (state.titleResource).isEqualTo( R .string.jetpack_installed)
181
+ assertThat (state.messageResource).isEqualTo( R .string.jetpack_installed_message)
182
+ assertThat (state.icon).isEqualTo( R .drawable.ic_plans_white_24dp)
183
+ assertThat (state.buttonResource).isEqualTo( R .string.install_jetpack_continue)
184
+ assertThat (state.progressBarVisible).isEqualTo( false )
186
185
}
187
186
188
187
private fun assertErrorState (state : JetpackRemoteInstallViewState ) {
189
- assertTrue (state is Error )
190
- assertEquals (state.type, JetpackRemoteInstallViewState .Type .ERROR )
191
- assertEquals (state.titleResource, R .string.jetpack_installation_problem)
192
- assertEquals (state.messageResource, R .string.jetpack_installation_problem_message)
193
- assertEquals (state.icon, R .drawable.img_illustration_info_outline_88dp)
194
- assertEquals (state.buttonResource, R .string.install_jetpack_retry)
195
- assertEquals (state.progressBarVisible, false )
188
+ assertThat (state).isInstanceOf( Error :: class .java )
189
+ assertThat (state.type).isEqualTo( JetpackRemoteInstallViewState .Type .ERROR )
190
+ assertThat (state.titleResource).isEqualTo( R .string.jetpack_installation_problem)
191
+ assertThat (state.messageResource).isEqualTo( R .string.jetpack_installation_problem_message)
192
+ assertThat (state.icon).isEqualTo( R .drawable.img_illustration_info_outline_88dp)
193
+ assertThat (state.buttonResource).isEqualTo( R .string.install_jetpack_retry)
194
+ assertThat (state.progressBarVisible).isEqualTo( false )
196
195
}
197
196
}
0 commit comments