From 229617eed5c5a1db8caced144a7a37bc2d1cf980 Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 28 Nov 2023 18:30:04 +0530 Subject: [PATCH] Simplified recoveryKeyContext class --- .../main/java/io/ably/lib/realtime/Connection.java | 5 +---- .../java/io/ably/lib/types/RecoveryKeyContext.java | 12 ++---------- .../io/ably/lib/types/RecoveryKeyContextTest.java | 11 +++++------ 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/lib/src/main/java/io/ably/lib/realtime/Connection.java b/lib/src/main/java/io/ably/lib/realtime/Connection.java index 96469e9e2..4c4638168 100644 --- a/lib/src/main/java/io/ably/lib/realtime/Connection.java +++ b/lib/src/main/java/io/ably/lib/realtime/Connection.java @@ -71,10 +71,7 @@ public String createRecoveryKey() { return null; } - RecoveryKeyContext recoveryKey = new RecoveryKeyContext(key, serial); - recoveryKey.setChannelSerials(this.ably.getChannelSerials()); - - return recoveryKey.encode(); + return new RecoveryKeyContext(key, serial, ably.getChannelSerials()).encode(); } /** diff --git a/lib/src/main/java/io/ably/lib/types/RecoveryKeyContext.java b/lib/src/main/java/io/ably/lib/types/RecoveryKeyContext.java index 7d7e48522..8faac8c94 100644 --- a/lib/src/main/java/io/ably/lib/types/RecoveryKeyContext.java +++ b/lib/src/main/java/io/ably/lib/types/RecoveryKeyContext.java @@ -20,9 +20,10 @@ public class RecoveryKeyContext { */ private final Map channelSerials = new HashMap<>(); - public RecoveryKeyContext(String connectionKey, long msgSerial) { + public RecoveryKeyContext(String connectionKey, long msgSerial, Map channelSerials) { this.connectionKey = connectionKey; this.msgSerial = msgSerial; + this.channelSerials.putAll(channelSerials); } public String getConnectionKey() { @@ -37,15 +38,6 @@ public Map getChannelSerials() { return channelSerials; } - public void setChannelSerials(Map channelSerials) { - this.channelSerials.clear(); - this.channelSerials.putAll(channelSerials); - } - - public void addSerial(String channelName, String channelSerial) { - this.channelSerials.put(channelName, channelSerial); - } - public String encode() { return Serialisation.gson.toJson(this); } diff --git a/lib/src/test/java/io/ably/lib/types/RecoveryKeyContextTest.java b/lib/src/test/java/io/ably/lib/types/RecoveryKeyContextTest.java index 8684a8264..85d9e0127 100644 --- a/lib/src/test/java/io/ably/lib/types/RecoveryKeyContextTest.java +++ b/lib/src/test/java/io/ably/lib/types/RecoveryKeyContextTest.java @@ -17,12 +17,11 @@ public class RecoveryKeyContextTest { public void should_encode_recovery_key_context_object() { String expectedRecoveryKey = "{\"connectionKey\":\"uniqueKey\",\"msgSerial\":1,\"channelSerials\":{\"channel1\":\"1\",\"channel2\":\"2\",\"channel3\":\"3\"}}"; - RecoveryKeyContext recoveryKey = new RecoveryKeyContext("uniqueKey", 1); - Map keys = new HashMap<>(); - keys.put("channel1", "1"); - keys.put("channel2", "2"); - keys.put("channel3", "3"); - recoveryKey.setChannelSerials(keys); + Map serials = new HashMap<>(); + serials.put("channel1", "1"); + serials.put("channel2", "2"); + serials.put("channel3", "3"); + RecoveryKeyContext recoveryKey = new RecoveryKeyContext("uniqueKey", 1, serials); String encodedRecoveryKey = recoveryKey.encode(); assertEquals(expectedRecoveryKey, encodedRecoveryKey); }