@@ -57,7 +57,7 @@ import com.owncloud.android.testutil.OC_SECURE_SERVER_INFO_BASIC_AUTH
5757import com.owncloud.android.testutil.OC_USER_INFO
5858import com.owncloud.android.testutil.oauth.OC_CLIENT_REGISTRATION
5959import io.mockk.every
60- import io.mockk.mockkClass
60+ import io.mockk.mockk
6161import io.mockk.spyk
6262import io.mockk.verify
6363import org.junit.Assert.assertEquals
@@ -73,11 +73,11 @@ class OCLocalAuthenticationDataSourceTest {
7373 val instantExecutorRule = InstantTaskExecutorRule ()
7474
7575 private lateinit var ocLocalAuthenticationDataSource: OCLocalAuthenticationDataSource
76- private val accountManager = mockkClass( AccountManager :: class )
76+ private val accountManager = mockk< AccountManager >(relaxUnitFun = true )
7777 private val preferencesProvider = spyk<SharedPreferencesProvider >()
7878
7979 @Before
80- fun init () {
80+ fun setUp () {
8181 val context = InstrumentationRegistry .getInstrumentation().targetContext
8282
8383 ocLocalAuthenticationDataSource = OCLocalAuthenticationDataSource (
@@ -86,6 +86,13 @@ class OCLocalAuthenticationDataSourceTest {
8686 preferencesProvider,
8787 OC_ACCOUNT .type
8888 )
89+ getAccountsByType(OC_ACCOUNT .type, arrayOf(OC_ACCOUNT ))
90+ }
91+
92+ private fun getAccountsByType (accountType : String , accounts : Array <Account >) {
93+ every {
94+ accountManager.getAccountsByType(accountType)
95+ } returns accounts
8996 }
9097
9198 @Test
@@ -102,7 +109,7 @@ class OCLocalAuthenticationDataSourceTest {
102109 null
103110 )
104111
105- val newAccount = Account (OC_ACCOUNT_NAME , " owncloud " )
112+ val newAccount = Account (OC_ACCOUNT_NAME , OC_ACCOUNT .type )
106113
107114 // One for checking if the account exists and another one for getting the new account
108115 verifyAccountsByTypeAreGot(newAccount.type, 2 )
@@ -115,9 +122,6 @@ class OCLocalAuthenticationDataSourceTest {
115122
116123 @Test(expected = AccountNotNewException ::class )
117124 fun addBasicAccountAlreadyExistsNoUpdate () {
118- every {
119- accountManager.getAccountsByType(OC_ACCOUNT .type)
120- } returns arrayOf(OC_ACCOUNT ) // The account is already there
121125
122126 ocLocalAuthenticationDataSource.addBasicAccount(
123127 OC_ACCOUNT_ID ,
@@ -131,17 +135,6 @@ class OCLocalAuthenticationDataSourceTest {
131135
132136 @Test
133137 fun addBasicAccountAlreadyExistsUpdateSameUsername () {
134- every {
135- accountManager.getAccountsByType(OC_ACCOUNT .type)
136- } returns arrayOf(OC_ACCOUNT ) // The account is already there
137-
138- every {
139- accountManager.setPassword(any(), any())
140- } returns Unit
141-
142- every {
143- accountManager.setUserData(any(), any(), any())
144- } returns Unit
145138
146139 mockSelectedAccountNameInPreferences()
147140
@@ -167,10 +160,6 @@ class OCLocalAuthenticationDataSourceTest {
167160 @Test
168161 fun addBasicAccountAlreadyExistsUpdateDifferentUsername () {
169162
170- every {
171- accountManager.setUserData(any(), any(), any())
172- } returns Unit
173-
174163 mockSelectedAccountNameInPreferences()
175164
176165 try {
@@ -198,10 +187,6 @@ class OCLocalAuthenticationDataSourceTest {
198187 mockRegularAccountCreationFlow()
199188 mockSelectedAccountNameInPreferences()
200189
201- every {
202- accountManager.setAuthToken(any(), any(), any())
203- } returns Unit
204-
205190 val newAccountName = ocLocalAuthenticationDataSource.addOAuthAccount(
206191 OC_ACCOUNT_ID ,
207192 OC_REDIRECTION_PATH .lastPermanentLocation,
@@ -215,7 +200,7 @@ class OCLocalAuthenticationDataSourceTest {
215200 OC_CLIENT_REGISTRATION
216201 )
217202
218- val newAccount = Account (OC_ACCOUNT_NAME , " owncloud " )
203+ val newAccount = Account (OC_ACCOUNT_NAME , OC_ACCOUNT .type )
219204
220205 // One for checking if the account exists and another one for getting the new account
221206 verifyAccountsByTypeAreGot(newAccount.type, 2 )
@@ -231,9 +216,6 @@ class OCLocalAuthenticationDataSourceTest {
231216
232217 @Test(expected = AccountNotNewException ::class )
233218 fun addOAuthAccountAlreadyExistsNoUpdate () {
234- every {
235- accountManager.getAccountsByType(OC_ACCOUNT .type)
236- } returns arrayOf(OC_ACCOUNT ) // The account is already there
237219
238220 ocLocalAuthenticationDataSource.addOAuthAccount(
239221 OC_ACCOUNT_ID ,
@@ -251,17 +233,6 @@ class OCLocalAuthenticationDataSourceTest {
251233
252234 @Test
253235 fun addOAuthAccountAlreadyExistsUpdateSameUsername () {
254- every {
255- accountManager.getAccountsByType(OC_ACCOUNT .type)
256- } returns arrayOf(OC_ACCOUNT ) // The account is already there
257-
258- every {
259- accountManager.setUserData(any(), any(), any())
260- } returns Unit
261-
262- every {
263- accountManager.setAuthToken(any(), any(), any())
264- } returns Unit
265236
266237 mockSelectedAccountNameInPreferences()
267238
@@ -292,14 +263,6 @@ class OCLocalAuthenticationDataSourceTest {
292263 @Test
293264 fun addOAuthAccountAlreadyExistsUpdateDifferentUsername () {
294265
295- every {
296- accountManager.setUserData(any(), any(), any())
297- } returns Unit
298-
299- every {
300- accountManager.setAuthToken(any(), any(), any())
301- } returns Unit
302-
303266 mockSelectedAccountNameInPreferences()
304267
305268 try {
@@ -337,9 +300,6 @@ class OCLocalAuthenticationDataSourceTest {
337300
338301 @Test
339302 fun supportsOAuthOk () {
340- every {
341- accountManager.getAccountsByType(OC_ACCOUNT .type)
342- } returns arrayOf(OC_ACCOUNT )
343303
344304 every {
345305 accountManager.getUserData(OC_ACCOUNT , KEY_SUPPORTS_OAUTH2 )
@@ -355,18 +315,13 @@ class OCLocalAuthenticationDataSourceTest {
355315
356316 @Test(expected = AccountNotFoundException ::class )
357317 fun supportsOAuthAccountNotFound () {
358- every {
359- accountManager.getAccountsByType(OC_ACCOUNT .type)
360- } returns arrayOf() // That account does not exist
318+ getAccountsByType(OC_ACCOUNT .type, arrayOf())// That account does not exist
361319
362320 ocLocalAuthenticationDataSource.supportsOAuth2(OC_ACCOUNT .name)
363321 }
364322
365323 @Test
366324 fun getBaseUrlOk () {
367- every {
368- accountManager.getAccountsByType(OC_ACCOUNT .type)
369- } returns arrayOf(OC_ACCOUNT )
370325
371326 every {
372327 accountManager.getUserData(OC_ACCOUNT , KEY_OC_BASE_URL )
@@ -382,9 +337,7 @@ class OCLocalAuthenticationDataSourceTest {
382337
383338 @Test(expected = AccountNotFoundException ::class )
384339 fun getBaseUrlAccountNotFound () {
385- every {
386- accountManager.getAccountsByType(OC_ACCOUNT .type)
387- } returns arrayOf() // That account does not exist
340+ getAccountsByType(OC_ACCOUNT .type, arrayOf()) // That account does not exist
388341
389342 ocLocalAuthenticationDataSource.getBaseUrl(OC_ACCOUNT .name)
390343 }
@@ -402,9 +355,7 @@ class OCLocalAuthenticationDataSourceTest {
402355
403356 private fun mockRegularAccountCreationFlow () {
404357 // Step 1: Get accounts to know if the current account exists
405- every {
406- accountManager.getAccountsByType(" owncloud" )
407- } returns arrayOf() // There's no accounts yet
358+ getAccountsByType(OC_ACCOUNT .type, arrayOf()) // There's no accounts yet
408359
409360 // Step 2: Add new account
410361 every {
0 commit comments