From 453e7955bb4c08089b58260e148e662b167aa993 Mon Sep 17 00:00:00 2001 From: Tiger Oakes Date: Wed, 5 Feb 2020 20:37:49 -0800 Subject: [PATCH] Add license header to ext tests (#8130) --- .../org/mozilla/fenix/ext/ActivityTest.kt | 27 ++++++++------- .../org/mozilla/fenix/ext/BrowserIconsTest.kt | 5 ++- .../org/mozilla/fenix/ext/DrawableTest.kt | 25 ++++++++------ .../org/mozilla/fenix/ext/FragmentTest.kt | 33 ++++++++++--------- .../org/mozilla/fenix/ext/ImageButtonTest.kt | 13 +++++--- .../java/org/mozilla/fenix/ext/LogTest.kt | 14 ++++---- .../mozilla/fenix/ext/NavControllerTest.kt | 5 ++- .../{preferences.kt => SharedPreferences.kt} | 0 .../java/org/mozilla/fenix/ext/StringTest.kt | 4 +++ .../fenix/whatsnew/WhatsNewStorageTest.kt | 4 +-- 10 files changed, 77 insertions(+), 53 deletions(-) rename app/src/test/java/org/mozilla/fenix/ext/{preferences.kt => SharedPreferences.kt} (100%) diff --git a/app/src/test/java/org/mozilla/fenix/ext/ActivityTest.kt b/app/src/test/java/org/mozilla/fenix/ext/ActivityTest.kt index 768a69f0a..8363710f9 100644 --- a/app/src/test/java/org/mozilla/fenix/ext/ActivityTest.kt +++ b/app/src/test/java/org/mozilla/fenix/ext/ActivityTest.kt @@ -1,35 +1,38 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + package org.mozilla.fenix.ext -import org.mozilla.fenix.TestApplication -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.Assert.assertTrue -import org.junit.Assert.assertEquals -import org.robolectric.Robolectric -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config import android.app.Activity import android.view.View import android.view.WindowManager +import org.junit.Assert.assertEquals +import org.junit.Assert.assertTrue +import org.junit.Test +import org.junit.runner.RunWith +import org.mozilla.fenix.TestApplication +import org.robolectric.Robolectric +import org.robolectric.RobolectricTestRunner import org.robolectric.Shadows.shadowOf +import org.robolectric.annotation.Config @RunWith(RobolectricTestRunner::class) @Config(application = TestApplication::class) - class ActivityTest { @Test fun testEnterImmersiveMode() { val activity = Robolectric.buildActivity(Activity::class.java).create().get() - val window = activity.getWindow() + val window = activity.window // Turn off Keep Screen on Flag if it is on if (shadowOf(window).getFlag(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)) window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) // Make sure that System UI flags are not set before the test val flags = arrayOf(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION, View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN, View.SYSTEM_UI_FLAG_HIDE_NAVIGATION, View.SYSTEM_UI_FLAG_FULLSCREEN, View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) - if (flags.any { f -> (window.getDecorView().getSystemUiVisibility() and f) == f }) { - window.getDecorView().setSystemUiVisibility(0) + if (flags.any { f -> (window.decorView.systemUiVisibility and f) == f }) { + window.decorView.systemUiVisibility = 0 } // Run diff --git a/app/src/test/java/org/mozilla/fenix/ext/BrowserIconsTest.kt b/app/src/test/java/org/mozilla/fenix/ext/BrowserIconsTest.kt index 44eee3118..96f71232c 100644 --- a/app/src/test/java/org/mozilla/fenix/ext/BrowserIconsTest.kt +++ b/app/src/test/java/org/mozilla/fenix/ext/BrowserIconsTest.kt @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + package org.mozilla.fenix.ext import android.widget.ImageView @@ -15,7 +19,6 @@ import org.robolectric.annotation.Config @RunWith(RobolectricTestRunner::class) @Config(application = TestApplication::class) - class BrowserIconsTest { @Test fun loadIntoViewTest() { diff --git a/app/src/test/java/org/mozilla/fenix/ext/DrawableTest.kt b/app/src/test/java/org/mozilla/fenix/ext/DrawableTest.kt index 129a9291a..7b016be70 100644 --- a/app/src/test/java/org/mozilla/fenix/ext/DrawableTest.kt +++ b/app/src/test/java/org/mozilla/fenix/ext/DrawableTest.kt @@ -1,28 +1,33 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + package org.mozilla.fenix.ext -import org.mozilla.fenix.TestApplication -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.Assert.assertFalse -import org.junit.Assert.assertTrue -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config -import android.graphics.drawable.Drawable -import android.graphics.Rect import android.graphics.Canvas import android.graphics.ColorFilter +import android.graphics.Rect +import android.graphics.drawable.Drawable +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test +import org.junit.runner.RunWith +import org.mozilla.fenix.TestApplication +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config @RunWith(RobolectricTestRunner::class) @Config(application = TestApplication::class) - class DrawableTest { @Test fun testSetBounds() { val drawable = TestDrawable() assertFalse(drawable.boundsChanged) + val size = 10 drawable.setBounds(size) assertTrue(drawable.boundsChanged) + val returnRec = drawable.copyBounds() assertTrue(returnRec.contains(0, 0, -10, 10)) } diff --git a/app/src/test/java/org/mozilla/fenix/ext/FragmentTest.kt b/app/src/test/java/org/mozilla/fenix/ext/FragmentTest.kt index 05b47d732..75a0c1b06 100644 --- a/app/src/test/java/org/mozilla/fenix/ext/FragmentTest.kt +++ b/app/src/test/java/org/mozilla/fenix/ext/FragmentTest.kt @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + package org.mozilla.fenix.ext import androidx.fragment.app.Fragment @@ -25,25 +29,24 @@ import org.robolectric.annotation.Config @RunWith(RobolectricTestRunner::class) @Config(application = TestApplication::class) - class FragmentTest { - val navDirections: NavDirections = mockk(relaxed = true) - val mockDestination = spyk(NavDestination("hi")) - val mockExtras: Extras = mockk(relaxed = true) - val mockId = 4 - val navController = spyk(NavController(testContext)) - val mockFragment: Fragment = mockk(relaxed = true) - val mockOptions: NavOptions = mockk(relaxed = true) + private val navDirections: NavDirections = mockk(relaxed = true) + private val mockDestination = spyk(NavDestination("hi")) + private val mockExtras: Extras = mockk(relaxed = true) + private val mockId = 4 + private val navController = spyk(NavController(testContext)) + private val mockFragment: Fragment = mockk(relaxed = true) + private val mockOptions: NavOptions = mockk(relaxed = true) @Before fun setup() { mockkStatic(NavHostFragment::class) every { (NavHostFragment.findNavController(mockFragment)) } returns navController - every { (NavHostFragment.findNavController(mockFragment).getCurrentDestination()) } returns mockDestination - every { (mockDestination.getId()) } returns mockId - every { (navController.getCurrentDestination()) } returns mockDestination - every { (NavHostFragment.findNavController(mockFragment).getCurrentDestination()?.getId()) } answers { (mockDestination.getId()) } + every { (NavHostFragment.findNavController(mockFragment).currentDestination) } returns mockDestination + every { (mockDestination.id) } returns mockId + every { (navController.currentDestination) } returns mockDestination + every { (NavHostFragment.findNavController(mockFragment).currentDestination?.id) } answers { (mockDestination.id) } } @Test @@ -51,7 +54,7 @@ class FragmentTest { every { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, null)) } just Runs mockFragment.nav(mockId, navDirections) - verify { (NavHostFragment.findNavController(mockFragment).getCurrentDestination()) } + verify { (NavHostFragment.findNavController(mockFragment).currentDestination) } verify { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, null)) } confirmVerified(mockFragment) } @@ -61,7 +64,7 @@ class FragmentTest { every { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockExtras)) } just Runs mockFragment.nav(mockId, navDirections, mockExtras) - verify { (NavHostFragment.findNavController(mockFragment).getCurrentDestination()) } + verify { (NavHostFragment.findNavController(mockFragment).currentDestination) } verify { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockExtras)) } confirmVerified(mockFragment) } @@ -71,7 +74,7 @@ class FragmentTest { every { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockOptions)) } just Runs mockFragment.nav(mockId, navDirections, mockOptions) - verify { (NavHostFragment.findNavController(mockFragment).getCurrentDestination()) } + verify { (NavHostFragment.findNavController(mockFragment).currentDestination) } verify { (NavHostFragment.findNavController(mockFragment).navigate(navDirections, mockOptions)) } confirmVerified(mockFragment) } diff --git a/app/src/test/java/org/mozilla/fenix/ext/ImageButtonTest.kt b/app/src/test/java/org/mozilla/fenix/ext/ImageButtonTest.kt index 64704d29b..06387db9c 100644 --- a/app/src/test/java/org/mozilla/fenix/ext/ImageButtonTest.kt +++ b/app/src/test/java/org/mozilla/fenix/ext/ImageButtonTest.kt @@ -1,6 +1,10 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + package org.mozilla.fenix.ext -import kotlinx.coroutines.ObsoleteCoroutinesApi +import android.view.View import mozilla.components.support.test.robolectric.testContext import org.mozilla.fenix.TestApplication import org.junit.Test @@ -12,23 +16,22 @@ import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config import android.widget.ImageButton -@ObsoleteCoroutinesApi @RunWith(RobolectricTestRunner::class) @Config(application = TestApplication::class) class ImageButtonTest { - val imageButton = ImageButton(testContext) + private val imageButton = ImageButton(testContext) @Test fun `Hide and disable`() { imageButton.hideAndDisable() assertFalse(imageButton.isEnabled) - assertEquals(4, imageButton.visibility) + assertEquals(View.INVISIBLE, imageButton.visibility) } @Test fun `Show and enable`() { imageButton.showAndEnable() assertTrue(imageButton.isEnabled) - assertEquals(0, imageButton.visibility) + assertEquals(View.VISIBLE, imageButton.visibility) } } diff --git a/app/src/test/java/org/mozilla/fenix/ext/LogTest.kt b/app/src/test/java/org/mozilla/fenix/ext/LogTest.kt index 5831829a7..5a553339f 100644 --- a/app/src/test/java/org/mozilla/fenix/ext/LogTest.kt +++ b/app/src/test/java/org/mozilla/fenix/ext/LogTest.kt @@ -4,23 +4,23 @@ package org.mozilla.fenix.ext -import org.mozilla.fenix.TestApplication -import org.junit.Test -import org.junit.runner.RunWith -import org.robolectric.RobolectricTestRunner -import org.robolectric.annotation.Config +import android.util.Log import io.mockk.mockk import io.mockk.mockkStatic import io.mockk.verify -import android.util.Log import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mozilla.fenix.TestApplication +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config @RunWith(RobolectricTestRunner::class) @Config(application = TestApplication::class) class LogTest { - val numCalls = if (org.mozilla.fenix.Config.channel.isDebug) 1 else 0 + private val numCalls = if (org.mozilla.fenix.Config.channel.isDebug) 1 else 0 @Before fun setup() { diff --git a/app/src/test/java/org/mozilla/fenix/ext/NavControllerTest.kt b/app/src/test/java/org/mozilla/fenix/ext/NavControllerTest.kt index 4e22e5fe8..dfe43af77 100644 --- a/app/src/test/java/org/mozilla/fenix/ext/NavControllerTest.kt +++ b/app/src/test/java/org/mozilla/fenix/ext/NavControllerTest.kt @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + package org.mozilla.fenix.ext import android.os.Bundle @@ -18,7 +22,6 @@ import org.robolectric.annotation.Config @RunWith(RobolectricTestRunner::class) @Config(application = TestApplication::class) - class NavControllerTest { private val navController: NavController = mockk(relaxed = true) diff --git a/app/src/test/java/org/mozilla/fenix/ext/preferences.kt b/app/src/test/java/org/mozilla/fenix/ext/SharedPreferences.kt similarity index 100% rename from app/src/test/java/org/mozilla/fenix/ext/preferences.kt rename to app/src/test/java/org/mozilla/fenix/ext/SharedPreferences.kt 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 d370c3e44..a2d7430e0 100644 --- a/app/src/test/java/org/mozilla/fenix/ext/StringTest.kt +++ b/app/src/test/java/org/mozilla/fenix/ext/StringTest.kt @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + package org.mozilla.fenix.ext import assertk.assertThat diff --git a/app/src/test/java/org/mozilla/fenix/whatsnew/WhatsNewStorageTest.kt b/app/src/test/java/org/mozilla/fenix/whatsnew/WhatsNewStorageTest.kt index 244170482..0b51f36a2 100644 --- a/app/src/test/java/org/mozilla/fenix/whatsnew/WhatsNewStorageTest.kt +++ b/app/src/test/java/org/mozilla/fenix/whatsnew/WhatsNewStorageTest.kt @@ -1,9 +1,9 @@ -package org.mozilla.fenix.whatsnew - /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +package org.mozilla.fenix.whatsnew + import androidx.test.ext.junit.runners.AndroidJUnit4 import mozilla.components.support.test.robolectric.testContext import org.junit.Assert