-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #403 from LachlanMcKee/fix-backstack-byte-code
Fix backstack JDK 17 byte code
- Loading branch information
Showing
4 changed files
with
153 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 65 additions & 47 deletions
112
.../unsplash-client/src/test/java/com/badoo/ribs/example/root/RootInteractorAuthStateTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,67 @@ | ||
package com.badoo.ribs.example.root | ||
|
||
// TODO: Uncomment once Mockito issues with BackStack are fixed. | ||
// This blocked the update to AGP 8.2.2 | ||
//@ExtendWith(RxSchedulerExtension::class) | ||
//class RootInteractorAuthStateTest { | ||
// | ||
// private val backStack: BackStack<Configuration> = mock() | ||
// | ||
// private val stateRelay = PublishRelay.create<AuthState>() | ||
// private val authDataSource = mock<AuthDataSource>().apply { | ||
// whenever(authUpdates).thenReturn(stateRelay) | ||
// } | ||
// private lateinit var interactor: RootInteractor | ||
// private lateinit var interactorTestHelper: InteractorTestHelper<Nothing> | ||
// | ||
// @BeforeEach | ||
// fun setup() { | ||
// interactor = RootInteractor( | ||
// buildParams = emptyBuildParams(), | ||
// backStack = backStack, | ||
// authDataSource = authDataSource, | ||
// networkErrors = PublishRelay.create() | ||
// ) | ||
// interactorTestHelper = InteractorTestHelper(interactor) | ||
// } | ||
// | ||
// @ParameterizedTest | ||
// @MethodSource("data") | ||
// fun `an example test with some conditions should pass`( | ||
// authState: AuthState, | ||
// expectedConfiguration: Configuration | ||
// ) { | ||
// interactorTestHelper.moveToStateAndCheck(Lifecycle.State.CREATED) { | ||
// stateRelay.accept(authState) | ||
// | ||
// verify(backStack).replace(expectedConfiguration) | ||
// } | ||
// } | ||
// | ||
// companion object { | ||
// @JvmStatic | ||
// fun data(): Stream<Arguments> = Stream.of( | ||
// Arguments.of(AuthState.Unauthenticated, Configuration.Content.LoggedOut), | ||
// Arguments.of(AuthState.Anonymous, Configuration.Content.LoggedIn), | ||
// Arguments.of(AuthState.Authenticated(""), Configuration.Content.LoggedIn) | ||
// ) | ||
// } | ||
//} | ||
import androidx.lifecycle.Lifecycle | ||
import com.badoo.ribs.example.RxSchedulerExtension | ||
import com.badoo.ribs.example.auth.AuthDataSource | ||
import com.badoo.ribs.example.auth.AuthState | ||
import com.badoo.ribs.example.root.routing.RootRouter.Configuration | ||
import com.badoo.ribs.routing.source.backstack.BackStack | ||
import com.badoo.ribs.routing.source.backstack.operation.replace | ||
import com.badoo.ribs.test.InteractorTestHelper | ||
import com.badoo.ribs.test.emptyBuildParams | ||
import com.jakewharton.rxrelay2.PublishRelay | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import org.junit.jupiter.params.ParameterizedTest | ||
import org.junit.jupiter.params.provider.Arguments | ||
import org.junit.jupiter.params.provider.MethodSource | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.verify | ||
import org.mockito.kotlin.whenever | ||
import java.util.stream.Stream | ||
|
||
@ExtendWith(RxSchedulerExtension::class) | ||
class RootInteractorAuthStateTest { | ||
|
||
private val backStack: BackStack<Configuration> = mock() | ||
|
||
private val stateRelay = PublishRelay.create<AuthState>() | ||
private val authDataSource = mock<AuthDataSource>().apply { | ||
whenever(authUpdates).thenReturn(stateRelay) | ||
} | ||
private lateinit var interactor: RootInteractor | ||
private lateinit var interactorTestHelper: InteractorTestHelper<Nothing> | ||
|
||
@BeforeEach | ||
fun setup() { | ||
interactor = RootInteractor( | ||
buildParams = emptyBuildParams(), | ||
backStack = backStack, | ||
authDataSource = authDataSource, | ||
networkErrors = PublishRelay.create() | ||
) | ||
interactorTestHelper = InteractorTestHelper(interactor) | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("data") | ||
fun `an example test with some conditions should pass`( | ||
authState: AuthState, | ||
expectedConfiguration: Configuration | ||
) { | ||
interactorTestHelper.moveToStateAndCheck(Lifecycle.State.CREATED) { | ||
stateRelay.accept(authState) | ||
|
||
verify(backStack).replace(expectedConfiguration) | ||
} | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
fun data(): Stream<Arguments> = Stream.of( | ||
Arguments.of(AuthState.Unauthenticated, Configuration.Content.LoggedOut), | ||
Arguments.of(AuthState.Anonymous, Configuration.Content.LoggedIn), | ||
Arguments.of(AuthState.Authenticated(""), Configuration.Content.LoggedIn) | ||
) | ||
} | ||
} |
126 changes: 74 additions & 52 deletions
126
sandbox/src/test/java/com/badoo/ribs/sandbox/rib/switcher/SwitcherInteractorTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,76 @@ | ||
package com.badoo.ribs.sandbox.rib.switcher | ||
|
||
// TODO: Uncomment once Mockito issues with BackStack are fixed. | ||
// This blocked the update to AGP 8.2.2 | ||
//@RunWith(RobolectricTestRunner::class) | ||
//class SwitcherInteractorTest { | ||
// | ||
// private val backStack: BackStack<Configuration> = mock() | ||
// private val dialogToTestOverlay: DialogToTestOverlay = mock() | ||
// | ||
// private val viewEventRelay = PublishRelay.create<Event>() | ||
// private lateinit var interactor: SwitcherInteractor | ||
// private lateinit var interactorTestHelper: InteractorTestHelper<SwitcherView> | ||
// | ||
// @Before | ||
// fun setup() { | ||
// interactor = SwitcherInteractor( | ||
// buildParams = emptyBuildParams(), | ||
// backStack = backStack, | ||
// dialogToTestOverlay = dialogToTestOverlay, | ||
// transitions = Observable.just(SETTLED), | ||
// transitionSettled = { true } | ||
// ) | ||
// | ||
// interactorTestHelper = createInteractorTestHelper(interactor, viewEventRelay) | ||
// } | ||
// | ||
// @Test | ||
// fun `router open overlay dialog when show overlay dialog clicked`(){ | ||
// interactorTestHelper.moveToStateAndCheck(STARTED) { | ||
// viewEventRelay.accept(Event.ShowOverlayDialogClicked) | ||
// | ||
// verify(backStack).pushOverlay(Overlay.Dialog) | ||
// } | ||
// } | ||
// | ||
// @Test | ||
// fun `router open blocker when show blocker clicked`(){ | ||
// interactorTestHelper.moveToStateAndCheck(STARTED) { | ||
// viewEventRelay.accept(Event.ShowBlockerClicked) | ||
// | ||
// verify(backStack).push(Content.Blocker) | ||
// } | ||
// } | ||
// | ||
// @Test | ||
// fun `skip view event when view not resumed`(){ | ||
// interactorTestHelper.moveToStateAndCheck(CREATED) { | ||
// viewEventRelay.accept(Event.ShowBlockerClicked) | ||
// | ||
// verify(backStack, never()).push(Content.Blocker) | ||
// } | ||
// } | ||
//} | ||
import androidx.lifecycle.Lifecycle.State.CREATED | ||
import androidx.lifecycle.Lifecycle.State.STARTED | ||
import com.badoo.common.ribs.rx2.createInteractorTestHelper | ||
import com.badoo.ribs.routing.router.Router.TransitionState.SETTLED | ||
import com.badoo.ribs.routing.source.backstack.BackStack | ||
import com.badoo.ribs.routing.source.backstack.operation.push | ||
import com.badoo.ribs.routing.source.backstack.operation.pushOverlay | ||
import com.badoo.ribs.sandbox.rib.switcher.SwitcherView.Event | ||
import com.badoo.ribs.sandbox.rib.switcher.dialog.DialogToTestOverlay | ||
import com.badoo.ribs.sandbox.rib.switcher.routing.SwitcherRouter.Configuration | ||
import com.badoo.ribs.sandbox.rib.switcher.routing.SwitcherRouter.Configuration.Content | ||
import com.badoo.ribs.sandbox.rib.switcher.routing.SwitcherRouter.Configuration.Overlay | ||
import com.badoo.ribs.test.InteractorTestHelper | ||
import com.badoo.ribs.test.emptyBuildParams | ||
import com.jakewharton.rxrelay2.PublishRelay | ||
import io.reactivex.Observable | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.never | ||
import org.mockito.kotlin.verify | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class SwitcherInteractorTest { | ||
|
||
private val backStack: BackStack<Configuration> = mock() | ||
private val dialogToTestOverlay: DialogToTestOverlay = mock() | ||
|
||
private val viewEventRelay = PublishRelay.create<Event>() | ||
private lateinit var interactor: SwitcherInteractor | ||
private lateinit var interactorTestHelper: InteractorTestHelper<SwitcherView> | ||
|
||
@Before | ||
fun setup() { | ||
interactor = SwitcherInteractor( | ||
buildParams = emptyBuildParams(), | ||
backStack = backStack, | ||
dialogToTestOverlay = dialogToTestOverlay, | ||
transitions = Observable.just(SETTLED), | ||
transitionSettled = { true } | ||
) | ||
|
||
interactorTestHelper = createInteractorTestHelper(interactor, viewEventRelay) | ||
} | ||
|
||
@Test | ||
fun `router open overlay dialog when show overlay dialog clicked`() { | ||
interactorTestHelper.moveToStateAndCheck(STARTED) { | ||
viewEventRelay.accept(Event.ShowOverlayDialogClicked) | ||
|
||
verify(backStack).pushOverlay(Overlay.Dialog) | ||
} | ||
} | ||
|
||
@Test | ||
fun `router open blocker when show blocker clicked`() { | ||
interactorTestHelper.moveToStateAndCheck(STARTED) { | ||
viewEventRelay.accept(Event.ShowBlockerClicked) | ||
|
||
verify(backStack).push(Content.Blocker) | ||
} | ||
} | ||
|
||
@Test | ||
fun `skip view event when view not resumed`() { | ||
interactorTestHelper.moveToStateAndCheck(CREATED) { | ||
viewEventRelay.accept(Event.ShowBlockerClicked) | ||
|
||
verify(backStack, never()).push(Content.Blocker) | ||
} | ||
} | ||
} |