mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-26 21:13:17 +01:00
Add DevicesHelper
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2021 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.textsecuregcm.tests.util;
|
||||
|
||||
import java.util.Random;
|
||||
import org.whispersystems.textsecuregcm.entities.SignedPreKey;
|
||||
import org.whispersystems.textsecuregcm.storage.Device;
|
||||
import org.whispersystems.textsecuregcm.util.Util;
|
||||
|
||||
public class DevicesHelper {
|
||||
|
||||
private static final Random RANDOM = new Random();
|
||||
|
||||
public static Device createDevice(final long deviceId) {
|
||||
final Device device = new Device(deviceId, null, null, null, null, null, null, false, 0, null, 0, 0, "OWT", 0,
|
||||
null);
|
||||
|
||||
setEnabled(device, true);
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
public static void setEnabled(Device device, boolean enabled) {
|
||||
if (enabled) {
|
||||
device.setSignedPreKey(new SignedPreKey(RANDOM.nextLong(), "testPublicKey-" + RANDOM.nextLong(),
|
||||
"testSignature-" + RANDOM.nextLong()));
|
||||
device.setGcmId("testGcmId" + RANDOM.nextLong());
|
||||
device.setLastSeen(Util.todayInMillis());
|
||||
} else {
|
||||
device.setSignedPreKey(null);
|
||||
}
|
||||
|
||||
// fail fast, to guard against a change to the isEnabled() implementation causing unexpected test behavior
|
||||
assert enabled == device.isEnabled();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user