Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/java/com/pusher/client/channel/PusherEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public String toString() {
public PusherEvent(String event, String channel, String userId, String data) {
jsonObject.addProperty("event", event);
jsonObject.addProperty("channel", channel);
jsonObject.addProperty("userId", userId);
if (userId != null) {
jsonObject.addProperty("user_id", userId);
}
jsonObject.addProperty("data", data);
}

Expand Down
14 changes: 14 additions & 0 deletions src/test/java/com/pusher/client/channel/PusherEventTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pusher.client.channel;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -45,6 +46,19 @@ public void testUserIdIsExtracted() {
);
assertEquals("my-user-id", e.getUserId());
}

@Test
public void testUserIdIsSetByConstructor() {
final PusherEvent e = new PusherEvent("my-event", "my-channel", "my-user-id", "{}");
assertEquals("my-user-id", e.getUserId());
}

@Test
public void testNullUserIdFromConstructorIsNull() {
final PusherEvent e = new PusherEvent("my-event", "my-channel", null, "{}");
assertNull(e.getUserId());
}

@Test
public void testErrorData() {
final PusherEvent e = PusherEvent.fromJson(
Expand Down
Loading