From 376740cd2cea25e9db1bfe61c70c645c9e4e1d2e Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Thu, 2 Apr 2020 09:52:56 -0700 Subject: [PATCH] For #9631: replace assertk assertions with junit. I created a series of editor macros to do this with minimal errors (and to do it quickly!). --- .../fenix/AppRequestInterceptorTest.kt | 9 +- .../CollectionCreationFragmentTest.kt | 17 +- .../java/org/mozilla/fenix/ext/StringTest.kt | 48 ++-- .../fenix/home/HomeFragmentStoreTest.kt | 20 +- ...necBookmarkShortcutsIntentProcessorTest.kt | 18 +- .../bookmarks/BookmarkFragmentStoreTest.kt | 39 ++-- .../library/bookmarks/DesktopFoldersTest.kt | 33 +-- .../library/history/HistoryControllerTest.kt | 34 +-- .../library/history/HistoryInteractorTest.kt | 5 +- .../settings/about/AboutPageAdapterTest.kt | 9 +- .../DefaultQuickSettingsControllerTest.kt | 101 ++++---- .../QuickSettingsFragmentStoreTest.kt | 216 +++++++----------- .../QuickSettingsInteractorTest.kt | 13 +- .../ext/PhoneFeatureExtKtTest.kt | 46 ++-- .../fenix/share/ShareControllerTest.kt | 59 +++-- .../AccountDevicesShareAdapterTest.kt | 9 +- .../share/listadapters/AppShareAdapterTest.kt | 11 +- 17 files changed, 270 insertions(+), 417 deletions(-) diff --git a/app/src/test/java/org/mozilla/fenix/AppRequestInterceptorTest.kt b/app/src/test/java/org/mozilla/fenix/AppRequestInterceptorTest.kt index ee409dcf4..f843555fa 100644 --- a/app/src/test/java/org/mozilla/fenix/AppRequestInterceptorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/AppRequestInterceptorTest.kt @@ -6,8 +6,6 @@ package org.mozilla.fenix import android.net.ConnectivityManager import androidx.core.content.getSystemService -import assertk.assertThat -import assertk.assertions.isEqualTo import io.mockk.every import io.mockk.mockk import io.mockk.mockkStatic @@ -15,6 +13,7 @@ import mozilla.components.browser.errorpages.ErrorPages import mozilla.components.browser.errorpages.ErrorType import mozilla.components.concept.engine.request.RequestInterceptor import mozilla.components.support.test.robolectric.testContext +import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -67,7 +66,7 @@ class AppRequestInterceptorTest { html = LOW_AND_MEDIUM_RISK_ERROR_PAGES ) - assertThat(actualPage).isEqualTo(expectedPage) + assertEquals(expectedPage, actualPage) } } @@ -84,7 +83,7 @@ class AppRequestInterceptorTest { html = LOW_AND_MEDIUM_RISK_ERROR_PAGES ) - assertThat(actualPage).isEqualTo(expectedPage) + assertEquals(expectedPage, actualPage) } } @@ -102,7 +101,7 @@ class AppRequestInterceptorTest { html = HIGH_RISK_ERROR_PAGES ) - assertThat(actualPage).isEqualTo(expectedPage) + assertEquals(expectedPage, actualPage) } } diff --git a/app/src/test/java/org/mozilla/fenix/collections/CollectionCreationFragmentTest.kt b/app/src/test/java/org/mozilla/fenix/collections/CollectionCreationFragmentTest.kt index 181fcfecb..a02f3d1fe 100644 --- a/app/src/test/java/org/mozilla/fenix/collections/CollectionCreationFragmentTest.kt +++ b/app/src/test/java/org/mozilla/fenix/collections/CollectionCreationFragmentTest.kt @@ -4,12 +4,6 @@ package org.mozilla.fenix.collections -import org.mozilla.fenix.helpers.FenixRobolectricTestRunner -import assertk.assertThat -import assertk.assertions.isNotNull -import assertk.assertions.isNull -import assertk.assertions.isTrue -import mozilla.components.support.test.robolectric.createAddedTestFragment import io.mockk.MockKAnnotations import io.mockk.every import io.mockk.impl.annotations.MockK @@ -23,10 +17,15 @@ import mozilla.components.browser.state.state.BrowserState import mozilla.components.browser.state.store.BrowserStore import mozilla.components.feature.tab.collections.Tab import mozilla.components.lib.publicsuffixlist.PublicSuffixList +import mozilla.components.support.test.robolectric.createAddedTestFragment import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertNull +import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test import org.junit.runner.RunWith +import org.mozilla.fenix.helpers.FenixRobolectricTestRunner private const val URL_MOZILLA = "www.mozilla.org" private const val SESSION_ID_MOZILLA = "0" @@ -72,10 +71,10 @@ class CollectionCreationFragmentTest { } } - assertThat(fragment.dialog).isNotNull() - assertThat(fragment.requireDialog().isShowing).isTrue() + assertNotNull(fragment.dialog) + assertTrue(fragment.requireDialog().isShowing) fragment.dismiss() - assertThat(fragment.dialog).isNull() + assertNull(fragment.dialog) } @Test diff --git a/app/src/test/java/org/mozilla/fenix/ext/StringTest.kt b/app/src/test/java/org/mozilla/fenix/ext/StringTest.kt index 17caacffa..8cc9ad55b 100644 --- a/app/src/test/java/org/mozilla/fenix/ext/StringTest.kt +++ b/app/src/test/java/org/mozilla/fenix/ext/StringTest.kt @@ -4,14 +4,10 @@ package org.mozilla.fenix.ext -import assertk.assertThat -import assertk.assertions.contains -import assertk.assertions.doesNotContain -import assertk.assertions.isEqualTo -import assertk.assertions.isFalse -import assertk.assertions.isTrue import mozilla.components.support.test.robolectric.testContext import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith @@ -50,13 +46,13 @@ class StringTest { val split = display.split(".") // If the list ends with 25.com... - assertThat(split.dropLast(1).last()).isEqualTo("25") + assertEquals("25", split.dropLast(1).last()) // ...and each value is 1 larger than the last... split.dropLast(1) .map { it.toInt() } .windowed(2, 1) .forEach { (prev, next) -> - assertThat(prev + 1).isEqualTo(next) + assertEquals(next, prev + 1) } // ...that means that all removed values came from the front of the list } @@ -67,7 +63,7 @@ class StringTest { // See https://chromium.googlesource.com/chromium/src/+/master/docs/security/url_display_guidelines/url_display_guidelines.md#eliding-urls val bigRegistrableDomain = "evil-but-also-shockingly-long-registrable-domain.com" - assertThat("https://login.your-bank.com.$bigRegistrableDomain/enter/your/password".shortened()).contains(bigRegistrableDomain) + assertTrue("https://login.your-bank.com.$bigRegistrableDomain/enter/your/password".shortened().contains(bigRegistrableDomain)) } @Test @@ -75,10 +71,10 @@ class StringTest { // See https://url.spec.whatwg.org/#url-rendering-simplification // See https://chromium.googlesource.com/chromium/src/+/master/docs/security/url_display_guidelines/url_display_guidelines.md#simplify - assertThat("https://examplecorp.com@attacker.example/".shortened()).doesNotContain("examplecorp") - assertThat("https://examplecorp.com@attacker.example/".shortened()).doesNotContain("com") - assertThat("https://user:password@example.com/".shortened()).doesNotContain("user") - assertThat("https://user:password@example.com/".shortened()).doesNotContain("password") + assertFalse("https://examplecorp.com@attacker.example/".shortened().contains("examplecorp")) + assertFalse("https://examplecorp.com@attacker.example/".shortened().contains("com")) + assertFalse("https://user:password@example.com/".shortened().contains("user")) + assertFalse("https://user:password@example.com/".shortened().contains("password")) } @Test @@ -207,39 +203,39 @@ class StringTest { // (https://searchfox.org/mozilla-mobile/source/firefox-echo-show/app/src/test/java/org/mozilla/focus/utils/TestFormattedDomain.java#228) @Test fun testIsIPv4RealAddress() { - assertThat("192.168.1.1".isIpv4()).isTrue() - assertThat("8.8.8.8".isIpv4()).isTrue() - assertThat("63.245.215.20".isIpv4()).isTrue() + assertTrue("192.168.1.1".isIpv4()) + assertTrue("8.8.8.8".isIpv4()) + assertTrue("63.245.215.20".isIpv4()) } @Test fun testIsIPv4WithProtocol() { - assertThat("http://8.8.8.8".isIpv4()).isFalse() - assertThat("https://8.8.8.8".isIpv4()).isFalse() + assertFalse("http://8.8.8.8".isIpv4()) + assertFalse("https://8.8.8.8".isIpv4()) } @Test fun testIsIPv4WithPort() { - assertThat("8.8.8.8:400".isIpv4()).isFalse() - assertThat("8.8.8.8:1337".isIpv4()).isFalse() + assertFalse("8.8.8.8:400".isIpv4()) + assertFalse("8.8.8.8:1337".isIpv4()) } @Test fun testIsIPv4WithPath() { - assertThat("8.8.8.8/index.html".isIpv4()).isFalse() - assertThat("8.8.8.8/".isIpv4()).isFalse() + assertFalse("8.8.8.8/index.html".isIpv4()) + assertFalse("8.8.8.8/".isIpv4()) } @Test fun testIsIPv4WithIPv6() { - assertThat("2001:db8::1 ".isIpv4()).isFalse() - assertThat("2001:db8:0:1:1:1:1:1".isIpv4()).isFalse() - assertThat("[2001:db8:a0b:12f0::1]".isIpv4()).isFalse() + assertFalse("2001:db8::1 ".isIpv4()) + assertFalse("2001:db8:0:1:1:1:1:1".isIpv4()) + assertFalse("[2001:db8:a0b:12f0::1]".isIpv4()) } // END test cases borrowed from FFTV private infix fun String.shortenedShouldBecome(expect: String) { - assertThat(this.shortened()).isEqualTo(expect) + assertEquals(expect, this.shortened()) } private fun String.shortened() = this.toShortUrl(publicSuffixList) diff --git a/app/src/test/java/org/mozilla/fenix/home/HomeFragmentStoreTest.kt b/app/src/test/java/org/mozilla/fenix/home/HomeFragmentStoreTest.kt index 68e706321..7e1cd71d9 100644 --- a/app/src/test/java/org/mozilla/fenix/home/HomeFragmentStoreTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/HomeFragmentStoreTest.kt @@ -5,8 +5,6 @@ package org.mozilla.fenix.home import android.content.Context -import assertk.assertThat -import assertk.assertions.isEqualTo import io.mockk.every import io.mockk.mockk import kotlinx.coroutines.runBlocking @@ -65,26 +63,26 @@ class HomeFragmentStoreTest { @Test fun `Test toggling the mode in HomeFragmentStore`() = runBlocking { // Verify that the default mode and tab states of the HomeFragment are correct. - assertThat(homeFragmentStore.state.mode).isEqualTo(Mode.Normal) + assertEquals(Mode.Normal, homeFragmentStore.state.mode) assertEquals(0, homeFragmentStore.state.tabs.size) // Change the HomeFragmentStore to Private mode. homeFragmentStore.dispatch(HomeFragmentAction.ModeChange(Mode.Private)).join() - assertThat(homeFragmentStore.state.mode).isEqualTo(Mode.Private) + assertEquals(Mode.Private, homeFragmentStore.state.mode) assertEquals(0, homeFragmentStore.state.tabs.size) // Change the HomeFragmentStore back to Normal mode. homeFragmentStore.dispatch(HomeFragmentAction.ModeChange(Mode.Normal)).join() - assertThat(homeFragmentStore.state.mode).isEqualTo(Mode.Normal) + assertEquals(Mode.Normal, homeFragmentStore.state.mode) assertEquals(0, homeFragmentStore.state.tabs.size) } @Test fun `Test toggling the mode with tabs in HomeFragmentStore`() = runBlocking { // Verify that the default mode and tab states of the HomeFragment are correct. - assertThat(homeFragmentStore.state.mode).isEqualTo(Mode.Normal) + assertEquals(Mode.Normal, homeFragmentStore.state.mode) assertEquals(0, homeFragmentStore.state.tabs.size) // Add 2 Tabs to the HomeFragmentStore. @@ -96,7 +94,7 @@ class HomeFragmentStoreTest { // Change the HomeFragmentStore to Private mode. homeFragmentStore.dispatch(HomeFragmentAction.ModeChange(Mode.Private)).join() - assertThat(homeFragmentStore.state.mode).isEqualTo(Mode.Private) + assertEquals(Mode.Private, homeFragmentStore.state.mode) assertEquals(0, homeFragmentStore.state.tabs.size) } @@ -108,7 +106,7 @@ class HomeFragmentStoreTest { val tabCollections: List = listOf(mockk(), mockk()) homeFragmentStore.dispatch(HomeFragmentAction.CollectionsChange(tabCollections)).join() - assertThat(homeFragmentStore.state.collections).isEqualTo(tabCollections) + assertEquals(tabCollections, homeFragmentStore.state.collections) } @Test @@ -119,7 +117,7 @@ class HomeFragmentStoreTest { val topSites: List = listOf(mockk(), mockk()) homeFragmentStore.dispatch(HomeFragmentAction.TopSitesChange(topSites)).join() - assertThat(homeFragmentStore.state.topSites).isEqualTo(topSites) + assertEquals(topSites, homeFragmentStore.state.topSites) } @Test @@ -154,7 +152,7 @@ class HomeFragmentStoreTest { assertEquals(0, homeFragmentStore.state.collections.size) assertEquals(0, homeFragmentStore.state.tabs.size) assertEquals(0, homeFragmentStore.state.topSites.size) - assertThat(homeFragmentStore.state.mode).isEqualTo(Mode.Normal) + assertEquals(Mode.Normal, homeFragmentStore.state.mode) val collections: List = listOf(mockk()) val tabs: List = listOf(mockk(), mockk()) @@ -170,7 +168,7 @@ class HomeFragmentStoreTest { ).join() assertEquals(1, homeFragmentStore.state.collections.size) - assertThat(homeFragmentStore.state.mode).isEqualTo(Mode.Private) + assertEquals(Mode.Private, homeFragmentStore.state.mode) assertEquals(2, homeFragmentStore.state.tabs.size) assertEquals(2, homeFragmentStore.state.topSites.size) } diff --git a/app/src/test/java/org/mozilla/fenix/home/intent/FennecBookmarkShortcutsIntentProcessorTest.kt b/app/src/test/java/org/mozilla/fenix/home/intent/FennecBookmarkShortcutsIntentProcessorTest.kt index f712517b7..34db89fb5 100644 --- a/app/src/test/java/org/mozilla/fenix/home/intent/FennecBookmarkShortcutsIntentProcessorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/home/intent/FennecBookmarkShortcutsIntentProcessorTest.kt @@ -6,11 +6,6 @@ package org.mozilla.fenix.home.intent import android.content.Intent import android.net.Uri -import assertk.assertAll -import assertk.assertThat -import assertk.assertions.isEqualTo -import assertk.assertions.isFalse -import assertk.assertions.isTrue import io.mockk.Called import io.mockk.every import io.mockk.mockk @@ -23,6 +18,9 @@ import mozilla.components.browser.session.SessionManager import mozilla.components.concept.engine.EngineSession import mozilla.components.feature.intent.ext.getSessionId import mozilla.components.feature.session.SessionUseCases +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue import org.junit.Test import org.junit.runner.RunWith import org.mozilla.fenix.home.intent.FennecBookmarkShortcutsIntentProcessor.Companion.ACTION_FENNEC_HOMESCREEN_SHORTCUT @@ -42,7 +40,7 @@ class FennecBookmarkShortcutsIntentProcessorTest { val wasEmptyIntentProcessed = processor.process(Intent()) - assertThat(wasEmptyIntentProcessed).isFalse() + assertFalse(wasEmptyIntentProcessed) verify { sessionManager wasNot Called loadUrlUseCase wasNot Called @@ -62,11 +60,9 @@ class FennecBookmarkShortcutsIntentProcessorTest { val wasIntentProcessed = processor.process(fennecShortcutsIntent) - assertAll { - assertThat(wasIntentProcessed).isTrue() - assertThat(fennecShortcutsIntent.action).isEqualTo(Intent.ACTION_VIEW) - assertThat(fennecShortcutsIntent.getSessionId()).isEqualTo(expectedSession.id) - } + assertTrue(wasIntentProcessed) + assertEquals(Intent.ACTION_VIEW, fennecShortcutsIntent.action) + assertEquals(expectedSession.id, fennecShortcutsIntent.getSessionId()) verifyAll { sessionManager.add(expectedSession, true) loadUrlUseCase(testUrl, expectedSession, EngineSession.LoadUrlFlags.external()) diff --git a/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkFragmentStoreTest.kt b/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkFragmentStoreTest.kt index e256a1840..03d49f141 100644 --- a/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkFragmentStoreTest.kt +++ b/app/src/test/java/org/mozilla/fenix/library/bookmarks/BookmarkFragmentStoreTest.kt @@ -4,11 +4,10 @@ package org.mozilla.fenix.library.bookmarks -import assertk.assertThat -import assertk.assertions.isEqualTo import kotlinx.coroutines.runBlocking import mozilla.components.concept.storage.BookmarkNode import mozilla.components.concept.storage.BookmarkNodeType +import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertSame import org.junit.Assert.assertTrue @@ -21,12 +20,12 @@ class BookmarkFragmentStoreTest { val initialState = BookmarkFragmentState(null) val store = BookmarkFragmentStore(initialState) - assertThat(BookmarkFragmentState(null, BookmarkFragmentState.Mode.Normal())).isEqualTo(store.state) + assertEquals(store.state, BookmarkFragmentState(null, BookmarkFragmentState.Mode.Normal())) store.dispatch(BookmarkFragmentAction.Change(tree)).join() - assertThat(tree).isEqualTo(store.state.tree) - assertThat(initialState.mode).isEqualTo(store.state.mode) + assertEquals(store.state.tree, tree) + assertEquals(store.state.mode, initialState.mode) } @Test @@ -34,12 +33,12 @@ class BookmarkFragmentStoreTest { val initialState = BookmarkFragmentState(tree) val store = BookmarkFragmentStore(initialState) - assertThat(BookmarkFragmentState(tree, BookmarkFragmentState.Mode.Normal())).isEqualTo(store.state) + assertEquals(store.state, BookmarkFragmentState(tree, BookmarkFragmentState.Mode.Normal())) store.dispatch(BookmarkFragmentAction.Change(newTree)).join() - assertThat(newTree).isEqualTo(store.state.tree) - assertThat(initialState.mode).isEqualTo(store.state.mode) + assertEquals(store.state.tree, newTree) + assertEquals(store.state.mode, initialState.mode) } @Test @@ -47,12 +46,12 @@ class BookmarkFragmentStoreTest { val initialState = BookmarkFragmentState(tree) val store = BookmarkFragmentStore(initialState) - assertThat(BookmarkFragmentState(tree, BookmarkFragmentState.Mode.Normal())).isEqualTo(store.state) + assertEquals(store.state, BookmarkFragmentState(tree, BookmarkFragmentState.Mode.Normal())) store.dispatch(BookmarkFragmentAction.Change(tree)).join() - assertThat(initialState.tree).isEqualTo(store.state.tree) - assertThat(initialState.mode).isEqualTo(store.state.mode) + assertEquals(store.state.tree, initialState.tree) + assertEquals(store.state.mode, initialState.mode) } @Test @@ -62,8 +61,8 @@ class BookmarkFragmentStoreTest { store.dispatch(BookmarkFragmentAction.Change(newTree)).join() - assertThat(newTree).isEqualTo(store.state.tree) - assertThat(BookmarkFragmentState.Mode.Selecting(setOf(subfolder))).isEqualTo(store.state.mode) + assertEquals(store.state.tree, newTree) + assertEquals(store.state.mode, BookmarkFragmentState.Mode.Selecting(setOf(subfolder))) } @Test @@ -73,11 +72,11 @@ class BookmarkFragmentStoreTest { store.dispatch(BookmarkFragmentAction.Select(childItem)).join() - assertThat(BookmarkFragmentState(tree, BookmarkFragmentState.Mode.Selecting(setOf(childItem)))).isEqualTo(store.state) + assertEquals(store.state, BookmarkFragmentState(tree, BookmarkFragmentState.Mode.Selecting(setOf(childItem)))) store.dispatch(BookmarkFragmentAction.Deselect(childItem)).join() - assertThat(BookmarkFragmentState(tree, BookmarkFragmentState.Mode.Normal())).isEqualTo(store.state) + assertEquals(store.state, BookmarkFragmentState(tree, BookmarkFragmentState.Mode.Normal())) } @Test @@ -117,7 +116,7 @@ class BookmarkFragmentStoreTest { store.dispatch(BookmarkFragmentAction.DeselectAll).join() - assertThat(initialState.copy(mode = BookmarkFragmentState.Mode.Normal())).isEqualTo(store.state) + assertEquals(store.state, initialState.copy(mode = BookmarkFragmentState.Mode.Normal())) } @Test @@ -138,8 +137,8 @@ class BookmarkFragmentStoreTest { store.dispatch(BookmarkFragmentAction.Change(newTree)).join() store.state.run { - assertThat(newTree).isEqualTo(tree) - assertThat(BookmarkFragmentState.Mode.Normal()).isEqualTo(mode) + assertEquals(tree, newTree) + assertEquals(mode, BookmarkFragmentState.Mode.Normal()) } } @@ -174,8 +173,8 @@ class BookmarkFragmentStoreTest { store.dispatch(BookmarkFragmentAction.Change(rootFolder)).join() - assertThat(rootFolder).isEqualTo(store.state.tree) - assertThat(BookmarkFragmentState.Mode.Normal(false)).isEqualTo(store.state.mode) + assertEquals(store.state.tree, rootFolder) + assertEquals(store.state.mode, BookmarkFragmentState.Mode.Normal(false)) } private val item = BookmarkNode(BookmarkNodeType.ITEM, "456", "123", 0, "Mozilla", "http://mozilla.org", null) diff --git a/app/src/test/java/org/mozilla/fenix/library/bookmarks/DesktopFoldersTest.kt b/app/src/test/java/org/mozilla/fenix/library/bookmarks/DesktopFoldersTest.kt index ce5111dd1..f680fef9d 100644 --- a/app/src/test/java/org/mozilla/fenix/library/bookmarks/DesktopFoldersTest.kt +++ b/app/src/test/java/org/mozilla/fenix/library/bookmarks/DesktopFoldersTest.kt @@ -5,8 +5,6 @@ package org.mozilla.fenix.library.bookmarks import android.content.Context -import assertk.assertThat -import assertk.assertions.isEqualTo import io.mockk.every import io.mockk.mockk import io.mockk.spyk @@ -16,6 +14,7 @@ import mozilla.components.browser.storage.sync.PlacesBookmarksStorage import mozilla.components.concept.storage.BookmarkNode import mozilla.components.concept.storage.BookmarkNodeType import mozilla.components.support.test.robolectric.testContext +import org.junit.Assert.assertEquals import org.junit.Assert.assertSame import org.junit.Before import org.junit.Test @@ -52,32 +51,22 @@ class DesktopFoldersTest { fun `withRootTitle and do showMobileRoot`() { val desktopFolders = DesktopFolders(context, showMobileRoot = true) - assertThat(desktopFolders.withRootTitle(mockNodeWithTitle("root")).title) - .isEqualTo(testContext.getString(R.string.library_bookmarks)) - assertThat(desktopFolders.withRootTitle(mockNodeWithTitle("mobile")).title) - .isEqualTo(testContext.getString(R.string.library_bookmarks)) - assertThat(desktopFolders.withRootTitle(mockNodeWithTitle("menu")).title) - .isEqualTo(testContext.getString(R.string.library_desktop_bookmarks_menu)) - assertThat(desktopFolders.withRootTitle(mockNodeWithTitle("toolbar")).title) - .isEqualTo(testContext.getString(R.string.library_desktop_bookmarks_toolbar)) - assertThat(desktopFolders.withRootTitle(mockNodeWithTitle("unfiled")).title) - .isEqualTo(testContext.getString(R.string.library_desktop_bookmarks_unfiled)) + assertEquals(testContext.getString(R.string.library_bookmarks), desktopFolders.withRootTitle(mockNodeWithTitle("root")).title) + assertEquals(testContext.getString(R.string.library_bookmarks), desktopFolders.withRootTitle(mockNodeWithTitle("mobile")).title) + assertEquals(testContext.getString(R.string.library_desktop_bookmarks_menu), desktopFolders.withRootTitle(mockNodeWithTitle("menu")).title) + assertEquals(testContext.getString(R.string.library_desktop_bookmarks_toolbar), desktopFolders.withRootTitle(mockNodeWithTitle("toolbar")).title) + assertEquals(testContext.getString(R.string.library_desktop_bookmarks_unfiled), desktopFolders.withRootTitle(mockNodeWithTitle("unfiled")).title) } @Test fun `withRootTitle and do not showMobileRoot`() { val desktopFolders = DesktopFolders(context, showMobileRoot = false) - assertThat(desktopFolders.withRootTitle(mockNodeWithTitle("root")).title) - .isEqualTo(testContext.getString(R.string.library_desktop_bookmarks_root)) - assertThat(desktopFolders.withRootTitle(mockNodeWithTitle("mobile"))) - .isEqualTo(mockNodeWithTitle("mobile")) - assertThat(desktopFolders.withRootTitle(mockNodeWithTitle("menu")).title) - .isEqualTo(testContext.getString(R.string.library_desktop_bookmarks_menu)) - assertThat(desktopFolders.withRootTitle(mockNodeWithTitle("toolbar")).title) - .isEqualTo(testContext.getString(R.string.library_desktop_bookmarks_toolbar)) - assertThat(desktopFolders.withRootTitle(mockNodeWithTitle("unfiled")).title) - .isEqualTo(testContext.getString(R.string.library_desktop_bookmarks_unfiled)) + assertEquals(testContext.getString(R.string.library_desktop_bookmarks_root), desktopFolders.withRootTitle(mockNodeWithTitle("root")).title) + assertEquals(mockNodeWithTitle("mobile"), desktopFolders.withRootTitle(mockNodeWithTitle("mobile"))) + assertEquals(testContext.getString(R.string.library_desktop_bookmarks_menu), desktopFolders.withRootTitle(mockNodeWithTitle("menu")).title) + assertEquals(testContext.getString(R.string.library_desktop_bookmarks_toolbar), desktopFolders.withRootTitle(mockNodeWithTitle("toolbar")).title) + assertEquals(testContext.getString(R.string.library_desktop_bookmarks_unfiled), desktopFolders.withRootTitle(mockNodeWithTitle("unfiled")).title) } @Test diff --git a/app/src/test/java/org/mozilla/fenix/library/history/HistoryControllerTest.kt b/app/src/test/java/org/mozilla/fenix/library/history/HistoryControllerTest.kt index e025cb7e5..62e5ae8cc 100644 --- a/app/src/test/java/org/mozilla/fenix/library/history/HistoryControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/library/history/HistoryControllerTest.kt @@ -9,18 +9,14 @@ import android.content.ClipboardManager import android.content.res.Resources import androidx.navigation.NavController import androidx.navigation.NavDirections -import assertk.assertAll -import assertk.assertThat -import assertk.assertions.hasSize -import assertk.assertions.isEqualTo import io.mockk.every import io.mockk.mockk import io.mockk.slot import io.mockk.verify import mozilla.components.concept.engine.prompt.ShareData import org.junit.Assert.assertEquals -import org.junit.Assert.assertTrue import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -164,11 +160,9 @@ class HistoryControllerTest { clipboardManager.primaryClip = capture(clipdata) snackbar.show() } - assertAll { - assertEquals(clipdata.captured.itemCount, 1) - assertThat(clipdata.captured.description.label).isEqualTo(historyItem.url) - assertThat(clipdata.captured.getItemAt(0).text).isEqualTo(historyItem.url) - } + assertEquals(1, clipdata.captured.itemCount) + assertEquals(historyItem.url, clipdata.captured.description.label) + assertEquals(historyItem.url, clipdata.captured.getItemAt(0).text) } @Test @@ -186,17 +180,13 @@ class HistoryControllerTest { capture(directions) ) } - assertAll { - // The below class is private, can't easily assert using `instanceOf` - assertEquals( - directions.captured::class.simpleName, - "ActionHistoryFragmentToShareFragment" - ) - assertThat(directions.captured.arguments["data"] as Array).hasSize(1) - assertThat(((directions.captured.arguments["data"] as Array)[0]).title) - .isEqualTo(historyItem.title) - assertThat(((directions.captured.arguments["data"] as Array)[0]).url) - .isEqualTo(historyItem.url) - } + + assertEquals( + directions.captured::class.simpleName, + "ActionHistoryFragmentToShareFragment" + ) + assertEquals(1, (directions.captured.arguments["data"] as Array).size) + assertEquals(historyItem.title, (directions.captured.arguments["data"] as Array)[0].title) + assertEquals(historyItem.url, (directions.captured.arguments["data"] as Array)[0].url) } } diff --git a/app/src/test/java/org/mozilla/fenix/library/history/HistoryInteractorTest.kt b/app/src/test/java/org/mozilla/fenix/library/history/HistoryInteractorTest.kt index b413c957c..b5ee0800d 100644 --- a/app/src/test/java/org/mozilla/fenix/library/history/HistoryInteractorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/library/history/HistoryInteractorTest.kt @@ -4,11 +4,10 @@ package org.mozilla.fenix.library.history -import assertk.assertThat -import assertk.assertions.isTrue import io.mockk.every import io.mockk.mockk import io.mockk.verifyAll +import org.junit.Assert.assertTrue import org.junit.Test import org.mozilla.fenix.browser.browsingmode.BrowsingMode @@ -55,7 +54,7 @@ class HistoryInteractorTest { verifyAll { controller.handleBackPressed() } - assertThat(backpressHandled).isTrue() + assertTrue(backpressHandled) } @Test diff --git a/app/src/test/java/org/mozilla/fenix/settings/about/AboutPageAdapterTest.kt b/app/src/test/java/org/mozilla/fenix/settings/about/AboutPageAdapterTest.kt index 1d0b62af0..2ae9fd3c9 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/about/AboutPageAdapterTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/about/AboutPageAdapterTest.kt @@ -6,8 +6,6 @@ package org.mozilla.fenix.settings.about import android.view.ViewGroup import android.widget.TextView -import assertk.assertThat -import assertk.assertions.isEqualTo import io.mockk.Runs import io.mockk.every import io.mockk.just @@ -16,6 +14,7 @@ import io.mockk.spyk import io.mockk.verify import kotlinx.android.synthetic.main.about_list_item.view.* import mozilla.components.support.test.robolectric.testContext +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith import org.mozilla.fenix.settings.about.viewholders.AboutItemViewHolder @@ -39,7 +38,7 @@ class AboutPageAdapterTest { fun `getItemCount on a default instantiated Adapter should return 0`() { val adapter = AboutPageAdapter(listener) - assertThat(adapter.itemCount).isEqualTo(0) + assertEquals(0, adapter.itemCount) } @Test @@ -48,7 +47,7 @@ class AboutPageAdapterTest { adapter.submitList(aboutList) - assertThat(adapter.itemCount).isEqualTo(2) + assertEquals(2, adapter.itemCount) } @Test @@ -59,7 +58,7 @@ class AboutPageAdapterTest { val viewHolder = adapter.onCreateViewHolder(parentView, AboutItemViewHolder.LAYOUT_ID) - assertThat(viewHolder::class).isEqualTo(AboutItemViewHolder::class) + assertEquals(AboutItemViewHolder::class, viewHolder::class) } @Test diff --git a/app/src/test/java/org/mozilla/fenix/settings/quicksettings/DefaultQuickSettingsControllerTest.kt b/app/src/test/java/org/mozilla/fenix/settings/quicksettings/DefaultQuickSettingsControllerTest.kt index 161021750..8dd147dbd 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/quicksettings/DefaultQuickSettingsControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/quicksettings/DefaultQuickSettingsControllerTest.kt @@ -6,12 +6,6 @@ package org.mozilla.fenix.settings.quicksettings import androidx.navigation.NavController import androidx.navigation.NavDirections -import assertk.assertAll -import assertk.assertThat -import assertk.assertions.isEqualTo -import assertk.assertions.isInstanceOf -import assertk.assertions.isSameAs -import assertk.assertions.isTrue import io.mockk.Runs import io.mockk.every import io.mockk.just @@ -29,6 +23,10 @@ import mozilla.components.feature.sitepermissions.SitePermissions import mozilla.components.feature.sitepermissions.SitePermissions.Status.NO_DECISION import mozilla.components.feature.tabs.TabsUseCases import mozilla.components.support.test.robolectric.testContext +import org.junit.Assert.assertArrayEquals +import org.junit.Assert.assertEquals +import org.junit.Assert.assertSame +import org.junit.Assert.assertTrue import org.junit.Ignore import org.junit.Test import org.junit.runner.RunWith @@ -94,10 +92,9 @@ class DefaultQuickSettingsControllerTest { verify { controller.handleAndroidPermissionRequest(capture(androidPermissions)) } - assertAll { - assertThat(androidPermissions.isCaptured).isTrue() - assertThat(androidPermissions.captured).isEqualTo(cameraFeature.androidPermissionsList) - } + + assertTrue(androidPermissions.isCaptured) + assertArrayEquals(cameraFeature.androidPermissionsList, androidPermissions.captured) } @Test @@ -116,7 +113,7 @@ class DefaultQuickSettingsControllerTest { controller.handlePermissionToggled(websitePermission) // We want to verify that the Status is toggled and this event is passed to Controller also. - assertThat(sitePermissions.camera).isSameAs(NO_DECISION) + assertSame(NO_DECISION, sitePermissions.camera) verifyOrder { val permission = sitePermissions.toggle(capture(toggledFeature)) controller.handlePermissionsChange(permission) @@ -125,15 +122,14 @@ class DefaultQuickSettingsControllerTest { verify { store.dispatch(capture(action)) } - assertAll { - assertThat(toggledFeature.isCaptured).isTrue() - assertThat(toggledFeature.captured).isSameAs(PhoneFeature.CAMERA) - assertThat(action.isCaptured).isTrue() - assertThat(action.captured).isInstanceOf(WebsitePermissionAction.TogglePermission::class) - assertThat((action.captured as WebsitePermissionAction.TogglePermission).websitePermission) - .isInstanceOf(websitePermission::class) - } + assertTrue(toggledFeature.isCaptured) + assertSame(PhoneFeature.CAMERA, toggledFeature.captured) + + assertTrue(action.isCaptured) + assertEquals(WebsitePermissionAction.TogglePermission::class, action.captured::class) + assertEquals(websitePermission::class, + (action.captured as WebsitePermissionAction.TogglePermission).websitePermission::class) } @Test @@ -183,19 +179,12 @@ class DefaultQuickSettingsControllerTest { verify { store.dispatch(capture(action)) } - assertAll { - assertThat(action.isCaptured).isTrue() - assertThat(action.captured).isInstanceOf(WebsitePermissionAction.TogglePermission::class) - assertThat((action.captured as WebsitePermissionAction.TogglePermission).websitePermission).isEqualTo( - permission - ) - assertThat((action.captured as WebsitePermissionAction.TogglePermission).updatedStatus).isEqualTo( - permissionStatus - ) - assertThat((action.captured as WebsitePermissionAction.TogglePermission).updatedEnabledStatus).isEqualTo( - permissionEnabled - ) - } + + assertTrue(action.isCaptured) + assertEquals(WebsitePermissionAction.TogglePermission::class, action.captured::class) + assertEquals(permission, (action.captured as WebsitePermissionAction.TogglePermission).websitePermission) + assertEquals(permissionStatus, (action.captured as WebsitePermissionAction.TogglePermission).updatedStatus) + assertEquals(permissionEnabled, (action.captured as WebsitePermissionAction.TogglePermission).updatedEnabledStatus) } @Test @@ -207,10 +196,9 @@ class DefaultQuickSettingsControllerTest { controller.handleAndroidPermissionRequest(testPermissions) verify { requestPermissions(capture(requiredPermissions)) } - assertAll { - assertThat(requiredPermissions.isCaptured).isTrue() - assertThat(requiredPermissions.captured).isEqualTo(testPermissions) - } + + assertTrue(requiredPermissions.isCaptured) + assertArrayEquals(testPermissions, requiredPermissions.captured) } @Test @@ -228,12 +216,11 @@ class DefaultQuickSettingsControllerTest { permissionStorage.updateSitePermissions(capture(permissions)) reload(capture(session)) } - assertAll { - assertThat(permissions.isCaptured).isTrue() - assertThat(permissions.captured).isEqualTo(testPermissions) - assertThat(session.isCaptured).isTrue() - assertThat(session.captured).isEqualTo(browserSession) - } + + assertTrue(permissions.isCaptured) + assertEquals(testPermissions, permissions.captured) + assertTrue(session.isCaptured) + assertEquals(browserSession, session.captured) } @Test @@ -244,32 +231,22 @@ class DefaultQuickSettingsControllerTest { val locationPermission = mockk() with(controller) { - assertAll { - assertThat(cameraPermission.getBackingFeature()).isSameAs(PhoneFeature.CAMERA) - assertThat(microphonePermission.getBackingFeature()).isSameAs(PhoneFeature.MICROPHONE) - assertThat(notificationPermission.getBackingFeature()).isSameAs(PhoneFeature.NOTIFICATION) - assertThat(locationPermission.getBackingFeature()).isSameAs(PhoneFeature.LOCATION) - } + assertSame(PhoneFeature.CAMERA, cameraPermission.getBackingFeature()) + assertSame(PhoneFeature.MICROPHONE, microphonePermission.getBackingFeature()) + assertSame(PhoneFeature.NOTIFICATION, notificationPermission.getBackingFeature()) + assertSame(PhoneFeature.LOCATION, locationPermission.getBackingFeature()) } } @Test fun `PhoneFeature#getCorrespondingPermission should return the WebsitePermission which it maps to`() { with(controller) { - assertAll { - assertThat(PhoneFeature.CAMERA.getCorrespondingPermission()) - .isInstanceOf(WebsitePermission.Camera::class) - assertThat(PhoneFeature.MICROPHONE.getCorrespondingPermission()) - .isInstanceOf(WebsitePermission.Microphone::class) - assertThat(PhoneFeature.NOTIFICATION.getCorrespondingPermission()) - .isInstanceOf(WebsitePermission.Notification::class) - assertThat(PhoneFeature.LOCATION.getCorrespondingPermission()) - .isInstanceOf(WebsitePermission.Location::class) - assertThat(PhoneFeature.AUTOPLAY_AUDIBLE.getCorrespondingPermission()) - .isInstanceOf(WebsitePermission.AutoplayAudible::class) - assertThat(PhoneFeature.AUTOPLAY_INAUDIBLE.getCorrespondingPermission()) - .isInstanceOf(WebsitePermission.AutoplayInaudible::class) - } + assertEquals(WebsitePermission.Camera::class, PhoneFeature.CAMERA.getCorrespondingPermission()::class) + assertEquals(WebsitePermission.Microphone::class, PhoneFeature.MICROPHONE.getCorrespondingPermission()::class) + assertEquals(WebsitePermission.Notification::class, PhoneFeature.NOTIFICATION.getCorrespondingPermission()::class) + assertEquals(WebsitePermission.Location::class, PhoneFeature.LOCATION.getCorrespondingPermission()::class) + assertEquals(WebsitePermission.AutoplayAudible::class, PhoneFeature.AUTOPLAY_AUDIBLE.getCorrespondingPermission()::class) + assertEquals(WebsitePermission.AutoplayInaudible::class, PhoneFeature.AUTOPLAY_INAUDIBLE.getCorrespondingPermission()::class) } } } diff --git a/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentStoreTest.kt b/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentStoreTest.kt index a51af4793..216626c5b 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentStoreTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsFragmentStoreTest.kt @@ -5,15 +5,6 @@ package org.mozilla.fenix.settings.quicksettings import android.content.pm.PackageManager -import assertk.assertAll -import assertk.assertThat -import assertk.assertions.isEqualTo -import assertk.assertions.isFalse -import assertk.assertions.isInstanceOf -import assertk.assertions.isNotNull -import assertk.assertions.isNotSameAs -import assertk.assertions.isSameAs -import assertk.assertions.isTrue import io.mockk.every import io.mockk.mockk import io.mockk.spyk @@ -22,10 +13,16 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.runBlocking import mozilla.components.feature.sitepermissions.SitePermissions import mozilla.components.support.test.robolectric.testContext +import org.junit.Assert.assertEquals +import org.junit.Assert.assertFalse +import org.junit.Assert.assertNotNull +import org.junit.Assert.assertNotSame +import org.junit.Assert.assertSame +import org.junit.Assert.assertTrue import org.junit.Test import org.junit.runner.RunWith import org.mozilla.fenix.R -import org.mozilla.fenix.ext.settings +import org.mozilla.fenix.helpers.FenixRobolectricTestRunner import org.mozilla.fenix.settings.PhoneFeature import org.mozilla.fenix.settings.quicksettings.QuickSettingsFragmentStore.Companion.getInsecureWebsiteUiValues import org.mozilla.fenix.settings.quicksettings.QuickSettingsFragmentStore.Companion.getPermissionStatus @@ -35,7 +32,6 @@ import org.mozilla.fenix.settings.quicksettings.ext.shouldBeEnabled import org.mozilla.fenix.settings.quicksettings.ext.shouldBeVisible import org.mozilla.fenix.settings.sitepermissions.AUTOPLAY_BLOCK_ALL import org.mozilla.fenix.utils.Settings -import org.mozilla.fenix.helpers.FenixRobolectricTestRunner @RunWith(FenixRobolectricTestRunner::class) class QuickSettingsFragmentStoreTest { @@ -58,12 +54,10 @@ class QuickSettingsFragmentStoreTest { context, "url", "Hello", "issuer", true, permissions, settings ) - assertAll { - assertThat(store).isNotNull() - assertThat(store.state).isNotNull() - assertThat(store.state.webInfoState).isNotNull() - assertThat(store.state.websitePermissionsState).isNotNull() - } + assertNotNull(store) + assertNotNull(store.state) + assertNotNull(store.state.webInfoState) + assertNotNull(store.state.websitePermissionsState) } @Test @@ -75,14 +69,12 @@ class QuickSettingsFragmentStoreTest { val state = QuickSettingsFragmentStore.createWebsiteInfoState(websiteUrl, websiteTitle, securedStatus, certificateIssuer) - assertAll { - assertThat(state).isNotNull() - assertThat(state.websiteUrl).isSameAs(websiteUrl) - assertThat(state.websiteTitle).isSameAs(websiteTitle) - assertThat(state.securityInfoRes).isEqualTo(secureStringRes) - assertThat(state.iconRes).isEqualTo(secureDrawableRes) - assertThat(state.iconTintRes).isEqualTo(secureColorRes) - } + assertNotNull(state) + assertSame(websiteUrl, state.websiteUrl) + assertSame(websiteTitle, state.websiteTitle) + assertEquals(secureStringRes, state.securityInfoRes) + assertEquals(secureDrawableRes, state.iconRes) + assertEquals(secureColorRes, state.iconTintRes) } @Test @@ -94,14 +86,12 @@ class QuickSettingsFragmentStoreTest { val state = QuickSettingsFragmentStore.createWebsiteInfoState(websiteUrl, websiteTitle, securedStatus, certificateIssuer) - assertAll { - assertThat(state).isNotNull() - assertThat(state.websiteUrl).isSameAs(websiteUrl) - assertThat(state.websiteTitle).isSameAs(websiteTitle) - assertThat(state.securityInfoRes).isEqualTo(insecureStringRes) - assertThat(state.iconRes).isEqualTo(insecureDrawableRes) - assertThat(state.iconTintRes).isEqualTo(insecureColorRes) - } + assertNotNull(state) + assertSame(websiteUrl, state.websiteUrl) + assertSame(websiteTitle, state.websiteTitle) + assertEquals(insecureStringRes, state.securityInfoRes) + assertEquals(insecureDrawableRes, state.iconRes) + assertEquals(insecureColorRes, state.iconTintRes) } @Test @@ -127,15 +117,13 @@ class QuickSettingsFragmentStoreTest { // Just need to know that the WebsitePermissionsState properties are initialized. // Making sure they are correctly initialized is tested in the `initWebsitePermission` test. - assertAll { - assertThat(state).isNotNull() - assertThat(state.camera).isNotNull() - assertThat(state.microphone).isNotNull() - assertThat(state.notification).isNotNull() - assertThat(state.location).isNotNull() - assertThat(state.autoplayAudible).isNotNull() - assertThat(state.autoplayInaudible).isNotNull() - } + assertNotNull(state) + assertNotNull(state.camera) + assertNotNull(state.microphone) + assertNotNull(state.notification) + assertNotNull(state.location) + assertNotNull(state.autoplayAudible) + assertNotNull(state.autoplayInaudible) } @Test @@ -153,14 +141,12 @@ class QuickSettingsFragmentStoreTest { val websitePermission = cameraFeature.toWebsitePermission(context, permissions, appSettings) - assertAll { - assertThat(websitePermission).isNotNull() - assertThat(websitePermission).isInstanceOf(WebsitePermission.Camera::class) - assertThat(websitePermission.status).isEqualTo(allowedStatus) - assertThat(websitePermission.isVisible).isTrue() - assertThat(websitePermission.isEnabled).isTrue() - assertThat(websitePermission.isBlockedByAndroid).isFalse() - } + assertNotNull(websitePermission) + assertEquals(WebsitePermission.Camera::class, websitePermission::class) + assertEquals(allowedStatus, websitePermission.status) + assertTrue(websitePermission.isVisible) + assertTrue(websitePermission.isEnabled) + assertFalse(websitePermission.isBlockedByAndroid) } @Test @@ -177,12 +163,11 @@ class QuickSettingsFragmentStoreTest { phoneFeature.shouldBeEnabled(context, permissions, appSettings) phoneFeature.isAndroidPermissionGranted(context) } - assertAll { - // Check that we only have a non-null permission status. - // Having each property calculated in a separate delegate means their correctness is - // to be tested in that delegated method. - assertThat(permissionsStatus).isNotNull() - } + + // Check that we only have a non-null permission status. + // Having each property calculated in a separate delegate means their correctness is + // to be tested in that delegated method. + assertNotNull(permissionsStatus) } @Test @@ -247,105 +232,58 @@ class QuickSettingsFragmentStoreTest { ) ).join() - assertAll { - assertThat(store.state).isNotNull() - assertThat(store.state).isNotSameAs(initialState) - assertThat(store.state.websitePermissionsState).isNotSameAs( - initialWebsitePermissionsState - ) - assertThat(store.state.webInfoState).isSameAs(websiteInfoState) + assertNotNull(store.state) + assertNotSame(initialState, store.state) + assertNotSame(initialWebsitePermissionsState, store.state.websitePermissionsState) + assertSame(websiteInfoState, store.state.webInfoState) - assertThat(store.state.websitePermissionsState.camera).isNotNull() - assertThat((store.state.websitePermissionsState.camera as WebsitePermission.Camera).name).isEqualTo( - cameraPermissionName - ) - assertThat(store.state.websitePermissionsState.camera.status).isEqualTo( - initialCameraStatus - ) - assertThat(store.state.websitePermissionsState.camera.isVisible).isEqualTo( - defaultVisibilityStatus - ) - assertThat(store.state.websitePermissionsState.camera.isEnabled).isEqualTo( - defaultEnabledStatus - ) - assertThat(store.state.websitePermissionsState.camera.isBlockedByAndroid).isEqualTo( - defaultBlockedByAndroidStatus - ) + assertNotNull(store.state.websitePermissionsState.camera) + assertEquals(cameraPermissionName, (store.state.websitePermissionsState.camera as WebsitePermission.Camera).name) + assertEquals(initialCameraStatus, store.state.websitePermissionsState.camera.status) + assertEquals(defaultVisibilityStatus, store.state.websitePermissionsState.camera.isVisible) + assertEquals(defaultEnabledStatus, store.state.websitePermissionsState.camera.isEnabled) + assertEquals(defaultBlockedByAndroidStatus, store.state.websitePermissionsState.camera.isBlockedByAndroid) - assertThat(store.state.websitePermissionsState.microphone).isNotNull() - assertThat((store.state.websitePermissionsState.microphone as WebsitePermission.Microphone).name).isEqualTo( - microphonePermissionName - ) - // Only the following two properties must have been changed! - assertThat(store.state.websitePermissionsState.microphone.status).isEqualTo( - updatedMicrophoneStatus - ) - assertThat(store.state.websitePermissionsState.microphone.isEnabled).isEqualTo( - updatedMicrophoneEnabledStatus - ) + assertNotNull(store.state.websitePermissionsState.microphone) + assertEquals(microphonePermissionName, (store.state.websitePermissionsState.microphone as WebsitePermission.Microphone).name) - assertThat(store.state.websitePermissionsState.microphone.isVisible).isEqualTo( - defaultVisibilityStatus - ) - assertThat(store.state.websitePermissionsState.microphone.isBlockedByAndroid).isEqualTo( - defaultBlockedByAndroidStatus - ) + // Only the following two properties must have been changed! + assertEquals(updatedMicrophoneStatus, store.state.websitePermissionsState.microphone.status) + assertEquals(updatedMicrophoneEnabledStatus, store.state.websitePermissionsState.microphone.isEnabled) - assertThat(store.state.websitePermissionsState.notification).isNotNull() - assertThat((store.state.websitePermissionsState.notification as WebsitePermission.Notification).name).isEqualTo( - notificationPermissionName - ) - assertThat(store.state.websitePermissionsState.notification.status).isEqualTo( - initialNotificationStatus - ) - assertThat(store.state.websitePermissionsState.notification.isVisible).isEqualTo( - defaultVisibilityStatus - ) - assertThat(store.state.websitePermissionsState.notification.isEnabled).isEqualTo( - defaultEnabledStatus - ) - assertThat(store.state.websitePermissionsState.notification.isBlockedByAndroid).isEqualTo( - defaultBlockedByAndroidStatus - ) + assertEquals(defaultVisibilityStatus, store.state.websitePermissionsState.microphone.isVisible) + assertEquals(defaultBlockedByAndroidStatus, store.state.websitePermissionsState.microphone.isBlockedByAndroid) - assertThat(store.state.websitePermissionsState.location).isNotNull() - assertThat((store.state.websitePermissionsState.location as WebsitePermission.Location).name).isEqualTo( - locationPermissionName - ) - assertThat(store.state.websitePermissionsState.location.status).isEqualTo( - initialLocationStatus - ) - assertThat(store.state.websitePermissionsState.location.isVisible).isEqualTo( - defaultVisibilityStatus - ) - assertThat(store.state.websitePermissionsState.location.isEnabled).isEqualTo( - defaultEnabledStatus - ) - assertThat(store.state.websitePermissionsState.location.isBlockedByAndroid).isEqualTo( - defaultBlockedByAndroidStatus - ) - } + assertNotNull(store.state.websitePermissionsState.notification) + assertEquals(notificationPermissionName, (store.state.websitePermissionsState.notification as WebsitePermission.Notification).name) + assertEquals(initialNotificationStatus, store.state.websitePermissionsState.notification.status) + assertEquals(defaultVisibilityStatus, store.state.websitePermissionsState.notification.isVisible) + assertEquals(defaultEnabledStatus, store.state.websitePermissionsState.notification.isEnabled) + assertEquals(defaultBlockedByAndroidStatus, store.state.websitePermissionsState.notification.isBlockedByAndroid) + + assertNotNull(store.state.websitePermissionsState.location) + assertEquals(locationPermissionName, (store.state.websitePermissionsState.location as WebsitePermission.Location).name) + assertEquals(initialLocationStatus, store.state.websitePermissionsState.location.status) + assertEquals(defaultVisibilityStatus, store.state.websitePermissionsState.location.isVisible) + assertEquals(defaultEnabledStatus, store.state.websitePermissionsState.location.isEnabled) + assertEquals(defaultBlockedByAndroidStatus, store.state.websitePermissionsState.location.isBlockedByAndroid) } @Test fun `getSecuredWebsiteUiValues() should return the right values`() { val uiValues = getSecuredWebsiteUiValues - assertAll { - assertThat(uiValues.first).isEqualTo(secureStringRes) - assertThat(uiValues.second).isEqualTo(secureDrawableRes) - assertThat(uiValues.third).isEqualTo(secureColorRes) - } + assertEquals(secureStringRes, uiValues.first) + assertEquals(secureDrawableRes, uiValues.second) + assertEquals(secureColorRes, uiValues.third) } @Test fun `getInsecureWebsiteUiValues() should return the right values`() { val uiValues = getInsecureWebsiteUiValues - assertAll { - assertThat(uiValues.first).isEqualTo(insecureStringRes) - assertThat(uiValues.second).isEqualTo(insecureDrawableRes) - assertThat(uiValues.third).isEqualTo(insecureColorRes) - } + assertEquals(insecureStringRes, uiValues.first) + assertEquals(insecureDrawableRes, uiValues.second) + assertEquals(insecureColorRes, uiValues.third) } } diff --git a/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsInteractorTest.kt b/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsInteractorTest.kt index 7d528304a..556dd513f 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsInteractorTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/quicksettings/QuickSettingsInteractorTest.kt @@ -4,13 +4,11 @@ package org.mozilla.fenix.settings.quicksettings -import assertk.assertAll -import assertk.assertThat -import assertk.assertions.isEqualTo -import assertk.assertions.isTrue import io.mockk.mockk import io.mockk.slot import io.mockk.verify +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue import org.junit.Test class QuickSettingsInteractorTest { @@ -36,9 +34,8 @@ class QuickSettingsInteractorTest { verify { controller.handlePermissionToggled(capture(permission)) } - assertAll { - assertThat(permission.isCaptured).isTrue() - assertThat(permission.captured).isEqualTo(websitePermission) - } + + assertTrue(permission.isCaptured) + assertEquals(websitePermission, permission.captured) } } diff --git a/app/src/test/java/org/mozilla/fenix/settings/quicksettings/ext/PhoneFeatureExtKtTest.kt b/app/src/test/java/org/mozilla/fenix/settings/quicksettings/ext/PhoneFeatureExtKtTest.kt index 6c3ab5305..834b88431 100644 --- a/app/src/test/java/org/mozilla/fenix/settings/quicksettings/ext/PhoneFeatureExtKtTest.kt +++ b/app/src/test/java/org/mozilla/fenix/settings/quicksettings/ext/PhoneFeatureExtKtTest.kt @@ -6,13 +6,11 @@ package org.mozilla.fenix.settings.quicksettings.ext import android.content.Context import android.content.pm.PackageManager -import assertk.assertAll -import assertk.assertThat -import assertk.assertions.isFalse -import assertk.assertions.isTrue import io.mockk.every import io.mockk.mockk import mozilla.components.feature.sitepermissions.SitePermissions +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue import org.junit.Test import org.mozilla.fenix.settings.PhoneFeature @@ -26,11 +24,9 @@ class PhoneFeatureExtKtTest { every { userAllowedPermission.camera } returns SitePermissions.Status.ALLOWED every { userBlockedPermission.camera } returns SitePermissions.Status.BLOCKED - assertAll { - assertThat(PhoneFeature.CAMERA.shouldBeVisible(noDecisionForPermission, mockk())).isFalse() - assertThat(PhoneFeature.CAMERA.shouldBeVisible(userAllowedPermission, mockk())).isTrue() - assertThat(PhoneFeature.CAMERA.shouldBeVisible(userBlockedPermission, mockk())).isTrue() - } + assertFalse(PhoneFeature.CAMERA.shouldBeVisible(noDecisionForPermission, mockk())) + assertTrue(PhoneFeature.CAMERA.shouldBeVisible(userAllowedPermission, mockk())) + assertTrue(PhoneFeature.CAMERA.shouldBeVisible(userBlockedPermission, mockk())) } @Test @@ -42,11 +38,9 @@ class PhoneFeatureExtKtTest { every { userAllowedPermission.camera } returns SitePermissions.Status.ALLOWED every { userBlockedPermission.camera } returns SitePermissions.Status.BLOCKED - assertAll { - assertThat(PhoneFeature.CAMERA.isUserPermissionGranted(userAllowedPermission, mockk())).isTrue() - assertThat(PhoneFeature.CAMERA.isUserPermissionGranted(noDecisionForPermission, mockk())).isFalse() - assertThat(PhoneFeature.CAMERA.isUserPermissionGranted(userBlockedPermission, mockk())).isFalse() - } + assertTrue(PhoneFeature.CAMERA.isUserPermissionGranted(userAllowedPermission, mockk())) + assertFalse(PhoneFeature.CAMERA.isUserPermissionGranted(noDecisionForPermission, mockk())) + assertFalse(PhoneFeature.CAMERA.isUserPermissionGranted(userBlockedPermission, mockk())) } @Test @@ -64,22 +58,14 @@ class PhoneFeatureExtKtTest { every { noDecisionForPermission.camera } returns SitePermissions.Status.NO_DECISION every { userBlockedPermission.camera } returns SitePermissions.Status.BLOCKED - assertAll { - // Check result for when the Android permission is granted to the app - assertThat(PhoneFeature.CAMERA.shouldBeEnabled( - androidPermissionGrantedContext, userAllowedPermission, mockk())).isTrue() - assertThat(PhoneFeature.CAMERA.shouldBeEnabled( - androidPermissionGrantedContext, noDecisionForPermission, mockk())).isFalse() - assertThat(PhoneFeature.CAMERA.shouldBeEnabled( - androidPermissionGrantedContext, userBlockedPermission, mockk())).isFalse() + // Check result for when the Android permission is granted to the app + assertTrue(PhoneFeature.CAMERA.shouldBeEnabled(androidPermissionGrantedContext, userAllowedPermission, mockk())) + assertFalse(PhoneFeature.CAMERA.shouldBeEnabled(androidPermissionGrantedContext, noDecisionForPermission, mockk())) + assertFalse(PhoneFeature.CAMERA.shouldBeEnabled(androidPermissionGrantedContext, userBlockedPermission, mockk())) - // Check result for when the Android permission is denied to the app - assertThat(PhoneFeature.CAMERA.shouldBeEnabled( - androidPermissionDeniedContext, userAllowedPermission, mockk())).isFalse() - assertThat(PhoneFeature.CAMERA.shouldBeEnabled( - androidPermissionDeniedContext, noDecisionForPermission, mockk())).isFalse() - assertThat(PhoneFeature.CAMERA.shouldBeEnabled( - androidPermissionDeniedContext, userBlockedPermission, mockk())).isFalse() - } + // Check result for when the Android permission is denied to the app + assertFalse(PhoneFeature.CAMERA.shouldBeEnabled(androidPermissionDeniedContext, userAllowedPermission, mockk())) + assertFalse(PhoneFeature.CAMERA.shouldBeEnabled(androidPermissionDeniedContext, noDecisionForPermission, mockk())) + assertFalse(PhoneFeature.CAMERA.shouldBeEnabled(androidPermissionDeniedContext, userBlockedPermission, mockk())) } } diff --git a/app/src/test/java/org/mozilla/fenix/share/ShareControllerTest.kt b/app/src/test/java/org/mozilla/fenix/share/ShareControllerTest.kt index 0a0fd5503..ba25848ce 100644 --- a/app/src/test/java/org/mozilla/fenix/share/ShareControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/share/ShareControllerTest.kt @@ -8,11 +8,6 @@ import android.app.Activity import android.content.Context import android.content.Intent import androidx.navigation.NavController -import assertk.assertAll -import assertk.assertThat -import assertk.assertions.isEqualTo -import assertk.assertions.isNotEqualTo -import assertk.assertions.isTrue import com.google.android.material.snackbar.Snackbar import io.mockk.Runs import io.mockk.every @@ -32,6 +27,9 @@ import mozilla.components.concept.sync.TabData import mozilla.components.feature.accounts.push.SendTabUseCases import mozilla.components.feature.share.RecentAppsStorage import mozilla.components.support.test.robolectric.testContext +import org.junit.Assert.assertEquals +import org.junit.Assert.assertNotEquals +import org.junit.Assert.assertTrue import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -101,15 +99,14 @@ class ShareControllerTest { testController.handleShareToApp(appShareOption) // Check that the Intent used for querying apps has the expected structure - assertAll { - assertThat(shareIntent.isCaptured).isTrue() - assertThat(shareIntent.captured.action).isEqualTo(Intent.ACTION_SEND) - assertThat(shareIntent.captured.extras!![Intent.EXTRA_TEXT]).isEqualTo(textToShare) - assertThat(shareIntent.captured.type).isEqualTo("text/plain") - assertThat(shareIntent.captured.flags).isEqualTo(Intent.FLAG_ACTIVITY_NEW_TASK) - assertThat(shareIntent.captured.component!!.packageName).isEqualTo(appPackageName) - assertThat(shareIntent.captured.component!!.className).isEqualTo(appClassName) - } + assertTrue(shareIntent.isCaptured) + assertEquals(Intent.ACTION_SEND, shareIntent.captured.action) + assertEquals(textToShare, shareIntent.captured.extras!![Intent.EXTRA_TEXT]) + assertEquals("text/plain", shareIntent.captured.type) + assertEquals(Intent.FLAG_ACTIVITY_NEW_TASK, shareIntent.captured.flags) + assertEquals(appPackageName, shareIntent.captured.component!!.packageName) + assertEquals(appClassName, shareIntent.captured.component!!.className) + verifyOrder { recentAppStorage.updateRecentApp(appShareOption.activityName) activityContext.startActivity(shareIntent.captured) @@ -158,12 +155,11 @@ class ShareControllerTest { sendTabUseCases.sendToDeviceAsync(capture(deviceId), capture(tabsShared)) // dismiss() is also to be called, but at the moment cannot test it in a coroutine. } - assertAll { - assertThat(deviceId.isCaptured).isTrue() - assertThat(deviceId.captured).isEqualTo(deviceToShareTo.id) - assertThat(tabsShared.isCaptured).isTrue() - assertThat(tabsShared.captured).isEqualTo(tabsData) - } + + assertTrue(deviceId.isCaptured) + assertEquals(deviceToShareTo.id, deviceId.captured) + assertTrue(tabsShared.isCaptured) + assertEquals(tabsData, tabsShared.captured) } @Test @@ -181,11 +177,10 @@ class ShareControllerTest { sendTabUseCases.sendToAllAsync(capture(tabsShared)) // dismiss() is also to be called, but at the moment cannot test it in a coroutine. } - assertAll { - // SendTabUseCases should send a the `shareTabs` mapped to tabData - assertThat(tabsShared.isCaptured).isTrue() - assertThat(tabsShared.captured).isEqualTo(tabsData) - } + + // SendTabUseCases should send a the `shareTabs` mapped to tabData + assertTrue(tabsShared.isCaptured) + assertEquals(tabsData, tabsShared.captured) } @Test @@ -267,16 +262,14 @@ class ShareControllerTest { val tabSharedMessage = controllerWithOneSharedTab.getSuccessMessage() val tabsSharedMessage = controllerWithMoreSharedTabs.getSuccessMessage() - assertAll { - assertThat(tabSharedMessage).isNotEqualTo(tabsSharedMessage) - assertThat(tabSharedMessage).isEqualTo(expectedTabSharedMessage) - assertThat(tabsSharedMessage).isEqualTo(expectedTabsSharedMessage) - } + assertNotEquals(tabsSharedMessage, tabSharedMessage) + assertEquals(expectedTabSharedMessage, tabSharedMessage) + assertEquals(expectedTabsSharedMessage, tabsSharedMessage) } @Test fun `getShareText should respect concatenate shared tabs urls`() { - assertThat(controller.getShareText()).isEqualTo(textToShare) + assertEquals(textToShare, controller.getShareText()) } @Test @@ -287,7 +280,7 @@ class ShareControllerTest { tabData = shareData.toTabData() } - assertThat(tabData).isEqualTo(tabsData) + assertEquals(tabsData, tabData) } @Test @@ -305,6 +298,6 @@ class ShareControllerTest { ).toTabData() } - assertThat(tabData).isEqualTo(expected) + assertEquals(expected, tabData) } } diff --git a/app/src/test/java/org/mozilla/fenix/share/listadapters/AccountDevicesShareAdapterTest.kt b/app/src/test/java/org/mozilla/fenix/share/listadapters/AccountDevicesShareAdapterTest.kt index a49f8cc9c..a82dfe69e 100644 --- a/app/src/test/java/org/mozilla/fenix/share/listadapters/AccountDevicesShareAdapterTest.kt +++ b/app/src/test/java/org/mozilla/fenix/share/listadapters/AccountDevicesShareAdapterTest.kt @@ -5,8 +5,6 @@ package org.mozilla.fenix.share.listadapters import android.view.ViewGroup -import assertk.assertThat -import assertk.assertions.isEqualTo import io.mockk.Runs import io.mockk.every import io.mockk.just @@ -14,6 +12,7 @@ import io.mockk.mockk import io.mockk.spyk import io.mockk.verify import mozilla.components.support.test.robolectric.testContext +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith import org.mozilla.fenix.share.ShareInteractor @@ -28,7 +27,7 @@ class AccountDevicesShareAdapterTest { fun `getItemCount on a default instantiated Adapter should return 0`() { val adapter = AccountDevicesShareAdapter(mockk()) - assertThat(adapter.itemCount).isEqualTo(0) + assertEquals(0, adapter.itemCount) } @Test @@ -39,7 +38,7 @@ class AccountDevicesShareAdapterTest { val viewHolder = adapter.onCreateViewHolder(parentView, 0) - assertThat(viewHolder::class).isEqualTo(AccountDeviceViewHolder::class) + assertEquals(AccountDeviceViewHolder::class, viewHolder::class) } @Test @@ -50,7 +49,7 @@ class AccountDevicesShareAdapterTest { val viewHolder = adapter.onCreateViewHolder(parentView, 0) - assertThat(viewHolder.interactor).isEqualTo(interactor) + assertEquals(interactor, viewHolder.interactor) } @Test diff --git a/app/src/test/java/org/mozilla/fenix/share/listadapters/AppShareAdapterTest.kt b/app/src/test/java/org/mozilla/fenix/share/listadapters/AppShareAdapterTest.kt index 1c18881f8..c7ce09fd6 100644 --- a/app/src/test/java/org/mozilla/fenix/share/listadapters/AppShareAdapterTest.kt +++ b/app/src/test/java/org/mozilla/fenix/share/listadapters/AppShareAdapterTest.kt @@ -5,8 +5,6 @@ package org.mozilla.fenix.share.listadapters import android.view.ViewGroup -import assertk.assertThat -import assertk.assertions.isEqualTo import io.mockk.Runs import io.mockk.every import io.mockk.just @@ -15,6 +13,7 @@ import io.mockk.spyk import io.mockk.verify import io.mockk.verifyOrder import mozilla.components.support.test.robolectric.testContext +import org.junit.Assert.assertEquals import org.junit.Test import org.junit.runner.RunWith import org.mozilla.fenix.share.ShareInteractor @@ -49,14 +48,14 @@ class AppShareAdapterTest { fun `getItemCount on a default instantiated Adapter should return 0`() { val adapter = AppShareAdapter(mockk()) - assertThat(adapter.itemCount).isEqualTo(0) + assertEquals(0, adapter.itemCount) } @Test fun `getItemCount after updateData() call should return the the passed in list's size`() { val adapter = AppShareAdapter(mockk()).apply { submitList(appOptions) } - assertThat(adapter.itemCount).isEqualTo(2) + assertEquals(2, adapter.itemCount) } @Test @@ -67,7 +66,7 @@ class AppShareAdapterTest { val viewHolder = adapter.onCreateViewHolder(parentView, 0) - assertThat(viewHolder::class).isEqualTo(AppViewHolder::class) + assertEquals(AppViewHolder::class, viewHolder::class) } @Test @@ -78,7 +77,7 @@ class AppShareAdapterTest { val viewHolder = adapter.onCreateViewHolder(parentView, 0) - assertThat(viewHolder.interactor).isEqualTo(interactor) + assertEquals(interactor, viewHolder.interactor) } @Test