Best Mockito-kotlin code snippet using test.Open.closed
SessionLifecycleTest.kt
Source:SessionLifecycleTest.kt
...75 assertThat("New session has same settings",76 newSession.settings, equalTo(session.settings))77 assertThat("New session is open", newSession.isOpen, equalTo(true))78 newSession.close()79 assertThat("New session can be closed", newSession.isOpen, equalTo(false))80 }81 sessionRule.session.reload()82 sessionRule.session.waitForPageStop()83 }84 @Test(expected = IllegalStateException::class)85 fun readFromParcel_throwOnAlreadyOpen() {86 //disable readFromParcel_throwOnAlreadyOpen for frequent failures Bug 153218687 assumeThat(sessionRule.env.isDebugBuild, equalTo(true))88 // Throw exception if retrying to open again; otherwise we would leak the old open window.89 sessionRule.session.toParcel { parcel ->90 sessionRule.createOpenSession().readFromParcel(parcel)91 }92 }93 @Test fun readFromParcel_canLoadPageAfterRead() {94 val newSession = sessionRule.createClosedSession()95 sessionRule.session.toParcel { parcel ->96 newSession.readFromParcel(parcel)97 }98 newSession.reload()99 newSession.waitForPageStop()100 }101 @Test fun readFromParcel_closedSession() {102 val session = sessionRule.createClosedSession()103 session.toParcel { parcel ->104 val newSession = sessionRule.createClosedSession()105 newSession.readFromParcel(parcel)106 assertThat("New session should not be open",107 newSession.isOpen, equalTo(false))108 }109 sessionRule.session.reload()110 sessionRule.session.waitForPageStop()111 }112 @Test fun readFromParcel_closedSessionAfterParceling() {113 val session = sessionRule.createOpenSession()114 session.toParcel { parcel ->115 assertThat("Session is still open", session.isOpen, equalTo(true))116 session.close()117 val newSession = sessionRule.createClosedSession()118 newSession.readFromParcel(parcel)119 assertThat("New session should not be open",120 newSession.isOpen, equalTo(false))121 }122 sessionRule.session.reload()123 sessionRule.session.waitForPageStop()124 }125 @Test fun readFromParcel_closedSessionAfterReadParcel() {126 // disable test on opt for frequently failing Bug 1519591127 assumeThat(sessionRule.env.isDebugBuild, equalTo(true))128 val session = sessionRule.createOpenSession()129 session.toParcel { parcel ->130 assertThat("Session is still open", session.isOpen, equalTo(true))131 val newSession = sessionRule.createClosedSession()132 newSession.readFromParcel(parcel)133 assertThat("New session should be open",134 newSession.isOpen, equalTo(true))135 assertThat("Old session should be closed",136 session.isOpen, equalTo(false))137 }138 sessionRule.session.reload()139 sessionRule.session.waitForPageStop()140 }141 @Test fun readFromParcel_closeOpenAndLoad() {142 val newSession = sessionRule.createClosedSession()143 sessionRule.session.toParcel { parcel ->144 newSession.readFromParcel(parcel)145 }146 newSession.close()147 newSession.open()148 newSession.reload()149 newSession.waitForPageStop()150 }151 @Test fun readFromParcel_allowCallsBeforeUnparceling() {152 val newSession = sessionRule.createClosedSession()153 newSession.loadTestPath(HELLO_HTML_PATH)154 newSession.reload()155 sessionRule.session.toParcel { parcel ->156 newSession.readFromParcel(parcel)157 }158 newSession.waitForPageStops(2)159 }160 @Test fun readFromParcel_chained() {161 val session1 = sessionRule.createClosedSession()162 val session2 = sessionRule.createClosedSession()163 val session3 = sessionRule.createClosedSession()164 sessionRule.session.toParcel { parcel ->165 session1.readFromParcel(parcel)166 }167 session1.toParcel { parcel ->168 session2.readFromParcel(parcel)169 }170 session2.toParcel { parcel ->171 session3.readFromParcel(parcel)172 }173 session3.reload()174 session3.waitForPageStop()175 }176 @NullDelegate(GeckoSession.NavigationDelegate::class)177 @ClosedSessionAtStart178 @Test fun readFromParcel_moduleUpdated() {179 val session = sessionRule.createOpenSession()180 // Disable navigation notifications on the old, open session.181 assertThat("Old session navigation delegate should be null",182 session.navigationDelegate, nullValue())183 // Enable navigation notifications on the new, closed session.184 var onLocationCount = 0185 sessionRule.session.navigationDelegate = object : Callbacks.NavigationDelegate {186 override fun onLocationChange(session: GeckoSession, url: String?) {187 onLocationCount++188 }189 }190 // Transferring the old session to the new session should191 // automatically re-enable navigation notifications.192 session.toParcel { parcel ->193 sessionRule.session.readFromParcel(parcel)194 }195 sessionRule.session.reload()196 sessionRule.session.waitForPageStop()197 assertThat("New session should receive navigation notifications",198 onLocationCount, equalTo(1))199 }200 @WithDevToolsAPI201 @Test fun readFromParcel_focusedInput() {202 // When an input is focused, make sure SessionTextInput is still active after transferring.203 mainSession.loadTestPath(INPUTS_PATH)204 mainSession.waitForPageStop()205 mainSession.evaluateJS("$('#input').focus()")206 mainSession.waitUntilCalled(object : Callbacks.TextInputDelegate {207 @AssertCalled(count = 1)208 override fun restartInput(session: GeckoSession, reason: Int) {209 assertThat("Reason should be correct",210 reason, equalTo(GeckoSession.TextInputDelegate.RESTART_REASON_FOCUS))211 }212 })213 val newSession = sessionRule.createClosedSession()214 mainSession.toParcel { parcel ->215 newSession.readFromParcel(parcel)216 }217 // We generate an extra focus event during transfer.218 newSession.waitUntilCalled(object : Callbacks.TextInputDelegate {219 @AssertCalled(count = 1)220 override fun restartInput(session: GeckoSession, reason: Int) {221 assertThat("Reason should be correct",222 reason, equalTo(GeckoSession.TextInputDelegate.RESTART_REASON_FOCUS))223 }224 })225 newSession.evaluateJS("$('#input').blur()")226 newSession.waitUntilCalled(object : Callbacks.TextInputDelegate {227 @AssertCalled(count = 1)228 override fun restartInput(session: GeckoSession, reason: Int) {229 // We generate an extra focus event during transfer.230 assertThat("Reason should be correct",231 reason, equalTo(GeckoSession.TextInputDelegate.RESTART_REASON_BLUR))232 }233 })234 }235 private fun testRestoreInstanceState(fromSession: GeckoSession?,236 ontoSession: GeckoSession?) =237 GeckoView(InstrumentationRegistry.getTargetContext()).apply {238 id = 0239 if (fromSession != null) {240 setSession(fromSession, sessionRule.runtime)241 }242 val state = SparseArray<Parcelable>()243 saveHierarchyState(state)244 if (ontoSession !== fromSession) {245 releaseSession()246 if (ontoSession != null) {247 setSession(ontoSession, sessionRule.runtime)248 }249 }250 restoreHierarchyState(state)251 }252 @ClosedSessionAtStart253 @Test fun restoreRuntimeSettings_noSession() {254 val extrasSetting = Bundle(2)255 extrasSetting.putInt("test1", 10)256 extrasSetting.putBoolean("test2", true)257 val settings = GeckoRuntimeSettings.Builder()258 .javaScriptEnabled(false)259 .extras(extrasSetting)260 .build()261 settings.toParcel { parcel ->262 val newSettings = GeckoRuntimeSettings.Builder().build()263 newSettings.readFromParcel(parcel)264 assertThat("Parceled settings must match",265 newSettings.javaScriptEnabled,266 equalTo(settings.javaScriptEnabled))267 assertThat("Parceled settings must match",268 newSettings.extras.getInt("test1"),269 equalTo(settings.extras.getInt("test1")))270 assertThat("Parceled settings must match",271 newSettings.extras.getBoolean("test2"),272 equalTo(settings.extras.getBoolean("test2")))273 }274 }275 @ClosedSessionAtStart276 @Test fun restoreInstanceState_noSessionOntoNoSession() {277 val view = testRestoreInstanceState(null, null)278 assertThat("View session is restored", view.session, nullValue())279 }280 @ClosedSessionAtStart281 @Test fun restoreInstanceState_closedSessionOntoNoSession() {282 val view = testRestoreInstanceState(mainSession, null)283 assertThat("View session is restored", view.session, equalTo(mainSession))284 assertThat("View session is closed", view.session?.isOpen, equalTo(false))285 }286 @Test fun restoreInstanceState_openSessionOntoNoSession() {287 val view = testRestoreInstanceState(mainSession, null)288 assertThat("View session is restored", view.session, equalTo(mainSession))289 assertThat("View session is open", view.session?.isOpen, equalTo(true))290 view.session?.reload()291 sessionRule.waitForPageStop()292 }293 @ClosedSessionAtStart294 @Test fun restoreInstanceState_noSessionOntoClosedSession() {295 val view = testRestoreInstanceState(null, sessionRule.createClosedSession())296 assertThat("View session is not restored", view.session, notNullValue())297 assertThat("View session is closed", view.session?.isOpen, equalTo(false))298 }299 @ClosedSessionAtStart300 @Test fun restoreInstanceState_closedSessionOntoClosedSession() {301 val view = testRestoreInstanceState(mainSession, sessionRule.createClosedSession())302 assertThat("View session is restored", view.session, equalTo(mainSession))303 assertThat("View session is closed", view.session?.isOpen, equalTo(false))304 }305 @Test fun restoreInstanceState_openSessionOntoClosedSession() {306 val view = testRestoreInstanceState(mainSession, sessionRule.createClosedSession())307 assertThat("View session is restored", view.session, equalTo(mainSession))308 assertThat("View session is open", view.session?.isOpen, equalTo(true))309 view.session?.reload()310 sessionRule.waitForPageStop()311 }312 @ClosedSessionAtStart313 @Test fun restoreInstanceState_noSessionOntoOpenSession() {314 val view = testRestoreInstanceState(null, sessionRule.createOpenSession())315 assertThat("View session is not restored", view.session, notNullValue())316 assertThat("View session is open", view.session?.isOpen, equalTo(true))317 view.session?.reload()318 sessionRule.waitForPageStop()319 }320 @ClosedSessionAtStart321 @Test fun restoreInstanceState_closedSessionOntoOpenSession() {322 val view = testRestoreInstanceState(mainSession, sessionRule.createOpenSession())323 assertThat("View session is not restored", view.session, not(equalTo(mainSession)))324 assertThat("View session is open", view.session?.isOpen, equalTo(true))325 view.session?.reload()326 sessionRule.waitForPageStop()327 }328 @Test fun restoreInstanceState_openSessionOntoOpenSession() {329 val view = testRestoreInstanceState(mainSession, sessionRule.createOpenSession())330 assertThat("View session is restored", view.session, equalTo(mainSession))331 assertThat("View session is open", view.session?.isOpen, equalTo(true))332 view.session?.reload()333 sessionRule.waitForPageStop()334 }335 @ClosedSessionAtStart336 @Test fun restoreInstanceState_sameClosedSession() {337 val view = testRestoreInstanceState(mainSession, mainSession)338 assertThat("View session is unchanged", view.session, equalTo(mainSession))339 assertThat("View session is closed", view.session!!.isOpen, equalTo(false))340 }341 @Test fun restoreInstanceState_sameOpenSession() {342 // We should keep the session open when restoring the same open session.343 val view = testRestoreInstanceState(mainSession, mainSession)344 assertThat("View session is unchanged", view.session, equalTo(mainSession))345 assertThat("View session is open", view.session!!.isOpen, equalTo(true))346 view.session!!.reload()347 sessionRule.waitForPageStop()348 }349 @Test fun createFromParcel() {350 val session = sessionRule.createOpenSession()351 session.toParcel { parcel ->352 val newSession = sessionRule.wrapSession(353 GeckoSession.CREATOR.createFromParcel(parcel))354 assertThat("New session has same settings",355 newSession.settings, equalTo(session.settings))356 assertThat("New session is open", newSession.isOpen, equalTo(true))357 newSession.close()358 assertThat("New session can be closed", newSession.isOpen, equalTo(false))359 }360 sessionRule.session.reload()361 sessionRule.session.waitForPageStop()362 }363 @Test fun collectClosed() {364 // We can't use a normal scoped function like `run` because365 // those are inlined, which leaves a local reference.366 fun createSession(): QueuedWeakReference<GeckoSession> {367 return QueuedWeakReference<GeckoSession>(GeckoSession())368 }369 waitUntilCollected(createSession())370 }371 @Test fun collectAfterClose() {372 fun createSession(): QueuedWeakReference<GeckoSession> {...
DefaultRecentlyClosedControllerTest.kt
Source:DefaultRecentlyClosedControllerTest.kt
1/* This Source Code Form is subject to the terms of the Mozilla Public2 * License, v. 2.0. If a copy of the MPL was not distributed with this3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */4package org.mozilla.fenix.library.recentlyclosed5import androidx.navigation.NavController6import androidx.navigation.NavOptions7import io.mockk.mockk8import io.mockk.coEvery9import io.mockk.clearMocks10import io.mockk.every11import io.mockk.verify12import io.mockk.coVerify13import io.mockk.just14import io.mockk.Runs15import kotlinx.coroutines.CoroutineScope16import kotlinx.coroutines.Dispatchers17import kotlinx.coroutines.runBlocking18import mozilla.components.browser.state.action.RecentlyClosedAction19import mozilla.components.browser.state.state.recover.TabState20import mozilla.components.browser.state.store.BrowserStore21import mozilla.components.concept.engine.prompt.ShareData22import mozilla.components.feature.recentlyclosed.RecentlyClosedTabsStorage23import mozilla.components.feature.tabs.TabsUseCases24import mozilla.components.support.test.robolectric.testContext25import mozilla.telemetry.glean.testing.GleanTestRule26import org.junit.Assert.assertEquals27import org.junit.Assert.assertFalse28import org.junit.Assert.assertNull29import org.junit.Assert.assertTrue30import org.junit.Before31import org.junit.Rule32import org.junit.Test33import org.junit.runner.RunWith34import org.mozilla.fenix.GleanMetrics.RecentlyClosedTabs35import org.mozilla.fenix.HomeActivity36import org.mozilla.fenix.R37import org.mozilla.fenix.browser.browsingmode.BrowsingMode38import org.mozilla.fenix.components.metrics.MetricController39import org.mozilla.fenix.ext.directionsEq40import org.mozilla.fenix.ext.optionsEq41import org.mozilla.fenix.helpers.FenixRobolectricTestRunner42@RunWith(FenixRobolectricTestRunner::class)43class DefaultRecentlyClosedControllerTest {44 private val navController: NavController = mockk(relaxed = true)45 private val activity: HomeActivity = mockk(relaxed = true)46 private val browserStore: BrowserStore = mockk(relaxed = true)47 private val recentlyClosedStore: RecentlyClosedFragmentStore = mockk(relaxed = true)48 private val tabsUseCases: TabsUseCases = mockk(relaxed = true)49 private val metrics: MetricController = mockk(relaxed = true)50 @get:Rule51 val gleanTestRule = GleanTestRule(testContext)52 @Before53 fun setUp() {54 coEvery { tabsUseCases.restore.invoke(any(), any(), true) } just Runs55 }56 @Test57 fun handleOpen() {58 val item: TabState = mockk(relaxed = true)59 var tabUrl: String? = null60 var actualBrowsingMode: BrowsingMode? = null61 val controller = createController(62 openToBrowser = { url, browsingMode ->63 tabUrl = url64 actualBrowsingMode = browsingMode65 }66 )67 controller.handleOpen(item, BrowsingMode.Private)68 assertEquals(item.url, tabUrl)69 assertEquals(actualBrowsingMode, BrowsingMode.Private)70 tabUrl = null71 actualBrowsingMode = null72 controller.handleOpen(item, BrowsingMode.Normal)73 assertEquals(item.url, tabUrl)74 assertEquals(actualBrowsingMode, BrowsingMode.Normal)75 }76 @Test77 fun `open multiple tabs`() {78 val tabs = createFakeTabList(2)79 val tabUrls = mutableListOf<String>()80 val actualBrowsingModes = mutableListOf<BrowsingMode?>()81 val controller = createController(82 openToBrowser = { url, mode ->83 tabUrls.add(url)84 actualBrowsingModes.add(mode)85 }86 )87 assertFalse(RecentlyClosedTabs.menuOpenInNormalTab.testHasValue())88 controller.handleOpen(tabs.toSet(), BrowsingMode.Normal)89 assertEquals(2, tabUrls.size)90 assertEquals(tabs[0].url, tabUrls[0])91 assertEquals(tabs[1].url, tabUrls[1])92 assertEquals(BrowsingMode.Normal, actualBrowsingModes[0])93 assertEquals(BrowsingMode.Normal, actualBrowsingModes[1])94 assertTrue(RecentlyClosedTabs.menuOpenInNormalTab.testHasValue())95 assertNull(RecentlyClosedTabs.menuOpenInNormalTab.testGetValue().last().extra)96 clearMocks(metrics)97 tabUrls.clear()98 actualBrowsingModes.clear()99 controller.handleOpen(tabs.toSet(), BrowsingMode.Private)100 assertEquals(2, tabUrls.size)101 assertEquals(tabs[0].url, tabUrls[0])102 assertEquals(tabs[1].url, tabUrls[1])103 assertEquals(BrowsingMode.Private, actualBrowsingModes[0])104 assertEquals(BrowsingMode.Private, actualBrowsingModes[1])105 assertTrue(RecentlyClosedTabs.menuOpenInPrivateTab.testHasValue())106 assertEquals(1, RecentlyClosedTabs.menuOpenInPrivateTab.testGetValue().size)107 assertNull(RecentlyClosedTabs.menuOpenInPrivateTab.testGetValue().single().extra)108 }109 @Test110 fun `handle selecting first tab`() {111 val selectedTab = createFakeTab()112 every { recentlyClosedStore.state.selectedTabs } returns emptySet()113 assertFalse(RecentlyClosedTabs.enterMultiselect.testHasValue())114 createController().handleSelect(selectedTab)115 verify { recentlyClosedStore.dispatch(RecentlyClosedFragmentAction.Select(selectedTab)) }116 assertTrue(RecentlyClosedTabs.enterMultiselect.testHasValue())117 assertEquals(1, RecentlyClosedTabs.enterMultiselect.testGetValue().size)118 assertNull(RecentlyClosedTabs.enterMultiselect.testGetValue().single().extra)119 }120 @Test121 fun `handle selecting a successive tab`() {122 val selectedTab = createFakeTab()123 every { recentlyClosedStore.state.selectedTabs } returns setOf(mockk())124 createController().handleSelect(selectedTab)125 verify { recentlyClosedStore.dispatch(RecentlyClosedFragmentAction.Select(selectedTab)) }126 assertFalse(RecentlyClosedTabs.enterMultiselect.testHasValue())127 }128 @Test129 fun `handle deselect last tab`() {130 val deselectedTab = createFakeTab()131 every { recentlyClosedStore.state.selectedTabs } returns setOf(deselectedTab)132 assertFalse(RecentlyClosedTabs.exitMultiselect.testHasValue())133 createController().handleDeselect(deselectedTab)134 verify { recentlyClosedStore.dispatch(RecentlyClosedFragmentAction.Deselect(deselectedTab)) }135 assertTrue(RecentlyClosedTabs.exitMultiselect.testHasValue())136 assertEquals(1, RecentlyClosedTabs.exitMultiselect.testGetValue().size)137 assertNull(RecentlyClosedTabs.exitMultiselect.testGetValue().single().extra)138 }139 @Test140 fun `handle deselect a tab from others still selected`() {141 val deselectedTab = createFakeTab()142 every { recentlyClosedStore.state.selectedTabs } returns setOf(deselectedTab, mockk())143 createController().handleDeselect(deselectedTab)144 verify { recentlyClosedStore.dispatch(RecentlyClosedFragmentAction.Deselect(deselectedTab)) }145 assertFalse(RecentlyClosedTabs.exitMultiselect.testHasValue())146 }147 @Test148 fun handleDelete() {149 val item: TabState = mockk(relaxed = true)150 assertFalse(RecentlyClosedTabs.deleteTab.testHasValue())151 createController().handleDelete(item)152 verify {153 browserStore.dispatch(RecentlyClosedAction.RemoveClosedTabAction(item))154 }155 assertTrue(RecentlyClosedTabs.deleteTab.testHasValue())156 assertEquals(1, RecentlyClosedTabs.deleteTab.testGetValue().size)157 assertNull(RecentlyClosedTabs.deleteTab.testGetValue().single().extra)158 }159 @Test160 fun `delete multiple tabs`() {161 val tabs = createFakeTabList(2)162 assertFalse(RecentlyClosedTabs.menuDelete.testHasValue())163 createController().handleDelete(tabs.toSet())164 verify {165 browserStore.dispatch(RecentlyClosedAction.RemoveClosedTabAction(tabs[0]))166 browserStore.dispatch(RecentlyClosedAction.RemoveClosedTabAction(tabs[1]))167 }168 assertTrue(RecentlyClosedTabs.menuDelete.testHasValue())169 assertNull(RecentlyClosedTabs.menuDelete.testGetValue().last().extra)170 }171 @Test172 fun handleNavigateToHistory() {173 assertFalse(RecentlyClosedTabs.showFullHistory.testHasValue())174 createController().handleNavigateToHistory()175 verify {176 navController.navigate(177 directionsEq(178 RecentlyClosedFragmentDirections.actionGlobalHistoryFragment()179 ),180 optionsEq(NavOptions.Builder().setPopUpTo(R.id.historyFragment, true).build())181 )182 }183 assertTrue(RecentlyClosedTabs.showFullHistory.testHasValue())184 assertEquals(1, RecentlyClosedTabs.showFullHistory.testGetValue().size)185 assertNull(RecentlyClosedTabs.showFullHistory.testGetValue().single().extra)186 }187 @Test188 fun `share multiple tabs`() {189 val tabs = createFakeTabList(2)190 assertFalse(RecentlyClosedTabs.menuShare.testHasValue())191 createController().handleShare(tabs.toSet())192 verify {193 val data = arrayOf(194 ShareData(title = tabs[0].title, url = tabs[0].url),195 ShareData(title = tabs[1].title, url = tabs[1].url)196 )197 navController.navigate(198 directionsEq(RecentlyClosedFragmentDirections.actionGlobalShareFragment(data))199 )200 }201 assertTrue(RecentlyClosedTabs.menuShare.testHasValue())202 assertEquals(1, RecentlyClosedTabs.menuShare.testGetValue().size)203 assertNull(RecentlyClosedTabs.menuShare.testGetValue().single().extra)204 }205 @Test206 fun handleRestore() = runBlocking {207 val item: TabState = mockk(relaxed = true)208 assertFalse(RecentlyClosedTabs.openTab.testHasValue())209 createController(scope = this).handleRestore(item)210 coVerify { tabsUseCases.restore.invoke(eq(item), any(), true) }211 assertTrue(RecentlyClosedTabs.openTab.testHasValue())212 assertEquals(1, RecentlyClosedTabs.openTab.testGetValue().size)213 assertNull(RecentlyClosedTabs.openTab.testGetValue().single().extra)214 }215 @Test216 fun `exist multi-select mode when back is pressed`() {217 every { recentlyClosedStore.state.selectedTabs } returns createFakeTabList(3).toSet()218 assertFalse(RecentlyClosedTabs.exitMultiselect.testHasValue())219 createController().handleBackPressed()220 verify { recentlyClosedStore.dispatch(RecentlyClosedFragmentAction.DeselectAll) }221 assertTrue(RecentlyClosedTabs.exitMultiselect.testHasValue())222 assertEquals(1, RecentlyClosedTabs.exitMultiselect.testGetValue().size)223 assertNull(RecentlyClosedTabs.exitMultiselect.testGetValue().single().extra)224 }225 @Test226 fun `report closing the fragment when back is pressed`() {227 every { recentlyClosedStore.state.selectedTabs } returns emptySet()228 assertFalse(RecentlyClosedTabs.closed.testHasValue())229 createController().handleBackPressed()230 verify(exactly = 0) { recentlyClosedStore.dispatch(RecentlyClosedFragmentAction.DeselectAll) }231 assertTrue(RecentlyClosedTabs.closed.testHasValue())232 assertEquals(1, RecentlyClosedTabs.closed.testGetValue().size)233 assertNull(RecentlyClosedTabs.closed.testGetValue().single().extra)234 }235 private fun createController(236 scope: CoroutineScope = CoroutineScope(Dispatchers.IO),237 openToBrowser: (String, BrowsingMode?) -> Unit = { _, _ -> },238 ): RecentlyClosedController {239 return DefaultRecentlyClosedController(240 navController,241 browserStore,242 recentlyClosedStore,243 RecentlyClosedTabsStorage(testContext, mockk(), mockk()),244 tabsUseCases,245 activity,246 scope,247 openToBrowser...
SubpluginsIT.kt
Source:SubpluginsIT.kt
...29 Project("allOpenSimple").build("build") {30 assertSuccessful()31 val classesDir = File(project.projectDir, kotlinClassesDir())32 val openClass = File(classesDir, "test/OpenClass.class")33 val closedClass = File(classesDir, "test/ClosedClass.class")34 assertTrue(openClass.exists())35 assertTrue(closedClass.exists())36 checkBytecodeContains(37 openClass,38 "public class test/OpenClass {",39 "public method()V"40 )41 checkBytecodeContains(42 closedClass,43 "public final class test/ClosedClass {",44 "public final method()V"45 )46 }47 }48 @Test49 fun testKotlinSpringPlugin() {50 Project("allOpenSpring").build("build") {51 assertSuccessful()52 val classesDir = File(project.projectDir, kotlinClassesDir())53 val openClass = File(classesDir, "test/OpenClass.class")54 val closedClass = File(classesDir, "test/ClosedClass.class")55 assertTrue(openClass.exists())56 assertTrue(closedClass.exists())57 checkBytecodeContains(58 openClass,59 "public class test/OpenClass {",60 "public method()V"61 )62 checkBytecodeContains(63 closedClass,64 "public final class test/ClosedClass {",65 "public final method()V"66 )67 }68 }69 @Test70 fun testKotlinJpaPlugin() {71 Project("noArgJpa").build("build") {72 assertSuccessful()73 val classesDir = File(project.projectDir, kotlinClassesDir())74 fun checkClass(name: String) {75 val testClass = File(classesDir, "test/$name.class")76 assertTrue(testClass.exists())77 checkBytecodeContains(testClass, "public <init>()V")...
AppNavigationTest.kt
Source:AppNavigationTest.kt
...52 @Test53 fun clickOnStatisticsNavigationItem_ShowsStatisticsScreen() {54 // Open Drawer to click on navigation.55 onView(withId(R.id.drawer_layout))56 .check(matches(isClosed(Gravity.START))) // Left Drawer should be closed.57 .perform(open()) // Open Drawer58 // Start statistics screen.59 onView(withId(R.id.nav_view)).perform(navigateTo(R.id.statistics_navigation_menu_item))60 // Check that statistics Activity was opened.61 onView(withId(R.id.statistics)).check(matches(isDisplayed()))62 }63 @Test64 fun clickOnListNavigationItem_ShowsListScreen() {65 // Open Drawer to click on navigation.66 onView(withId(R.id.drawer_layout))67 .check(matches(isClosed(Gravity.START))) // Left Drawer should be closed.68 .perform(open()) // Open Drawer69 // Start statistics screen.70 onView(withId(R.id.nav_view))71 .perform(navigateTo(R.id.statistics_navigation_menu_item))72 // Open Drawer to click on navigation.73 onView(withId(R.id.drawer_layout))74 .check(matches(isClosed(Gravity.START))) // Left Drawer should be closed.75 .perform(open()) // Open Drawer76 // Start tasks list screen.77 onView(withId(R.id.nav_view))78 .perform(navigateTo(R.id.list_navigation_menu_item))79 // Check that Tasks Activity was opened.80 onView(withId(R.id.tasksContainer)).check(matches(isDisplayed()))81 }82 @Test83 fun clickOnAndroidHomeIcon_OpensNavigation() {84 // Check that left drawer is closed at startup85 onView(withId(R.id.drawer_layout))86 .check(matches(isClosed(Gravity.START))) // Left Drawer should be closed.87 // Open Drawer88 onView(89 withContentDescription(90 activityTestRule.activity91 .getToolbarNavigationContentDescription(R.id.toolbar)92 )93 ).perform(click())94 // Check if drawer is open95 onView(withId(R.id.drawer_layout))96 .check(matches(isOpen(Gravity.START))) // Left drawer is open open.97 }98}...
GamePlayServiceTest.kt
Source:GamePlayServiceTest.kt
1package com.diegohr.ejercicio_bitsa_bitnovo.model2import org.hamcrest.CoreMatchers.`is`3import org.hamcrest.MatcherAssert.assertThat4import org.junit.Test5/**6 * Created by Diego Hernando on 9/6/21.7 */8class GamePlayServiceTest {9 private val castleStatusRepository = CastleStatusRepository(WindowUtils(), 64)10 private val service = GamePlayService(castleStatusRepository)11 private val castleStatusAfterThirdVisitorTestOk = listOf(12 "OPEN","OPEN","LEFT_OPEN","OPEN","OPEN","LEFT_OPEN","OPEN","OPEN",13 "LEFT_OPEN","OPEN","OPEN","LEFT_OPEN","OPEN","OPEN","LEFT_OPEN","OPEN",14 "OPEN","LEFT_OPEN","OPEN","OPEN","LEFT_OPEN","OPEN","OPEN","LEFT_OPEN",15 "OPEN","OPEN","LEFT_OPEN","OPEN","OPEN","LEFT_OPEN","OPEN","OPEN",16 "LEFT_OPEN","OPEN","OPEN","LEFT_OPEN","OPEN","OPEN","LEFT_OPEN","OPEN",17 "OPEN","LEFT_OPEN","OPEN","OPEN","LEFT_OPEN","OPEN","OPEN","LEFT_OPEN",18 "OPEN","OPEN","LEFT_OPEN","OPEN","OPEN","LEFT_OPEN","OPEN","OPEN",19 "LEFT_OPEN","OPEN","OPEN","LEFT_OPEN","OPEN","OPEN","LEFT_OPEN","OPEN"20 ).map { WindowStatus.valueOf(it) }.toTypedArray()21 private val castleStatusAfterFourthVisitorTestOk = listOf(22 "OPEN","OPEN","LEFT_OPEN","RIGHT_OPEN","OPEN","LEFT_OPEN","OPEN","RIGHT_OPEN",23 "LEFT_OPEN","OPEN","OPEN","RIGHT_OPEN","OPEN","OPEN","LEFT_OPEN","RIGHT_OPEN",24 "OPEN","LEFT_OPEN","OPEN","RIGHT_OPEN","LEFT_OPEN","OPEN","OPEN","RIGHT_OPEN",25 "OPEN","OPEN","LEFT_OPEN","RIGHT_OPEN","OPEN","LEFT_OPEN","OPEN","RIGHT_OPEN",26 "LEFT_OPEN","OPEN","OPEN","RIGHT_OPEN","OPEN","OPEN","LEFT_OPEN","RIGHT_OPEN",27 "OPEN","LEFT_OPEN","OPEN","RIGHT_OPEN","LEFT_OPEN","OPEN","OPEN","RIGHT_OPEN",28 "OPEN","OPEN","LEFT_OPEN","RIGHT_OPEN","OPEN","LEFT_OPEN","OPEN","RIGHT_OPEN",29 "LEFT_OPEN","OPEN","OPEN","RIGHT_OPEN","OPEN","OPEN","LEFT_OPEN","RIGHT_OPEN"30 ).map { WindowStatus.valueOf(it) }.toTypedArray()31 private val castleStatusAfterAllGameTestOk = listOf(32 "LEFT_OPEN","LEFT_OPEN","OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED",33 "OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED",34 "OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED",35 "OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED",36 "OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED",37 "OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED",38 "OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED",39 "OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED"40 ).map { WindowStatus.valueOf(it) }.toTypedArray()41 @Test42 fun `check status castle after first visitor play not change anything`(){43 val statusAfterPlay = service.firstPlay(1, castleStatusRepository.initialCastleStatus())44 assertThat(statusAfterPlay, `is`(castleStatusRepository.initialCastleStatus()))45 }46 @Test47 fun `check status castle after second visitor play not change anything`(){48 val statusAfterFirstPlay = service.firstPlay(1, castleStatusRepository.initialCastleStatus())49 val statusAfterSecondPlay = service.firstPlay(2, statusAfterFirstPlay)50 assertThat(statusAfterSecondPlay, `is`(castleStatusRepository.initialCastleStatus()))51 }52 @Test53 fun `check status castle after third visitor`(){54 val statusAfterFirstPlay = service.firstPlay(1, castleStatusRepository.initialCastleStatus())55 val statusAfterSecondPlay = service.firstPlay(2, statusAfterFirstPlay)56 val statusAfterThirdPlay = service.normalPlay(3, statusAfterSecondPlay)57 assertThat(statusAfterThirdPlay, `is`(castleStatusAfterThirdVisitorTestOk))58 }59 @Test60 fun `check status castle after fourth visitor`(){61 val statusAfterFourthPlay = service.normalPlay(4, castleStatusAfterThirdVisitorTestOk)62 assertThat(statusAfterFourthPlay, `is`(castleStatusAfterFourthVisitorTestOk))63 }64 @Test65 fun `check status castle after last visitor`(){66 val statusAfterGame = service.playAllGame()67 assertThat(statusAfterGame, `is`(castleStatusAfterAllGameTestOk))68 }69}...
WindowUtilsTest.kt
Source:WindowUtilsTest.kt
...19 fun `check open left wing in left opened window return left opened window` (){20 assertThat(utils.executeWindowOperation(WindowOperations.OPEN_LEFT, WindowStatus.LEFT_OPEN), `is`(WindowStatus.LEFT_OPEN))21 }22 @Test23 fun `check open left wing in closed window return left opened window` (){24 assertThat(utils.executeWindowOperation(WindowOperations.OPEN_LEFT, WindowStatus.CLOSED), `is`(WindowStatus.LEFT_OPEN))25 }26 @Test27 fun `check open right wing in opened window return opened window` (){28 assertThat(utils.executeWindowOperation(WindowOperations.OPEN_RIGHT, WindowStatus.OPEN), `is`(WindowStatus.OPEN))29 }30 @Test31 fun `check open right wing in left opened window return opened window` (){32 assertThat(utils.executeWindowOperation(WindowOperations.OPEN_RIGHT, WindowStatus.LEFT_OPEN), `is`(WindowStatus.OPEN))33 }34 @Test35 fun `check open right wing in right opened window return right opened window` (){36 assertThat(utils.executeWindowOperation(WindowOperations.OPEN_RIGHT, WindowStatus.RIGHT_OPEN), `is`(WindowStatus.RIGHT_OPEN))37 }38 @Test39 fun `check open right wing in closed window return right opened window` (){40 assertThat(utils.executeWindowOperation(WindowOperations.OPEN_RIGHT, WindowStatus.CLOSED), `is`(WindowStatus.RIGHT_OPEN))41 }42 @Test43 fun `check close right wing in opened window return left opened window` (){44 assertThat(utils.executeWindowOperation(WindowOperations.CLOSE_RIGHT, WindowStatus.OPEN), `is`(WindowStatus.LEFT_OPEN))45 }46 @Test47 fun `check close right wing in left opened window return left opened window` (){48 assertThat(utils.executeWindowOperation(WindowOperations.CLOSE_RIGHT, WindowStatus.LEFT_OPEN), `is`(WindowStatus.LEFT_OPEN))49 }50 @Test51 fun `check close right wing in right opened window return closed window` (){52 assertThat(utils.executeWindowOperation(WindowOperations.CLOSE_RIGHT, WindowStatus.RIGHT_OPEN), `is`(WindowStatus.CLOSED))53 }54 @Test55 fun `check close right wing in closed window return closed window` (){56 assertThat(utils.executeWindowOperation(WindowOperations.CLOSE_RIGHT, WindowStatus.CLOSED), `is`(WindowStatus.CLOSED))57 }58 @Test59 fun `check close left wing in opened window return right opened window` (){60 assertThat(utils.executeWindowOperation(WindowOperations.CLOSE_LEFT, WindowStatus.OPEN), `is`(WindowStatus.RIGHT_OPEN))61 }62 @Test63 fun `check close left wing in left opened window return closed window` (){64 assertThat(utils.executeWindowOperation(WindowOperations.CLOSE_LEFT, WindowStatus.LEFT_OPEN), `is`(WindowStatus.CLOSED))65 }66 @Test67 fun `check close left wing in right opened window return right opened window` (){68 assertThat(utils.executeWindowOperation(WindowOperations.CLOSE_LEFT, WindowStatus.RIGHT_OPEN), `is`(WindowStatus.RIGHT_OPEN))69 }70 @Test71 fun `check close left wing in closed window return closed window` (){72 assertThat(utils.executeWindowOperation(WindowOperations.CLOSE_LEFT, WindowStatus.CLOSED), `is`(WindowStatus.CLOSED))73 }74}...
WinnersFinderServiceTest.kt
Source:WinnersFinderServiceTest.kt
1package com.diegohr.ejercicio_bitsa_bitnovo.model2import org.hamcrest.CoreMatchers.`is`3import org.hamcrest.MatcherAssert.assertThat4import org.junit.Test5/**6 * Created by Diego Hernando on 9/6/21.7 */8class WinnersFinderServiceTest {9 private val service = WinnersFinderService()10 private val castleStatusTest1 = listOf(11 "LEFT_OPEN","LEFT_OPEN","OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED",12 ).map { WindowStatus.valueOf(it) }.toTypedArray()13 private val castleStatusTest2 = listOf(14 "OPEN","LEFT_OPEN","OPEN","CLOSED","OPEN","CLOSED","OPEN","RIGHT_OPEN",15 ).map { WindowStatus.valueOf(it) }.toTypedArray()16 private val castleStatusTest3 = listOf(17 "OPEN","CLOSED","OPEN","CLOSED","OPEN","CLOSED","CLOSED","RIGHT_OPEN",18 ).map { WindowStatus.valueOf(it) }.toTypedArray()19 @Test20 fun `check list of winners of castleStatusTest1` () {21 val winnersTest = listOf(5,7)22 val winners = service.findWinners(castleStatusTest1)23 assertThat(winners, `is`(winnersTest))24 }25 @Test26 fun `check list of second winners of castleStatusTest1` () {27 val winnersTest = listOf(3,5,7)28 val winners = service.findSecondWinners(castleStatusTest1)29 assertThat(winners, `is`(winnersTest))30 }31 @Test32 fun `check list of winners of castleStatusTest2` () {33 val winnersTest = listOf(5)34 val winners = service.findWinners(castleStatusTest2)35 assertThat(winners, `is`(winnersTest))36 }37 @Test38 fun `check list of second winners of castleStatusTest2` () {39 val winnersTest = listOf(1,3,5,7)40 val winners = service.findSecondWinners(castleStatusTest2)41 assertThat(winners, `is`(winnersTest))42 }43 @Test44 fun `check list of winners of castleStatusTest3` () {45 val winnersTest = listOf(1,3,5)46 val winners = service.findWinners(castleStatusTest3)47 assertThat(winners, `is`(winnersTest))48 }49 @Test50 fun `check list of second winners of castleStatusTest3` () {51 val winnersTest = listOf(1,3,5)52 val winners = service.findSecondWinners(castleStatusTest3)53 assertThat(winners, `is`(winnersTest))54 }55}...
MarketClosedAnalyzerTest.kt
Source:MarketClosedAnalyzerTest.kt
...10 @Test11 fun analyze() {12 val openMarket = basicMarket().copy(status = MarketStatus.OPEN)13 val openMarketWithPrices = MarketWithPrices(openMarket, basicContractPrices())14 val closedMarket = basicMarket().copy(status = MarketStatus.CLOSED)15 val closedMarketWithPrices = MarketWithPrices(closedMarket, basicContractPrices())16 val expectedNotification = Notification(17 marketId = openMarket.id,18 contractId = null,19 type = Notification.Type.MARKET_CLOSED20 )21 // Closing an open market - that's what we're looking for!22 assertEquals(23 setOf(expectedNotification),24 MarketClosedAnalyzer.analyze(openMarket, closedMarketWithPrices)25 )26 // Open markets aren't closed27 assertEquals(28 emptySet<Notification>(),29 MarketClosedAnalyzer.analyze(openMarket, openMarketWithPrices)30 )31 assertEquals(32 emptySet<Notification>(),33 MarketClosedAnalyzer.analyze(closedMarket, openMarketWithPrices)34 )35 // Already closed markets don't count36 assertEquals(37 emptySet<Notification>(),38 MarketClosedAnalyzer.analyze(closedMarket, closedMarketWithPrices)39 )40 // If we didn't know the market's state before, we don't declare it closed now41 assertEquals(42 emptySet<Notification>(),43 MarketClosedAnalyzer.analyze(null, openMarketWithPrices)44 )45 assertEquals(46 emptySet<Notification>(),47 MarketClosedAnalyzer.analyze(null, closedMarketWithPrices)48 )49 }50}
closed
Using AI Code Generation
1 test.Open t = new test.Open();2 t.closed();3 }4}5package test;6public class Open {7 private int a=10;8 protected int b=20;9 public int c=30;10 int d=40;11 public void closed(){12 System.out.println("Closed method of test.Open class");13 }14}
closed
Using AI Code Generation
1 test.Open t = new test.Open();2 t.closed();3 }4}5package test;6public class Open {7 private int a=10;8 protected int b=20;9 public int c=30;10 int d=40;11 public void closed(){12 System.out.println("Closed method of test.Open class");13 }14}
closed
Using AI Code Generation
1 }2}3package test;4public class Closed extends test.Open{5 public static void main(String[] args) {6 test.Closed c = new test.Closed();7 c.closed();8 }9}10package test;11public class Open {12 protected void closed() {13 System.out.println("Closed method");14 }15}16package test;17public class Closed extends test.Open{18 public static void main(String[] args) {19 test.Closed c = new test.Closed();20 c.closed();21 }22}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!