From 53122b9cbbdac5e50af4d942130b336bfb07bd83 Mon Sep 17 00:00:00 2001 From: Cesare Rocchi Date: Wed, 2 May 2018 17:13:17 +0200 Subject: [PATCH 1/3] Fix typo --- .../io/ably/lib/test/realtime/RealtimePresenceHistoryTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceHistoryTest.java b/lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceHistoryTest.java index 5aca2307a..26cb16ff8 100644 --- a/lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceHistoryTest.java +++ b/lib/src/test/java/io/ably/lib/test/realtime/RealtimePresenceHistoryTest.java @@ -625,7 +625,7 @@ public void presencehistory_time_f() { (new ChannelWaiter(channel)).waitFor(ChannelState.attached); assertEquals("Verify attached state reached", channel.state, ChannelState.attached); - /* send batches of messages with shprt inter-message delay */ + /* send batches of messages with short inter-message delay */ CompletionSet msgComplete = new CompletionSet(); for(int i = 0; i < 20; i++) { channel.presence.enter(String.valueOf(i), msgComplete.add()); From a209402d421a837a86b047e467f19bf5665f835f Mon Sep 17 00:00:00 2001 From: Cesare Rocchi Date: Thu, 3 May 2018 10:11:03 +0200 Subject: [PATCH 2/3] Fix invalid message data test --- .../java/io/ably/lib/types/BaseMessage.java | 1 + .../test/realtime/RealtimeMessageTest.java | 28 ++++++++++--------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/src/main/java/io/ably/lib/types/BaseMessage.java b/lib/src/main/java/io/ably/lib/types/BaseMessage.java index 666981fd4..285388df6 100644 --- a/lib/src/main/java/io/ably/lib/types/BaseMessage.java +++ b/lib/src/main/java/io/ably/lib/types/BaseMessage.java @@ -131,6 +131,7 @@ public void encode(ChannelOptions opts) throws AblyException { encoding = ((encoding == null) ? "" : encoding + "/") + "utf-8"; } } else if(!(data instanceof byte[])) { + Log.d(TAG, "Message data must be either `byte[]`, `String` or `JSONElement`; implicit coercion of other types to String is deprecated"); throw AblyException.fromErrorInfo(new ErrorInfo("Invalid message data or encoding", 400, 40013)); } } diff --git a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeMessageTest.java b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeMessageTest.java index 53bc69690..72247d319 100644 --- a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeMessageTest.java +++ b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeMessageTest.java @@ -825,27 +825,29 @@ static class MessagesEncodingDataItem { public void reject_invalid_message_data() throws AblyException { HashMap data = new HashMap(); Message message = new Message("event", data); - final Log.LogHandler logHandler = Log.handler; - try { - final ArrayList capturedLog = new ArrayList<>(); - Log.setHandler(new Log.LogHandler() { - @Override - public void println(int severity, String tag, String msg, Throwable tr) { - capturedLog.add(new LogLine(severity, tag, msg, tr)); - } - }); + Log.LogHandler originalLogHandler = Log.handler; + int originalLogLevel = Log.level; + Log.setLevel(Log.DEBUG); + final ArrayList capturedLog = new ArrayList<>(); + Log.setHandler(new Log.LogHandler() { + @Override + public void println(int severity, String tag, String msg, Throwable tr) { + capturedLog.add(new LogLine(severity, tag, msg, tr)); + } + }); + try { message.encode(null); - + } catch (AblyException e) { assertEquals(null, message.encoding); assertEquals(data, message.data); - assertEquals(1, capturedLog.size()); LogLine capturedLine = capturedLog.get(0); assertTrue(capturedLine.tag.contains("ably")); - assertTrue(capturedLine.msg.contains("Message data must be either `byte[]`, `String` or `JSONElement`; implicit coercion of other types to String is deprecated" )); + assertTrue(capturedLine.msg.contains("Message data must be either `byte[]`, `String` or `JSONElement`; implicit coercion of other types to String is deprecated")); } finally { - Log.setHandler(logHandler); + Log.setHandler(originalLogHandler); + Log.setLevel(originalLogLevel); } } From 69995806b33671777dd68e989a2aa3ef56e1994d Mon Sep 17 00:00:00 2001 From: Cesare Rocchi Date: Thu, 3 May 2018 10:37:42 +0200 Subject: [PATCH 3/3] Add extra catch for generic exception --- .../java/io/ably/lib/test/realtime/RealtimeMessageTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeMessageTest.java b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeMessageTest.java index 72247d319..3c0b4e3ef 100644 --- a/lib/src/test/java/io/ably/lib/test/realtime/RealtimeMessageTest.java +++ b/lib/src/test/java/io/ably/lib/test/realtime/RealtimeMessageTest.java @@ -845,6 +845,8 @@ public void println(int severity, String tag, String msg, Throwable tr) { LogLine capturedLine = capturedLog.get(0); assertTrue(capturedLine.tag.contains("ably")); assertTrue(capturedLine.msg.contains("Message data must be either `byte[]`, `String` or `JSONElement`; implicit coercion of other types to String is deprecated")); + } catch (Throwable t) { + fail("reject_invalid_message_data: Unexpected exception"); } finally { Log.setHandler(originalLogHandler); Log.setLevel(originalLogLevel);