@@ -6,10 +6,7 @@ import com.nhaarman.mockitokotlin2.argumentCaptor
66import com.nhaarman.mockitokotlin2.mock
77import com.nhaarman.mockitokotlin2.verify
88import 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
1310import org.junit.Before
1411import org.junit.Rule
1512import org.junit.Test
@@ -19,18 +16,16 @@ import org.mockito.junit.MockitoJUnitRunner
1916import org.wordpress.android.R
2017import org.wordpress.android.fluxc.Dispatcher
2118import org.wordpress.android.fluxc.action.JetpackAction
22- import org.wordpress.android.fluxc.action.JetpackAction.INSTALL_JETPACK
2319import org.wordpress.android.fluxc.annotations.action.Action
2420import org.wordpress.android.fluxc.model.SiteModel
2521import org.wordpress.android.fluxc.store.AccountStore
2622import org.wordpress.android.fluxc.store.JetpackStore
2723import 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
2925import org.wordpress.android.fluxc.store.JetpackStore.OnJetpackInstalled
3026import org.wordpress.android.fluxc.store.SiteStore
27+ import org.wordpress.android.test
3128import 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
3429import org.wordpress.android.ui.JetpackRemoteInstallViewState.Error
3530import org.wordpress.android.ui.JetpackRemoteInstallViewState.Installed
3631import org.wordpress.android.ui.JetpackRemoteInstallViewState.Installing
@@ -65,7 +60,7 @@ class JetpackRemoteInstallViewModelTest {
6560 }
6661
6762 @Test
68- fun `on click starts jetpack install` () = runBlocking {
63+ fun `on click starts jetpack install` () = test {
6964 viewModel.start(site, null )
7065
7166 val startState = viewStates[0 ]
@@ -78,12 +73,12 @@ class JetpackRemoteInstallViewModelTest {
7873 assertInstallingState(installingState)
7974
8075 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)
8378 }
8479
8580 @Test
86- fun `on successful result finishes jetpack install` () = runBlocking {
81+ fun `on successful result finishes jetpack install` () = test {
8782 val updatedSite = mock<SiteModel >()
8883 whenever(siteStore.getSiteByLocalId(siteId)).thenReturn(updatedSite)
8984 whenever(accountStore.hasAccessToken()).thenReturn(true )
@@ -92,57 +87,61 @@ class JetpackRemoteInstallViewModelTest {
9287 val startState = viewStates[0 ]
9388 assertStartState(startState)
9489
95- viewModel.onEventsUpdated(OnJetpackInstalled (true , INSTALL_JETPACK ))
90+ viewModel.onEventsUpdated(OnJetpackInstalled (true , JetpackAction . INSTALL_JETPACK ))
9691 val installedState = viewStates[1 ]
9792 assertInstalledState(installedState)
9893
9994 // Continue after Jetpack is installed
10095 installedState.onClick()
10196
10297 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
106101 }
107102
108103 @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" )
111106 viewModel.start(site, null )
112107
113108 val startState = viewStates[0 ]
114109 assertStartState(startState)
115110
116- viewModel.onEventsUpdated(OnJetpackInstalled (installError, INSTALL_JETPACK ))
111+ viewModel.onEventsUpdated(OnJetpackInstalled (installError, JetpackAction . INSTALL_JETPACK ))
117112
118113 val errorState = viewStates[1 ]
119114 assertErrorState(errorState)
120115
121116 errorState.onClick()
122117
123118 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)
126121 }
127122
128123 @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+ )
131130 viewModel.start(site, null )
132131
133132 val startState = viewStates[0 ]
134133 assertStartState(startState)
135134
136- viewModel.onEventsUpdated(OnJetpackInstalled (installError, INSTALL_JETPACK ))
135+ viewModel.onEventsUpdated(OnJetpackInstalled (installError, JetpackAction . INSTALL_JETPACK ))
137136
138137 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
141140 }
142141
143142 @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( )
146145
147146 val updatedSite = mock<SiteModel >()
148147 whenever(siteStore.getSiteByLocalId(siteId)).thenReturn(updatedSite)
@@ -151,47 +150,47 @@ class JetpackRemoteInstallViewModelTest {
151150 viewModel.onLogin(siteId)
152151
153152 val connectionData = jetpackResultActionData!!
154- assertTrue (connectionData.loggedIn)
155- assertTrue (connectionData.site == updatedSite)
153+ assertThat (connectionData.loggedIn).isTrue
154+ assertThat (connectionData.site == updatedSite).isTrue
156155 }
157156
158157 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 )
166165 }
167166
168167 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 )
176175 }
177176
178177 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 )
186185 }
187186
188187 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 )
196195 }
197196}
0 commit comments