Skip to content

Commit 62dc428

Browse files
authored
Merge pull request #403 from LachlanMcKee/fix-backstack-byte-code
Fix backstack JDK 17 byte code
2 parents c4abb51 + 2367fc1 commit 62dc428

File tree

4 files changed

+153
-105
lines changed

4 files changed

+153
-105
lines changed

Diff for: gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
1414
org.gradle.caching=true
1515
org.gradle.parallel=true
1616

17-
VERSION_NAME=0.40.3
17+
VERSION_NAME=0.40.4
1818

1919
android.useAndroidX=true
2020
android.defaults.buildfeatures.buildconfig=true

Diff for: libraries/rib-base/src/main/java/com/badoo/ribs/routing/source/backstack/BackStack.kt

+13-5
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import android.os.Parcelable
55
import com.badoo.ribs.core.modality.BuildParams
66
import com.badoo.ribs.minimal.reactive.Cancellable
77
import com.badoo.ribs.minimal.reactive.Source
8+
import com.badoo.ribs.minimal.reactive.map
89
import com.badoo.ribs.minimal.state.Store
910
import com.badoo.ribs.minimal.state.TimeCapsule
10-
import com.badoo.ribs.minimal.reactive.map
1111
import com.badoo.ribs.routing.Routing
1212
import com.badoo.ribs.routing.history.RoutingHistory
1313
import com.badoo.ribs.routing.history.RoutingHistoryElement
@@ -72,7 +72,9 @@ class BackStack<C : Parcelable> internal constructor(
7272
override fun baseLineState(fromRestored: Boolean): RoutingHistory<C> =
7373
timeCapsule.initialState()
7474

75-
private val store = object : Store<State<C>>(timeCapsule.initialState()) {
75+
private val store = BackStackStore()
76+
77+
private inner class BackStackStore : Store<State<C>>(timeCapsule.initialState()) {
7678
init {
7779
timeCapsule.register(timeCapsuleKey) { state }
7880
initializeBackstack()
@@ -114,15 +116,21 @@ class BackStack<C : Parcelable> internal constructor(
114116
)
115117
}
116118

117-
private fun routingWithCorrectId(element: RoutingHistoryElement<C>, index: Int): Routing<C> =
119+
private fun routingWithCorrectId(
120+
element: RoutingHistoryElement<C>,
121+
index: Int
122+
): Routing<C> =
118123
element.routing.copy(
119124
identifier = state.contentIdForPosition(
120125
index,
121126
element.routing.configuration
122127
)
123128
)
124129

125-
private fun overlaysWithCorrectId(element: RoutingHistoryElement<C>, index: Int): List<Routing<C>> =
130+
private fun overlaysWithCorrectId(
131+
element: RoutingHistoryElement<C>,
132+
index: Int
133+
): List<Routing<C>> =
126134
element.overlays.mapIndexed { overlayIndex, overlay ->
127135
overlay.copy(
128136
identifier = state.overlayIdForPosition(
@@ -144,7 +152,7 @@ class BackStack<C : Parcelable> internal constructor(
144152
}
145153

146154
val activeConfiguration: C
147-
get()= state.elements
155+
get() = state.elements
148156
.last()
149157
.routing
150158
.configuration
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,67 @@
11
package com.badoo.ribs.example.root
22

3-
// TODO: Uncomment once Mockito issues with BackStack are fixed.
4-
// This blocked the update to AGP 8.2.2
5-
//@ExtendWith(RxSchedulerExtension::class)
6-
//class RootInteractorAuthStateTest {
7-
//
8-
// private val backStack: BackStack<Configuration> = mock()
9-
//
10-
// private val stateRelay = PublishRelay.create<AuthState>()
11-
// private val authDataSource = mock<AuthDataSource>().apply {
12-
// whenever(authUpdates).thenReturn(stateRelay)
13-
// }
14-
// private lateinit var interactor: RootInteractor
15-
// private lateinit var interactorTestHelper: InteractorTestHelper<Nothing>
16-
//
17-
// @BeforeEach
18-
// fun setup() {
19-
// interactor = RootInteractor(
20-
// buildParams = emptyBuildParams(),
21-
// backStack = backStack,
22-
// authDataSource = authDataSource,
23-
// networkErrors = PublishRelay.create()
24-
// )
25-
// interactorTestHelper = InteractorTestHelper(interactor)
26-
// }
27-
//
28-
// @ParameterizedTest
29-
// @MethodSource("data")
30-
// fun `an example test with some conditions should pass`(
31-
// authState: AuthState,
32-
// expectedConfiguration: Configuration
33-
// ) {
34-
// interactorTestHelper.moveToStateAndCheck(Lifecycle.State.CREATED) {
35-
// stateRelay.accept(authState)
36-
//
37-
// verify(backStack).replace(expectedConfiguration)
38-
// }
39-
// }
40-
//
41-
// companion object {
42-
// @JvmStatic
43-
// fun data(): Stream<Arguments> = Stream.of(
44-
// Arguments.of(AuthState.Unauthenticated, Configuration.Content.LoggedOut),
45-
// Arguments.of(AuthState.Anonymous, Configuration.Content.LoggedIn),
46-
// Arguments.of(AuthState.Authenticated(""), Configuration.Content.LoggedIn)
47-
// )
48-
// }
49-
//}
3+
import androidx.lifecycle.Lifecycle
4+
import com.badoo.ribs.example.RxSchedulerExtension
5+
import com.badoo.ribs.example.auth.AuthDataSource
6+
import com.badoo.ribs.example.auth.AuthState
7+
import com.badoo.ribs.example.root.routing.RootRouter.Configuration
8+
import com.badoo.ribs.routing.source.backstack.BackStack
9+
import com.badoo.ribs.routing.source.backstack.operation.replace
10+
import com.badoo.ribs.test.InteractorTestHelper
11+
import com.badoo.ribs.test.emptyBuildParams
12+
import com.jakewharton.rxrelay2.PublishRelay
13+
import org.junit.jupiter.api.BeforeEach
14+
import org.junit.jupiter.api.extension.ExtendWith
15+
import org.junit.jupiter.params.ParameterizedTest
16+
import org.junit.jupiter.params.provider.Arguments
17+
import org.junit.jupiter.params.provider.MethodSource
18+
import org.mockito.kotlin.mock
19+
import org.mockito.kotlin.verify
20+
import org.mockito.kotlin.whenever
21+
import java.util.stream.Stream
22+
23+
@ExtendWith(RxSchedulerExtension::class)
24+
class RootInteractorAuthStateTest {
25+
26+
private val backStack: BackStack<Configuration> = mock()
27+
28+
private val stateRelay = PublishRelay.create<AuthState>()
29+
private val authDataSource = mock<AuthDataSource>().apply {
30+
whenever(authUpdates).thenReturn(stateRelay)
31+
}
32+
private lateinit var interactor: RootInteractor
33+
private lateinit var interactorTestHelper: InteractorTestHelper<Nothing>
34+
35+
@BeforeEach
36+
fun setup() {
37+
interactor = RootInteractor(
38+
buildParams = emptyBuildParams(),
39+
backStack = backStack,
40+
authDataSource = authDataSource,
41+
networkErrors = PublishRelay.create()
42+
)
43+
interactorTestHelper = InteractorTestHelper(interactor)
44+
}
45+
46+
@ParameterizedTest
47+
@MethodSource("data")
48+
fun `an example test with some conditions should pass`(
49+
authState: AuthState,
50+
expectedConfiguration: Configuration
51+
) {
52+
interactorTestHelper.moveToStateAndCheck(Lifecycle.State.CREATED) {
53+
stateRelay.accept(authState)
54+
55+
verify(backStack).replace(expectedConfiguration)
56+
}
57+
}
58+
59+
companion object {
60+
@JvmStatic
61+
fun data(): Stream<Arguments> = Stream.of(
62+
Arguments.of(AuthState.Unauthenticated, Configuration.Content.LoggedOut),
63+
Arguments.of(AuthState.Anonymous, Configuration.Content.LoggedIn),
64+
Arguments.of(AuthState.Authenticated(""), Configuration.Content.LoggedIn)
65+
)
66+
}
67+
}
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,76 @@
11
package com.badoo.ribs.sandbox.rib.switcher
22

3-
// TODO: Uncomment once Mockito issues with BackStack are fixed.
4-
// This blocked the update to AGP 8.2.2
5-
//@RunWith(RobolectricTestRunner::class)
6-
//class SwitcherInteractorTest {
7-
//
8-
// private val backStack: BackStack<Configuration> = mock()
9-
// private val dialogToTestOverlay: DialogToTestOverlay = mock()
10-
//
11-
// private val viewEventRelay = PublishRelay.create<Event>()
12-
// private lateinit var interactor: SwitcherInteractor
13-
// private lateinit var interactorTestHelper: InteractorTestHelper<SwitcherView>
14-
//
15-
// @Before
16-
// fun setup() {
17-
// interactor = SwitcherInteractor(
18-
// buildParams = emptyBuildParams(),
19-
// backStack = backStack,
20-
// dialogToTestOverlay = dialogToTestOverlay,
21-
// transitions = Observable.just(SETTLED),
22-
// transitionSettled = { true }
23-
// )
24-
//
25-
// interactorTestHelper = createInteractorTestHelper(interactor, viewEventRelay)
26-
// }
27-
//
28-
// @Test
29-
// fun `router open overlay dialog when show overlay dialog clicked`(){
30-
// interactorTestHelper.moveToStateAndCheck(STARTED) {
31-
// viewEventRelay.accept(Event.ShowOverlayDialogClicked)
32-
//
33-
// verify(backStack).pushOverlay(Overlay.Dialog)
34-
// }
35-
// }
36-
//
37-
// @Test
38-
// fun `router open blocker when show blocker clicked`(){
39-
// interactorTestHelper.moveToStateAndCheck(STARTED) {
40-
// viewEventRelay.accept(Event.ShowBlockerClicked)
41-
//
42-
// verify(backStack).push(Content.Blocker)
43-
// }
44-
// }
45-
//
46-
// @Test
47-
// fun `skip view event when view not resumed`(){
48-
// interactorTestHelper.moveToStateAndCheck(CREATED) {
49-
// viewEventRelay.accept(Event.ShowBlockerClicked)
50-
//
51-
// verify(backStack, never()).push(Content.Blocker)
52-
// }
53-
// }
54-
//}
3+
import androidx.lifecycle.Lifecycle.State.CREATED
4+
import androidx.lifecycle.Lifecycle.State.STARTED
5+
import com.badoo.common.ribs.rx2.createInteractorTestHelper
6+
import com.badoo.ribs.routing.router.Router.TransitionState.SETTLED
7+
import com.badoo.ribs.routing.source.backstack.BackStack
8+
import com.badoo.ribs.routing.source.backstack.operation.push
9+
import com.badoo.ribs.routing.source.backstack.operation.pushOverlay
10+
import com.badoo.ribs.sandbox.rib.switcher.SwitcherView.Event
11+
import com.badoo.ribs.sandbox.rib.switcher.dialog.DialogToTestOverlay
12+
import com.badoo.ribs.sandbox.rib.switcher.routing.SwitcherRouter.Configuration
13+
import com.badoo.ribs.sandbox.rib.switcher.routing.SwitcherRouter.Configuration.Content
14+
import com.badoo.ribs.sandbox.rib.switcher.routing.SwitcherRouter.Configuration.Overlay
15+
import com.badoo.ribs.test.InteractorTestHelper
16+
import com.badoo.ribs.test.emptyBuildParams
17+
import com.jakewharton.rxrelay2.PublishRelay
18+
import io.reactivex.Observable
19+
import org.junit.Before
20+
import org.junit.Test
21+
import org.junit.runner.RunWith
22+
import org.mockito.kotlin.mock
23+
import org.mockito.kotlin.never
24+
import org.mockito.kotlin.verify
25+
import org.robolectric.RobolectricTestRunner
26+
27+
@RunWith(RobolectricTestRunner::class)
28+
class SwitcherInteractorTest {
29+
30+
private val backStack: BackStack<Configuration> = mock()
31+
private val dialogToTestOverlay: DialogToTestOverlay = mock()
32+
33+
private val viewEventRelay = PublishRelay.create<Event>()
34+
private lateinit var interactor: SwitcherInteractor
35+
private lateinit var interactorTestHelper: InteractorTestHelper<SwitcherView>
36+
37+
@Before
38+
fun setup() {
39+
interactor = SwitcherInteractor(
40+
buildParams = emptyBuildParams(),
41+
backStack = backStack,
42+
dialogToTestOverlay = dialogToTestOverlay,
43+
transitions = Observable.just(SETTLED),
44+
transitionSettled = { true }
45+
)
46+
47+
interactorTestHelper = createInteractorTestHelper(interactor, viewEventRelay)
48+
}
49+
50+
@Test
51+
fun `router open overlay dialog when show overlay dialog clicked`() {
52+
interactorTestHelper.moveToStateAndCheck(STARTED) {
53+
viewEventRelay.accept(Event.ShowOverlayDialogClicked)
54+
55+
verify(backStack).pushOverlay(Overlay.Dialog)
56+
}
57+
}
58+
59+
@Test
60+
fun `router open blocker when show blocker clicked`() {
61+
interactorTestHelper.moveToStateAndCheck(STARTED) {
62+
viewEventRelay.accept(Event.ShowBlockerClicked)
63+
64+
verify(backStack).push(Content.Blocker)
65+
}
66+
}
67+
68+
@Test
69+
fun `skip view event when view not resumed`() {
70+
interactorTestHelper.moveToStateAndCheck(CREATED) {
71+
viewEventRelay.accept(Event.ShowBlockerClicked)
72+
73+
verify(backStack, never()).push(Content.Blocker)
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)