mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-25 11:20:47 +01:00
committed by
Greyson Parrelli
parent
56d53f0b6a
commit
a96c8867ae
@@ -1,120 +0,0 @@
|
||||
package org.thoughtcrime.securesms.util.livedata;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestRule;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.thoughtcrime.securesms.util.livedata.LiveDataTestUtil.assertNoValue;
|
||||
import static org.thoughtcrime.securesms.util.livedata.LiveDataTestUtil.observeAndGetOneValue;
|
||||
|
||||
public final class LiveDataUtilTest_skip {
|
||||
|
||||
@Rule
|
||||
public TestRule rule = new LiveDataRule();
|
||||
|
||||
@Test
|
||||
public void skip_no_value() {
|
||||
MutableLiveData<String> liveData = new MutableLiveData<>();
|
||||
|
||||
LiveData<String> skipped = LiveDataUtil.skip(liveData, 0);
|
||||
|
||||
assertNoValue(skipped);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skip_same_value_with_zero_skip() {
|
||||
MutableLiveData<String> liveData = new MutableLiveData<>();
|
||||
|
||||
LiveData<String> skipped = LiveDataUtil.skip(liveData, 0);
|
||||
liveData.setValue("A");
|
||||
|
||||
assertEquals("A", observeAndGetOneValue(skipped));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skip_second_value_with_skip_one() {
|
||||
MutableLiveData<String> liveData = new MutableLiveData<>();
|
||||
TestObserver<String> testObserver = new TestObserver<>();
|
||||
|
||||
LiveData<String> skipped = LiveDataUtil.skip(liveData, 1);
|
||||
|
||||
skipped.observeForever(testObserver);
|
||||
liveData.setValue("A");
|
||||
liveData.setValue("B");
|
||||
skipped.removeObserver(testObserver);
|
||||
|
||||
Assertions.assertThat(testObserver.getValues())
|
||||
.containsExactly("B");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skip_no_value_with_skip() {
|
||||
MutableLiveData<String> liveData = new MutableLiveData<>();
|
||||
|
||||
LiveData<String> skipped = LiveDataUtil.skip(liveData, 1);
|
||||
liveData.setValue("A");
|
||||
|
||||
assertNoValue(skipped);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skip_third_and_fourth_value_with_skip_two() {
|
||||
MutableLiveData<String> liveData = new MutableLiveData<>();
|
||||
TestObserver<String> testObserver = new TestObserver<>();
|
||||
|
||||
LiveData<String> skipped = LiveDataUtil.skip(liveData, 2);
|
||||
|
||||
skipped.observeForever(testObserver);
|
||||
liveData.setValue("A");
|
||||
liveData.setValue("B");
|
||||
liveData.setValue("C");
|
||||
liveData.setValue("D");
|
||||
skipped.removeObserver(testObserver);
|
||||
|
||||
Assertions.assertThat(testObserver.getValues())
|
||||
.containsExactly("C", "D");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skip_set_one_before_then_skip() {
|
||||
MutableLiveData<String> liveData = new MutableLiveData<>();
|
||||
TestObserver<String> testObserver = new TestObserver<>();
|
||||
|
||||
liveData.setValue("A");
|
||||
|
||||
LiveData<String> skipped = LiveDataUtil.skip(liveData, 2);
|
||||
|
||||
skipped.observeForever(testObserver);
|
||||
liveData.setValue("B");
|
||||
liveData.setValue("C");
|
||||
liveData.setValue("D");
|
||||
skipped.removeObserver(testObserver);
|
||||
|
||||
Assertions.assertThat(testObserver.getValues())
|
||||
.containsExactly("C", "D");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void skip_set_two_before_then_skip() {
|
||||
MutableLiveData<String> liveData = new MutableLiveData<>();
|
||||
TestObserver<String> testObserver = new TestObserver<>();
|
||||
|
||||
liveData.setValue("A");
|
||||
liveData.setValue("B");
|
||||
|
||||
LiveData<String> skipped = LiveDataUtil.skip(liveData, 2);
|
||||
|
||||
skipped.observeForever(testObserver);
|
||||
liveData.setValue("C");
|
||||
liveData.setValue("D");
|
||||
skipped.removeObserver(testObserver);
|
||||
|
||||
Assertions.assertThat(testObserver.getValues())
|
||||
.containsExactly("D");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package org.thoughtcrime.securesms.util.livedata
|
||||
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.containsExactlyInAnyOrder
|
||||
import assertk.assertions.isEqualTo
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TestRule
|
||||
|
||||
@Suppress("ClassName")
|
||||
class LiveDataUtilTest_skip {
|
||||
@get:Rule
|
||||
val rule: TestRule = LiveDataRule()
|
||||
|
||||
@Test
|
||||
fun skip_no_value() {
|
||||
val liveData = MutableLiveData<String>()
|
||||
|
||||
val skipped = LiveDataUtil.skip(liveData, 0)
|
||||
|
||||
LiveDataTestUtil.assertNoValue(skipped)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun skip_same_value_with_zero_skip() {
|
||||
val liveData = MutableLiveData<String>()
|
||||
|
||||
val skipped = LiveDataUtil.skip(liveData, 0)
|
||||
liveData.value = "A"
|
||||
|
||||
assertThat(LiveDataTestUtil.observeAndGetOneValue(skipped)).isEqualTo("A")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun skip_second_value_with_skip_one() {
|
||||
val liveData = MutableLiveData<String>()
|
||||
val testObserver = TestObserver<String>()
|
||||
|
||||
val skipped = LiveDataUtil.skip(liveData, 1)
|
||||
|
||||
skipped.observeForever(testObserver)
|
||||
liveData.value = "A"
|
||||
liveData.value = "B"
|
||||
skipped.removeObserver(testObserver)
|
||||
|
||||
assertThat(testObserver.values).containsExactlyInAnyOrder("B")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun skip_no_value_with_skip() {
|
||||
val liveData = MutableLiveData<String>()
|
||||
|
||||
val skipped = LiveDataUtil.skip(liveData, 1)
|
||||
liveData.value = "A"
|
||||
|
||||
LiveDataTestUtil.assertNoValue(skipped)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun skip_third_and_fourth_value_with_skip_two() {
|
||||
val liveData = MutableLiveData<String>()
|
||||
val testObserver = TestObserver<String>()
|
||||
|
||||
val skipped = LiveDataUtil.skip(liveData, 2)
|
||||
|
||||
skipped.observeForever(testObserver)
|
||||
liveData.value = "A"
|
||||
liveData.value = "B"
|
||||
liveData.value = "C"
|
||||
liveData.value = "D"
|
||||
skipped.removeObserver(testObserver)
|
||||
|
||||
assertThat(testObserver.values).containsExactlyInAnyOrder("C", "D")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun skip_set_one_before_then_skip() {
|
||||
val liveData = MutableLiveData<String>()
|
||||
val testObserver = TestObserver<String>()
|
||||
|
||||
liveData.value = "A"
|
||||
|
||||
val skipped = LiveDataUtil.skip(liveData, 2)
|
||||
|
||||
skipped.observeForever(testObserver)
|
||||
liveData.value = "B"
|
||||
liveData.value = "C"
|
||||
liveData.value = "D"
|
||||
skipped.removeObserver(testObserver)
|
||||
|
||||
assertThat(testObserver.values).containsExactlyInAnyOrder("C", "D")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun skip_set_two_before_then_skip() {
|
||||
val liveData = MutableLiveData<String>()
|
||||
val testObserver = TestObserver<String>()
|
||||
|
||||
liveData.value = "A"
|
||||
liveData.value = "B"
|
||||
|
||||
val skipped = LiveDataUtil.skip(liveData, 2)
|
||||
|
||||
skipped.observeForever(testObserver)
|
||||
liveData.value = "C"
|
||||
liveData.value = "D"
|
||||
skipped.removeObserver(testObserver)
|
||||
|
||||
assertThat(testObserver.values).containsExactlyInAnyOrder("D")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user