Skip to content

Commit

Permalink
Made the minimal constructor for SimpleApnsPushNotification use a non…
Browse files Browse the repository at this point in the history
…-zero expiration time.
  • Loading branch information
jchambers committed Apr 8, 2018
1 parent 9f67025 commit aab6cfb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import java.util.Date;
import java.util.Objects;
import java.util.UUID;
import java.util.concurrent.TimeUnit;


/**
* A simple and immutable implementation of the {@link ApnsPushNotification} interface.
Expand All @@ -48,20 +50,27 @@ public class SimpleApnsPushNotification implements ApnsPushNotification {
private final UUID apnsId;

/**
* Constructs a new push notification with the given token, topic, and payload. No expiration time is set for the
* notification, so APNs will not attempt to store the notification for later delivery if the initial attempt fails.
* An "immediate" delivery priority is used for the notification, and as such the payload should contain an alert,
* sound, or badge component.
* The default expiration period for push notifications (one day).
*/
public static final long DEFAULT_EXPIRATION_PERIOD_MILLIS = TimeUnit.DAYS.toMillis(1);

/**
* Constructs a new push notification with the given token, topic, and payload. A default expiration time is set for
* the notification; callers that require immediate expiration or a non-default expiration period should use a
* constructor that accepts an expiration time as an argument. An "immediate" delivery priority is used for the
* notification, and as such the payload should contain an alert, sound, or badge component.
*
* @param token the device token to which this push notification should be delivered
* @param topic the topic to which this notification should be sent
* @param payload the payload to include in this push notification
*
* @see DeliveryPriority#IMMEDIATE
* @see #DEFAULT_EXPIRATION_PERIOD_MILLIS
*/
public SimpleApnsPushNotification(final String token, final String topic, final String payload) {
this(token, topic, payload, null, DeliveryPriority.IMMEDIATE, null, null);
this(token, topic, payload, new Date(System.currentTimeMillis() + DEFAULT_EXPIRATION_PERIOD_MILLIS), DeliveryPriority.IMMEDIATE, null, null);
}

/**
* Constructs a new push notification with the given token, topic, payload, and expiration time. An "immediate"
* delivery priority is used for the notification, and as such the payload should contain an alert, sound, or badge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@
import java.util.Date;
import java.util.UUID;

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

public class SimpleApnsPushNotificationTest {

Expand All @@ -40,13 +39,15 @@ public void testSimpleApnsPushNotificationTokenTopicPayload() {
final String topic = "test-topic";
final String payload = "{\"test\": true}";

final Date now = new Date();

final SimpleApnsPushNotification pushNotification =
new SimpleApnsPushNotification(token, topic, payload);

assertEquals(token, pushNotification.getToken());
assertEquals(topic, pushNotification.getTopic());
assertEquals(payload, pushNotification.getPayload());
assertNull(pushNotification.getExpiration());
assertTrue(pushNotification.getExpiration().after(now));
Assert.assertEquals(DeliveryPriority.IMMEDIATE, pushNotification.getPriority());
assertNull(pushNotification.getCollapseId());
}
Expand Down

0 comments on commit aab6cfb

Please sign in to comment.