Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
dmdevgo committed Oct 5, 2018
2 parents 9de9dd2 + 41621a9 commit 91ec3df
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 30 deletions.
2 changes: 1 addition & 1 deletion rxpm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ext {
bintrayName = 'RxPM'
publishedGroupId = 'me.dmdev.rxpm'
artifact = 'rxpm'
libraryVersion = '1.2.2'
libraryVersion = '1.2.3'
gitUrl = 'https://github.com/dmdevgo/RxPM'
allLicenses = ['MIT']
}
Expand Down
2 changes: 0 additions & 2 deletions rxpm/src/main/kotlin/me/dmdev/rxpm/PmExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,4 @@ inline fun <T> Observable<T>.bufferWhileIdle(
.flatMapIterable { it }

)
.publish()
.refCount()
}
2 changes: 2 additions & 0 deletions rxpm/src/main/kotlin/me/dmdev/rxpm/PresentationModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ abstract class PresentationModel {
relay.bufferWhileIdle(isIdle, bufferSize)
}
}
.publish()
.apply { connect() }
}

}
Expand Down
73 changes: 46 additions & 27 deletions rxpm/src/test/kotlin/me/dmdev/rxpm/PresentationModelTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package me.dmdev.rxpm

import com.jakewharton.rxrelay2.PublishRelay
import com.nhaarman.mockitokotlin2.mock
import com.nhaarman.mockitokotlin2.spy
import com.nhaarman.mockitokotlin2.verify
Expand Down Expand Up @@ -76,86 +75,106 @@ class PresentationModelTest {
assertEquals(DESTROYED, pm.currentLifecycleState)
}

@Test fun bufferWhileUnbindBlockItemsBeforeCreated() {
val testObserver = pm.commands.test()
@Test fun commandBlocksItemsBeforeCreated() {
val testObserver = pm.commands.observable.test()

pm.relay.accept(1)
pm.acceptCommand(1)

testObserver.assertEmpty()
}

@Test fun bufferWhileUnbindBlockItemsBeforeBinded() {
val testObserver = pm.commands.test()
@Test fun commandBlocksItemsBeforeBinded() {
val testObserver = pm.commands.observable.test()

pm.lifecycleConsumer.accept(CREATED)
pm.relay.accept(1)
pm.acceptCommand(1)

testObserver.assertEmpty()
}

@Test fun bufferWhileUnbindReceiveItemsWhenBinded() {
val testObserver = pm.commands.test()
@Test fun commandPassItemsWhenBinded() {
val testObserver = pm.commands.observable.test()

pm.lifecycleConsumer.accept(CREATED)
pm.lifecycleConsumer.accept(BINDED)
pm.relay.accept(1)
pm.relay.accept(2)
pm.acceptCommand(1)
pm.acceptCommand(2)

testObserver.assertValuesOnly(1, 2)
}

@Test fun bufferWhileUnbindPassItemsAfterBinded() {
val testObserver = pm.commands.test()
@Test fun commandSendsBufferedItemsAfterBinded() {
val testObserver = pm.commands.observable.test()

pm.relay.accept(1)
pm.acceptCommand(1)
pm.lifecycleConsumer.accept(CREATED)
pm.relay.accept(2)
pm.acceptCommand(2)
pm.lifecycleConsumer.accept(BINDED)

testObserver.assertValuesOnly(1, 2)
}

@Test fun bufferWhileUnbindBlockItemsAfterUnbinded() {
val testObserver = pm.commands.test()
@Test fun commandBlocksItemsAfterUnbinded() {
val testObserver = pm.commands.observable.test()

pm.lifecycleConsumer.accept(CREATED)
pm.lifecycleConsumer.accept(BINDED)
pm.lifecycleConsumer.accept(UNBINDED)
pm.relay.accept(1)
pm.acceptCommand(1)

testObserver.assertEmpty()
}

@Test fun bufferWhileUnbindPassItemsAfterBindedAgain() {
val testObserver = pm.commands.test()
@Test fun commandSendsBufferedItemsAfterBindedAgain() {
val testObserver = pm.commands.observable.test()

pm.lifecycleConsumer.accept(CREATED)
pm.lifecycleConsumer.accept(BINDED)
pm.lifecycleConsumer.accept(UNBINDED)
pm.relay.accept(1)
pm.relay.accept(2)
pm.acceptCommand(1)
pm.acceptCommand(2)
pm.lifecycleConsumer.accept(BINDED)

testObserver.assertValuesOnly(1, 2)
}

@Test fun bufferWhileUnbindBlockItemsAfterDestroyed() {
val testObserver = pm.commands.test()
@Test fun commandBlocksItemsAfterDestroyed() {
val testObserver = pm.commands.observable.test()

pm.lifecycleConsumer.accept(CREATED)
pm.lifecycleConsumer.accept(BINDED)
pm.lifecycleConsumer.accept(UNBINDED)
pm.lifecycleConsumer.accept(DESTROYED)
pm.relay.accept(1)
pm.acceptCommand(1)

testObserver.assertEmpty()
}

@Test fun commandSendsBufferedItemsAfterResubscribedAndBindedAgain() {
val testObserver = pm.commands.observable.test()

pm.lifecycleConsumer.accept(CREATED)
pm.lifecycleConsumer.accept(BINDED)
pm.lifecycleConsumer.accept(UNBINDED)
testObserver.dispose()

pm.acceptCommand(1)

val testObserver2 = pm.commands.observable.test()
pm.lifecycleConsumer.accept(BINDED)

testObserver.assertEmpty()
testObserver2.assertValuesOnly(1)
}
}

open class TestPm(private val callbacks: LifecycleCallbacks) : PresentationModel() {

val relay = PublishRelay.create<Int>()
val commands = relay.bufferWhileUnbind()
val commands = Command<Int>()

fun acceptCommand(i : Int) {
commands.consumer.accept(i)
}

override fun onCreate() {
callbacks.onCreate()
Expand Down

0 comments on commit 91ec3df

Please sign in to comment.