Skip to content

Commit a51b9dc

Browse files
authored
Merge pull request #138 from pusher/emitchel-feature/trigger-fix
Removing the requirement to trigger with JSON objects as data (same as the Swift library)
2 parents ce025a3 + 950a903 commit a51b9dc

File tree

5 files changed

+13
-17
lines changed

5 files changed

+13
-17
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ build
1212
.idea
1313

1414
*.iml
15-
gradle.properties
15+
gradle.properties
16+
local.properties

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ apply plugin: 'org.ajoberstar.github-pages'
2121
apply plugin: 'signing'
2222

2323
group = "com.pusher"
24-
version = "1.4.0"
24+
version = "2.0.0-SNAPSHOT"
2525
sourceCompatibility = "1.6"
2626
targetCompatibility = "1.6"
2727

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Tue Nov 15 11:59:30 GMT 2016
1+
#Fri Feb 24 10:18:34 GMT 2017
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip

src/main/java/com/pusher/client/channel/impl/PrivateChannelImpl.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@ public void trigger(final String eventName, final String data) {
5252
}
5353

5454
try {
55-
final Map userData = GSON.fromJson(data, Map.class);
5655

5756
final Map<Object, Object> jsonPayload = new LinkedHashMap<Object, Object>();
5857
jsonPayload.put("event", eventName);
5958
jsonPayload.put("channel", name);
60-
jsonPayload.put("data", userData);
59+
jsonPayload.put("data", data);
6160

6261
final String jsonMessage = GSON.toJson(jsonPayload);
6362
connection.sendMessage(jsonMessage);

src/test/java/com/pusher/client/channel/impl/PrivateChannelImplTest.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void testTriggerWithValidEventSendsMessage() {
110110
verify(mockConnection)
111111
.sendMessage(
112112
"{\"event\":\"client-myEvent\",\"channel\":\"" + getChannelName()
113-
+ "\",\"data\":{\"fish\":\"chips\"}}");
113+
+ "\",\"data\":\"{\\\"fish\\\":\\\"chips\\\"}\"}");
114114
}
115115

116116
@Test(expected = IllegalArgumentException.class)
@@ -129,20 +129,16 @@ public void testTriggerWithInvalidEventNameThrowsException() {
129129
((PrivateChannelImpl)channel).trigger("myEvent", "{\"fish\":\"chips\"}");
130130
}
131131

132-
@Test(expected = IllegalArgumentException.class)
133-
public void testTriggerWithInvalidJSONThrowsException() {
134-
when(mockConnection.getState()).thenReturn(ConnectionState.CONNECTED);
135-
channel.updateState(ChannelState.SUBSCRIBED);
136-
137-
((PrivateChannelImpl)channel).trigger("client-myEvent", "{\"fish\":malformed");
138-
}
139-
140-
@Test(expected = IllegalArgumentException.class)
141-
public void testTriggerWithJSONStringInsteadOfObjectThrowsException() {
132+
@Test
133+
public void testTriggerWithString() {
142134
when(mockConnection.getState()).thenReturn(ConnectionState.CONNECTED);
143135
channel.updateState(ChannelState.SUBSCRIBED);
144136

145137
((PrivateChannelImpl)channel).trigger("client-myEvent", "string");
138+
139+
verify(mockConnection).sendMessage(
140+
"{\"event\":\"client-myEvent\",\"channel\":\"" + getChannelName()
141+
+ "\",\"data\":\"string\"}");
146142
}
147143

148144
@Test(expected = IllegalStateException.class)

0 commit comments

Comments
 (0)