mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-27 21:03:54 +01:00
Add tests for CommonsAppAdapter (#4818)
* Add tests for CommonsAppAdapter * Remove robolectric dependency
This commit is contained in:
parent
092079986a
commit
272f59b217
1 changed files with 110 additions and 0 deletions
|
|
@ -0,0 +1,110 @@
|
||||||
|
package fr.free.nrw.commons
|
||||||
|
|
||||||
|
import com.nhaarman.mockitokotlin2.verify
|
||||||
|
import com.nhaarman.mockitokotlin2.whenever
|
||||||
|
import fr.free.nrw.commons.auth.SessionManager
|
||||||
|
import fr.free.nrw.commons.kvstore.JsonKvStore
|
||||||
|
import org.junit.Assert
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import org.mockito.Mock
|
||||||
|
import org.mockito.MockitoAnnotations
|
||||||
|
import org.wikipedia.dataclient.SharedPreferenceCookieManager
|
||||||
|
import org.wikipedia.json.GsonMarshaller
|
||||||
|
import org.wikipedia.login.LoginResult
|
||||||
|
|
||||||
|
class CommonsAppAdapterUnitTest {
|
||||||
|
|
||||||
|
private lateinit var adapter: CommonsAppAdapter
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private lateinit var sessionManager: SessionManager
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private lateinit var preferences: JsonKvStore
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private lateinit var result: LoginResult
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private lateinit var cookies: SharedPreferenceCookieManager
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this)
|
||||||
|
adapter = CommonsAppAdapter(sessionManager, preferences)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun checkAdapterNotNull() {
|
||||||
|
Assert.assertNotNull(adapter)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testGetMediaWikiBaseUrl() {
|
||||||
|
Assert.assertEquals(adapter.mediaWikiBaseUrl, BuildConfig.COMMONS_URL)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testGetRestbaseUriFormat() {
|
||||||
|
Assert.assertEquals(adapter.restbaseUriFormat, BuildConfig.COMMONS_URL)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testGetDesiredLeadImageDp() {
|
||||||
|
Assert.assertEquals(adapter.desiredLeadImageDp, 640)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testIsLoggedIn() {
|
||||||
|
whenever(sessionManager.isUserLoggedIn).thenReturn(true)
|
||||||
|
Assert.assertEquals(adapter.isLoggedIn, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testGetUserName() {
|
||||||
|
whenever(sessionManager.userName).thenReturn("test")
|
||||||
|
Assert.assertEquals(adapter.userName, "test")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testGetPassword() {
|
||||||
|
whenever(sessionManager.password).thenReturn("test")
|
||||||
|
Assert.assertEquals(adapter.password, "test")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testUpdateAccount() {
|
||||||
|
adapter.updateAccount(result)
|
||||||
|
verify(sessionManager).updateAccount(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testSetCookies() {
|
||||||
|
adapter.cookies = cookies
|
||||||
|
verify(preferences).putString("cookie_store", GsonMarshaller.marshal(cookies))
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testLogErrorsInsteadOfCrashing() {
|
||||||
|
Assert.assertEquals(adapter.logErrorsInsteadOfCrashing(), false)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Throws(Exception::class)
|
||||||
|
fun testGetCookiesCaseNull() {
|
||||||
|
whenever(preferences.contains("cookie_store")).thenReturn(false)
|
||||||
|
Assert.assertEquals(adapter.cookies, null)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue