diff --git a/src/main/java/com/google/firebase/messaging/FirebaseMessaging.java b/src/main/java/com/google/firebase/messaging/FirebaseMessaging.java index 95366eaa7..91106bc65 100644 --- a/src/main/java/com/google/firebase/messaging/FirebaseMessaging.java +++ b/src/main/java/com/google/firebase/messaging/FirebaseMessaging.java @@ -41,6 +41,8 @@ */ public class FirebaseMessaging { + public static final int MAX_MESSAGES_IN_LIST = 500; + private final FirebaseApp app; private final Supplier extends FirebaseMessagingClient> messagingClient; private final Supplier extends InstanceIdClient> instanceIdClient; @@ -147,7 +149,8 @@ protected String execute() throws FirebaseMessagingException { *
The responses list obtained by calling {@link BatchResponse#getResponses()} on the return * value corresponds to the order of input messages. * - * @param messages A non-null, non-empty list containing up to 500 messages. + * @param messages A non-null, non-empty list containing up to {@value #MAX_MESSAGES_IN_LIST} + * messages. * @return A {@link BatchResponse} indicating the result of the operation. * @throws FirebaseMessagingException If an error occurs while handing the messages off to FCM for * delivery. An exception here indicates a total failure -- i.e. none of the messages in the @@ -171,7 +174,8 @@ public BatchResponse sendAll( *
The responses list obtained by calling {@link BatchResponse#getResponses()} on the return
* value corresponds to the order of input messages.
*
- * @param messages A non-null, non-empty list containing up to 500 messages.
+ * @param messages A non-null, non-empty list containing up to {@value #MAX_MESSAGES_IN_LIST}
+ * messages.
* @param dryRun A boolean indicating whether to perform a dry run (validation only) of the send.
* @return A {@link BatchResponse} indicating the result of the operation.
* @throws FirebaseMessagingException If an error occurs while handing the messages off to FCM for
@@ -186,7 +190,8 @@ public BatchResponse sendAll(
/**
* Similar to {@link #sendAll(List)} but performs the operation asynchronously.
*
- * @param messages A non-null, non-empty list containing up to 500 messages.
+ * @param messages A non-null, non-empty list containing up to {@value #MAX_MESSAGES_IN_LIST}
+ * messages.
* @return @return An {@code ApiFuture} that will complete with a {@link BatchResponse} when
* the messages have been sent.
*/
@@ -197,7 +202,8 @@ public ApiFuture Instances of this class are thread-safe and immutable. Use {@link MulticastMessage.Builder}
@@ -56,7 +58,8 @@ public class MulticastMessage {
private MulticastMessage(Builder builder) {
this.tokens = builder.tokens.build();
checkArgument(!this.tokens.isEmpty(), "at least one token must be specified");
- checkArgument(this.tokens.size() <= 500, "no more than 500 tokens can be specified");
+ checkArgument(this.tokens.size() <= MAX_MESSAGES_IN_LIST, "no more than "
+ + MAX_MESSAGES_IN_LIST + " tokens can be specified");
for (String token : this.tokens) {
checkArgument(!Strings.isNullOrEmpty(token), "none of the tokens can be null or empty");
}
@@ -107,8 +110,9 @@ public static class Builder {
private Builder() {}
/**
- * Adds a token to which the message should be sent. Up to 500 tokens can be specified on
- * a single instance of {@link MulticastMessage}.
+ * Adds a token to which the message should be sent.
+ * Up to {@value com.google.firebase.messaging.FirebaseMessaging#MAX_MESSAGES_IN_LIST}
+ * tokens can be specified on a single instance of {@link MulticastMessage}.
*
* @param token A non-null, non-empty Firebase device registration token.
* @return This builder.
@@ -119,8 +123,9 @@ public Builder addToken(@NonNull String token) {
}
/**
- * Adds a collection of tokens to which the message should be sent. Up to 500 tokens can be
- * specified on a single instance of {@link MulticastMessage}.
+ * Adds a collection of tokens to which the message should be sent.
+ * Up to {@value com.google.firebase.messaging.FirebaseMessaging#MAX_MESSAGES_IN_LIST}
+ * tokens can be specified on a single instance of {@link MulticastMessage}.
*
* @param tokens Collection of Firebase device registration tokens.
* @return This builder.
diff --git a/src/test/java/com/google/firebase/messaging/FirebaseMessagingIT.java b/src/test/java/com/google/firebase/messaging/FirebaseMessagingIT.java
index 9ae7bba24..16933ceaa 100644
--- a/src/test/java/com/google/firebase/messaging/FirebaseMessagingIT.java
+++ b/src/test/java/com/google/firebase/messaging/FirebaseMessagingIT.java
@@ -16,6 +16,7 @@
package com.google.firebase.messaging;
+import static com.google.firebase.messaging.FirebaseMessaging.MAX_MESSAGES_IN_LIST;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -147,16 +148,16 @@ public void testSendAll() throws Exception {
}
@Test
- public void testSendFiveHundred() throws Exception {
+ public void testSendMaximumAmountOfMessages() throws Exception {
List