mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-26 03:40:56 +01:00
Strongly type UUIDs as ACIs.
This commit is contained in:
@@ -12,6 +12,7 @@ import org.thoughtcrime.securesms.recipients.RecipientDetails
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.thoughtcrime.securesms.wallpaper.ChatWallpaper
|
||||
import org.whispersystems.libsignal.util.guava.Optional
|
||||
import org.whispersystems.signalservice.api.push.ACI
|
||||
import java.util.UUID
|
||||
import kotlin.random.Random
|
||||
|
||||
@@ -28,7 +29,7 @@ object RecipientDatabaseTestUtils {
|
||||
isSelf: Boolean = false,
|
||||
participants: List<Recipient> = listOf(),
|
||||
recipientId: RecipientId = RecipientId.from(Random.nextLong()),
|
||||
uuid: UUID? = UUID.randomUUID(),
|
||||
aci: ACI? = ACI.from(UUID.randomUUID()),
|
||||
username: String? = null,
|
||||
e164: String? = null,
|
||||
email: String? = null,
|
||||
@@ -89,7 +90,7 @@ object RecipientDatabaseTestUtils {
|
||||
registered,
|
||||
RecipientDatabase.RecipientSettings(
|
||||
recipientId,
|
||||
uuid,
|
||||
aci,
|
||||
username,
|
||||
e164,
|
||||
email,
|
||||
|
||||
@@ -25,13 +25,14 @@ import org.signal.storageservice.protos.groups.local.DecryptedGroupChange;
|
||||
import org.signal.storageservice.protos.groups.local.DecryptedMember;
|
||||
import org.signal.storageservice.protos.groups.local.DecryptedPendingMember;
|
||||
import org.thoughtcrime.securesms.testutil.MainThreadUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.signalservice.api.push.ACI;
|
||||
import org.whispersystems.signalservice.api.util.UuidUtil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.singletonList;
|
||||
@@ -1350,12 +1351,14 @@ public final class GroupsV2UpdateMessageProducerTest {
|
||||
}
|
||||
|
||||
private void assertSingleChangeMentioning(DecryptedGroupChange change, List<UUID> expectedMentions) {
|
||||
List<ACI> expectedMentionAcis = expectedMentions.stream().map(ACI::from).collect(Collectors.toList());
|
||||
|
||||
List<UpdateDescription> changes = producer.describeChanges(null, change);
|
||||
|
||||
assertThat(changes.size(), is(1));
|
||||
|
||||
UpdateDescription description = changes.get(0);
|
||||
assertThat(description.getMentioned(), is(expectedMentions));
|
||||
assertThat(description.getMentioned(), is(expectedMentionAcis));
|
||||
|
||||
if (expectedMentions.isEmpty()) {
|
||||
assertTrue(description.isStringStatic());
|
||||
@@ -1394,8 +1397,8 @@ public final class GroupsV2UpdateMessageProducerTest {
|
||||
}
|
||||
|
||||
private static @NonNull GroupsV2UpdateMessageProducer.DescribeMemberStrategy createDescriber(@NonNull Map<UUID, String> map) {
|
||||
return uuid -> {
|
||||
String name = map.get(uuid);
|
||||
return aci -> {
|
||||
String name = map.get(aci.uuid());
|
||||
assertNotNull(name);
|
||||
return name;
|
||||
};
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.junit.runner.RunWith;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
import org.signal.core.util.ThreadUtil;
|
||||
import org.whispersystems.signalservice.api.push.ACI;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -50,7 +51,7 @@ public final class UpdateDescriptionTest {
|
||||
|
||||
@Test(expected = AssertionError.class)
|
||||
public void stringFactory_cannot_run_on_main_thread() {
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(UUID.randomUUID()), () -> "update", 0);
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), () -> "update", 0);
|
||||
|
||||
setMainThread(true);
|
||||
|
||||
@@ -59,7 +60,7 @@ public final class UpdateDescriptionTest {
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void stringFactory_cannot_call_static_string() {
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(UUID.randomUUID()), () -> "update", 0);
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), () -> "update", 0);
|
||||
|
||||
description.getStaticString();
|
||||
}
|
||||
@@ -73,7 +74,7 @@ public final class UpdateDescriptionTest {
|
||||
return "update";
|
||||
};
|
||||
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(UUID.randomUUID()), stringFactory, 0);
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory, 0);
|
||||
|
||||
assertEquals(0, factoryCalls.get());
|
||||
|
||||
@@ -89,7 +90,7 @@ public final class UpdateDescriptionTest {
|
||||
public void stringFactory_reevaluated_on_every_call() {
|
||||
AtomicInteger factoryCalls = new AtomicInteger();
|
||||
UpdateDescription.StringFactory stringFactory = () -> "call" + factoryCalls.incrementAndGet();
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(UUID.randomUUID()), stringFactory, 0);
|
||||
UpdateDescription description = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory, 0);
|
||||
|
||||
setMainThread(false);
|
||||
|
||||
@@ -125,8 +126,8 @@ public final class UpdateDescriptionTest {
|
||||
AtomicInteger factoryCalls2 = new AtomicInteger();
|
||||
UpdateDescription.StringFactory stringFactory1 = () -> "update." + factoryCalls1.incrementAndGet();
|
||||
UpdateDescription.StringFactory stringFactory2 = () -> "update." + factoryCalls2.incrementAndGet();
|
||||
UpdateDescription description1 = UpdateDescription.mentioning(Collections.singletonList(UUID.randomUUID()), stringFactory1, 0);
|
||||
UpdateDescription description2 = UpdateDescription.mentioning(Collections.singletonList(UUID.randomUUID()), stringFactory2, 0);
|
||||
UpdateDescription description1 = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory1, 0);
|
||||
UpdateDescription description2 = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory2, 0);
|
||||
|
||||
factoryCalls1.set(10);
|
||||
factoryCalls2.set(20);
|
||||
@@ -148,9 +149,9 @@ public final class UpdateDescriptionTest {
|
||||
AtomicInteger factoryCalls2 = new AtomicInteger();
|
||||
UpdateDescription.StringFactory stringFactory1 = () -> "update." + factoryCalls1.incrementAndGet();
|
||||
UpdateDescription.StringFactory stringFactory2 = () -> "update." + factoryCalls2.incrementAndGet();
|
||||
UpdateDescription description1 = UpdateDescription.mentioning(Collections.singletonList(UUID.randomUUID()), stringFactory1, 0);
|
||||
UpdateDescription description1 = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory1, 0);
|
||||
UpdateDescription description2 = UpdateDescription.staticDescription("static", 0);
|
||||
UpdateDescription description3 = UpdateDescription.mentioning(Collections.singletonList(UUID.randomUUID()), stringFactory2, 0);
|
||||
UpdateDescription description3 = UpdateDescription.mentioning(Collections.singletonList(ACI.from(UUID.randomUUID())), stringFactory2, 0);
|
||||
|
||||
factoryCalls1.set(100);
|
||||
factoryCalls2.set(200);
|
||||
|
||||
Reference in New Issue
Block a user