mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-25 19:29:54 +01:00
Live group update messages on conversation list and conversation.
This commit is contained in:
committed by
Greyson Parrelli
parent
7446c2096d
commit
bd1c164d57
@@ -14,7 +14,7 @@ public final class LiveDataTestUtil {
|
||||
* <p>
|
||||
* This will therefore only work in conjunction with {@link LiveDataRule}.
|
||||
*/
|
||||
public static <T> T getValue(final LiveData<T> liveData) {
|
||||
public static <T> T observeAndGetOneValue(final LiveData<T> liveData) {
|
||||
AtomicReference<T> data = new AtomicReference<>();
|
||||
Observer<T> observer = data::set;
|
||||
|
||||
|
||||
@@ -10,9 +10,9 @@ import org.thoughtcrime.securesms.util.DefaultValueLiveData;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.thoughtcrime.securesms.util.livedata.LiveDataTestUtil.assertNoValue;
|
||||
import static org.thoughtcrime.securesms.util.livedata.LiveDataTestUtil.getValue;
|
||||
import static org.thoughtcrime.securesms.util.livedata.LiveDataTestUtil.observeAndGetOneValue;
|
||||
|
||||
public final class LiveDataUtilTest {
|
||||
public final class LiveDataUtilTest_combineLatest {
|
||||
|
||||
@Rule
|
||||
public TestRule rule = new LiveDataRule();
|
||||
@@ -61,7 +61,7 @@ public final class LiveDataUtilTest {
|
||||
liveDataA.setValue("Hello, ");
|
||||
liveDataB.setValue("World!");
|
||||
|
||||
assertEquals("Hello, World!", getValue(combined));
|
||||
assertEquals("Hello, World!", observeAndGetOneValue(combined));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -74,10 +74,10 @@ public final class LiveDataUtilTest {
|
||||
liveDataA.setValue("Hello, ");
|
||||
liveDataB.setValue("World!");
|
||||
|
||||
assertEquals("Hello, World!", getValue(combined));
|
||||
assertEquals("Hello, World!", observeAndGetOneValue(combined));
|
||||
|
||||
liveDataA.setValue("Welcome, ");
|
||||
assertEquals("Welcome, World!", getValue(combined));
|
||||
assertEquals("Welcome, World!", observeAndGetOneValue(combined));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,10 +90,10 @@ public final class LiveDataUtilTest {
|
||||
liveDataA.setValue("Hello, ");
|
||||
liveDataB.setValue("World!");
|
||||
|
||||
assertEquals("Hello, World!", getValue(combined));
|
||||
assertEquals("Hello, World!", observeAndGetOneValue(combined));
|
||||
|
||||
liveDataB.setValue("Joe!");
|
||||
assertEquals("Hello, Joe!", getValue(combined));
|
||||
assertEquals("Hello, Joe!", observeAndGetOneValue(combined));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -104,7 +104,7 @@ public final class LiveDataUtilTest {
|
||||
|
||||
liveDataA.setValue("Echo! ");
|
||||
|
||||
assertEquals("Echo! Echo! ", getValue(combined));
|
||||
assertEquals("Echo! Echo! ", observeAndGetOneValue(combined));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,7 +118,7 @@ public final class LiveDataUtilTest {
|
||||
|
||||
liveDataB.setValue("World!");
|
||||
|
||||
assertEquals("Hello, World!", getValue(combined));
|
||||
assertEquals("Hello, World!", observeAndGetOneValue(combined));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,6 +128,6 @@ public final class LiveDataUtilTest {
|
||||
|
||||
LiveData<Integer> combined = LiveDataUtil.combineLatest(liveDataA, liveDataB, (a, b) -> a * b);
|
||||
|
||||
assertEquals(Integer.valueOf(300), getValue(combined));
|
||||
assertEquals(Integer.valueOf(300), observeAndGetOneValue(combined));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
package org.thoughtcrime.securesms.util.livedata;
|
||||
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TestRule;
|
||||
import org.thoughtcrime.securesms.util.DefaultValueLiveData;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.thoughtcrime.securesms.util.livedata.LiveDataTestUtil.assertNoValue;
|
||||
import static org.thoughtcrime.securesms.util.livedata.LiveDataTestUtil.observeAndGetOneValue;
|
||||
|
||||
public final class LiveDataUtilTest_merge {
|
||||
|
||||
@Rule
|
||||
public TestRule rule = new LiveDataRule();
|
||||
|
||||
@Test
|
||||
public void merge_nothing() {
|
||||
LiveData<String> combined = LiveDataUtil.merge(Collections.emptyList());
|
||||
|
||||
assertNoValue(combined);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void merge_one_is_a_no_op() {
|
||||
MutableLiveData<String> liveDataA = new MutableLiveData<>();
|
||||
|
||||
LiveData<String> combined = LiveDataUtil.merge(Collections.singletonList(liveDataA));
|
||||
|
||||
assertSame(liveDataA, combined);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void initially_no_value() {
|
||||
MutableLiveData<String> liveDataA = new MutableLiveData<>();
|
||||
MutableLiveData<String> liveDataB = new MutableLiveData<>();
|
||||
|
||||
LiveData<String> combined = LiveDataUtil.merge(Arrays.asList(liveDataA, liveDataB));
|
||||
|
||||
assertNoValue(combined);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void value_on_first() {
|
||||
MutableLiveData<String> liveDataA = new MutableLiveData<>();
|
||||
MutableLiveData<String> liveDataB = new MutableLiveData<>();
|
||||
|
||||
LiveData<String> combined = LiveDataUtil.merge(Arrays.asList(liveDataA, liveDataB));
|
||||
|
||||
liveDataA.setValue("A");
|
||||
|
||||
assertEquals("A", observeAndGetOneValue(combined));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void value_on_second() {
|
||||
MutableLiveData<String> liveDataA = new MutableLiveData<>();
|
||||
MutableLiveData<String> liveDataB = new MutableLiveData<>();
|
||||
|
||||
LiveData<String> combined = LiveDataUtil.merge(Arrays.asList(liveDataA, liveDataB));
|
||||
|
||||
liveDataB.setValue("B");
|
||||
|
||||
assertEquals("B", observeAndGetOneValue(combined));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void value_on_third() {
|
||||
MutableLiveData<String> liveDataA = new MutableLiveData<>();
|
||||
MutableLiveData<String> liveDataB = new MutableLiveData<>();
|
||||
MutableLiveData<String> liveDataC = new MutableLiveData<>();
|
||||
|
||||
LiveData<String> combined = LiveDataUtil.merge(Arrays.asList(liveDataA, liveDataB, liveDataC));
|
||||
|
||||
liveDataC.setValue("C");
|
||||
|
||||
assertEquals("C", observeAndGetOneValue(combined));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void several_values_merged() {
|
||||
MutableLiveData<String> liveDataA = new MutableLiveData<>();
|
||||
MutableLiveData<String> liveDataB = new MutableLiveData<>();
|
||||
MutableLiveData<String> liveDataC = new MutableLiveData<>();
|
||||
|
||||
LiveData<String> combined = LiveDataUtil.merge(Arrays.asList(liveDataA, liveDataB, liveDataC));
|
||||
|
||||
liveDataC.setValue("C");
|
||||
|
||||
assertEquals("C", observeAndGetOneValue(combined));
|
||||
|
||||
liveDataA.setValue("A");
|
||||
|
||||
assertEquals("A", observeAndGetOneValue(combined));
|
||||
|
||||
liveDataB.setValue("B");
|
||||
|
||||
assertEquals("B", observeAndGetOneValue(combined));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void combined_same_instance() {
|
||||
MutableLiveData<String> liveDataA = new MutableLiveData<>();
|
||||
|
||||
LiveData<String> combined = LiveDataUtil.merge(Arrays.asList(liveDataA, liveDataA));
|
||||
|
||||
liveDataA.setValue("Echo! ");
|
||||
|
||||
assertSame(liveDataA, combined);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void combined_same_instances_repeated() {
|
||||
MutableLiveData<String> liveDataA = new MutableLiveData<>();
|
||||
MutableLiveData<String> liveDataB = new MutableLiveData<>();
|
||||
MutableLiveData<String> liveDataC = new MutableLiveData<>();
|
||||
|
||||
LiveData<String> combined = LiveDataUtil.merge(Arrays.asList(liveDataA, liveDataB, liveDataC, liveDataA, liveDataB, liveDataC));
|
||||
|
||||
liveDataC.setValue("C");
|
||||
|
||||
assertEquals("C", observeAndGetOneValue(combined));
|
||||
|
||||
liveDataA.setValue("A");
|
||||
|
||||
assertEquals("A", observeAndGetOneValue(combined));
|
||||
|
||||
liveDataB.setValue("B");
|
||||
|
||||
assertEquals("B", observeAndGetOneValue(combined));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void on_a_set_before_combine() {
|
||||
MutableLiveData<String> liveDataA = new MutableLiveData<>();
|
||||
MutableLiveData<String> liveDataB = new MutableLiveData<>();
|
||||
|
||||
liveDataA.setValue("A");
|
||||
|
||||
LiveData<String> combined = LiveDataUtil.merge(Arrays.asList(liveDataA, liveDataB));
|
||||
|
||||
assertEquals("A", observeAndGetOneValue(combined));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void on_default_values() {
|
||||
MutableLiveData<Integer> liveDataA = new DefaultValueLiveData<>(10);
|
||||
MutableLiveData<Integer> liveDataB = new DefaultValueLiveData<>(30);
|
||||
|
||||
LiveData<Integer> combined = LiveDataUtil.merge(Arrays.asList(liveDataA, liveDataB));
|
||||
|
||||
assertEquals(Integer.valueOf(30), observeAndGetOneValue(combined));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user