Deserialize null capabilities in Device entities as empty sets

This commit is contained in:
Jon Chambers
2024-11-01 16:48:56 -04:00
committed by GitHub
parent fc0a7b7657
commit c9a396b9e3
2 changed files with 27 additions and 0 deletions

View File

@@ -6,11 +6,15 @@
package org.whispersystems.textsecuregcm.storage;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import java.time.Duration;
import java.time.Instant;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.whispersystems.textsecuregcm.util.SystemMapper;
class DeviceTest {
@@ -42,4 +46,25 @@ class DeviceTest {
assertEquals(expectExpired, device.isExpired());
}
@Test
void deserializeCapabilities() throws JsonProcessingException {
{
final Device device = SystemMapper.jsonMapper().readValue("""
{
"capabilities": null
}
""", Device.class);
assertNotNull(device.getCapabilities(),
"Device deserialization should populate null capabilities with an empty set");
}
{
final Device device = SystemMapper.jsonMapper().readValue("{}", Device.class);
assertNotNull(device.getCapabilities(),
"Device deserialization should populate null capabilities with an empty set");
}
}
}