diff --git a/src/test/java/com/google/firebase/messaging/FirebaseMessagingClientImplTest.java b/src/test/java/com/google/firebase/messaging/FirebaseMessagingClientImplTest.java index 17848cc65..3180aea01 100644 --- a/src/test/java/com/google/firebase/messaging/FirebaseMessagingClientImplTest.java +++ b/src/test/java/com/google/firebase/messaging/FirebaseMessagingClientImplTest.java @@ -17,7 +17,6 @@ package com.google.firebase.messaging; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; @@ -29,7 +28,6 @@ import com.google.api.client.http.HttpHeaders; import com.google.api.client.http.HttpMethods; import com.google.api.client.http.HttpRequest; -import com.google.api.client.http.HttpRequestInitializer; import com.google.api.client.http.HttpResponseException; import com.google.api.client.http.HttpResponseInterceptor; import com.google.api.client.http.HttpTransport; @@ -73,16 +71,9 @@ public class FirebaseMessagingClientImplTest { private static final String MOCK_RESPONSE = "{\"name\": \"mock-name\"}"; - private static final String MOCK_BATCH_SUCCESS_RESPONSE = TestUtils.loadResource( - "fcm_batch_success.txt"); - - private static final String MOCK_BATCH_FAILURE_RESPONSE = TestUtils.loadResource( - "fcm_batch_failure.txt"); - private static final Message EMPTY_MESSAGE = Message.builder() .setTopic("test-topic") .build(); - private static final List MESSAGE_LIST = ImmutableList.of(EMPTY_MESSAGE, EMPTY_MESSAGE); private static final boolean DRY_RUN_ENABLED = true; private static final boolean DRY_RUN_DISABLED = false; @@ -320,187 +311,6 @@ public void testSendErrorWithDetailsAndNoCode() { } } - @Test - public void testSendAll() throws Exception { - final TestResponseInterceptor interceptor = new TestResponseInterceptor(); - FirebaseMessagingClient client = initMessagingClientForBatchRequests( - MOCK_BATCH_SUCCESS_RESPONSE, interceptor); - - BatchResponse responses = client.sendAll(MESSAGE_LIST, false); - - assertBatchResponse(responses, interceptor, 2, 0); - } - - @Test - public void testSendAllDryRun() throws Exception { - final TestResponseInterceptor interceptor = new TestResponseInterceptor(); - FirebaseMessagingClient client = initMessagingClientForBatchRequests( - MOCK_BATCH_SUCCESS_RESPONSE, interceptor); - - BatchResponse responses = client.sendAll(MESSAGE_LIST, true); - - assertBatchResponse(responses, interceptor, 2, 0); - } - - @Test - public void testRequestInitializerAppliedToBatchRequests() throws Exception { - TestResponseInterceptor interceptor = new TestResponseInterceptor(); - MockHttpTransport transport = new MockHttpTransport.Builder() - .setLowLevelHttpResponse(getBatchResponse(MOCK_BATCH_SUCCESS_RESPONSE)) - .build(); - HttpRequestInitializer initializer = new HttpRequestInitializer() { - @Override - public void initialize(HttpRequest httpRequest) { - httpRequest.getHeaders().set("x-custom-header", "test-value"); - } - }; - FirebaseMessagingClientImpl client = FirebaseMessagingClientImpl.builder() - .setProjectId("test-project") - .setJsonFactory(ApiClientUtils.getDefaultJsonFactory()) - .setRequestFactory(transport.createRequestFactory(initializer)) - .setChildRequestFactory(Utils.getDefaultTransport().createRequestFactory()) - .setResponseInterceptor(interceptor) - .build(); - - try { - client.sendAll(MESSAGE_LIST, DRY_RUN_DISABLED); - } finally { - HttpRequest request = interceptor.getLastRequest(); - assertEquals("test-value", request.getHeaders().get("x-custom-header")); - } - } - - @Test - public void testSendAllFailure() throws Exception { - final TestResponseInterceptor interceptor = new TestResponseInterceptor(); - FirebaseMessagingClient client = initMessagingClientForBatchRequests( - MOCK_BATCH_FAILURE_RESPONSE, interceptor); - List messages = ImmutableList.of(EMPTY_MESSAGE, EMPTY_MESSAGE, EMPTY_MESSAGE); - - BatchResponse responses = client.sendAll(messages, DRY_RUN_DISABLED); - - assertBatchResponse(responses, interceptor, 1, 2); - } - - @Test - public void testSendAllHttpError() { - for (int code : HTTP_ERRORS) { - response.setStatusCode(code).setContent("{}"); - - try { - client.sendAll(MESSAGE_LIST, DRY_RUN_DISABLED); - fail("No error thrown for HTTP error"); - } catch (FirebaseMessagingException error) { - checkExceptionFromHttpResponse(error, HTTP_2_ERROR.get(code), null, - "Unexpected HTTP response with status: " + code + "\n{}"); - } - checkBatchRequestHeader(interceptor.getLastRequest()); - } - } - - @Test - public void testSendAllTransportError() { - FirebaseMessagingClient client = initClientWithFaultyTransport(); - - try { - client.sendAll(MESSAGE_LIST, DRY_RUN_DISABLED); - fail("No error thrown for HTTP error"); - } catch (FirebaseMessagingException error) { - assertEquals(ErrorCode.UNKNOWN, error.getErrorCode()); - assertEquals( - "Unknown error while making a remote service call: transport error", error.getMessage()); - assertTrue(error.getCause() instanceof IOException); - assertNull(error.getHttpResponse()); - assertNull(error.getMessagingErrorCode()); - } - } - - @Test - public void testSendAllErrorWithEmptyResponse() { - for (int code : HTTP_ERRORS) { - response.setStatusCode(code).setZeroContent(); - - try { - client.sendAll(MESSAGE_LIST, DRY_RUN_DISABLED); - fail("No error thrown for HTTP error"); - } catch (FirebaseMessagingException error) { - checkExceptionFromHttpResponse(error, HTTP_2_ERROR.get(code), null, - "Unexpected HTTP response with status: " + code + "\nnull"); - } - checkBatchRequestHeader(interceptor.getLastRequest()); - } - } - - @Test - public void testSendAllErrorWithDetails() { - for (int code : HTTP_ERRORS) { - response.setStatusCode(code).setContent( - "{\"error\": {\"status\": \"INVALID_ARGUMENT\", \"message\": \"test error\"}}"); - - try { - client.sendAll(MESSAGE_LIST, DRY_RUN_DISABLED); - fail("No error thrown for HTTP error"); - } catch (FirebaseMessagingException error) { - checkExceptionFromHttpResponse(error, ErrorCode.INVALID_ARGUMENT, null); - } - checkBatchRequestHeader(interceptor.getLastRequest()); - } - } - - @Test - public void testSendAllErrorWithCanonicalCode() { - for (int code : HTTP_ERRORS) { - response.setStatusCode(code).setContent( - "{\"error\": {\"status\": \"NOT_FOUND\", \"message\": \"test error\"}}"); - - try { - client.sendAll(MESSAGE_LIST, DRY_RUN_DISABLED); - fail("No error thrown for HTTP error"); - } catch (FirebaseMessagingException error) { - checkExceptionFromHttpResponse(error, ErrorCode.NOT_FOUND, null); - } - checkBatchRequestHeader(interceptor.getLastRequest()); - } - } - - @Test - public void testSendAllErrorWithFcmError() { - for (int code : HTTP_ERRORS) { - response.setStatusCode(code).setContent( - "{\"error\": {\"status\": \"INVALID_ARGUMENT\", \"message\": \"test error\", " - + "\"details\":[{\"@type\": \"type.googleapis.com/google.firebase.fcm" - + ".v1.FcmError\", \"errorCode\": \"UNREGISTERED\"}]}}"); - - try { - client.sendAll(MESSAGE_LIST, DRY_RUN_DISABLED); - fail("No error thrown for HTTP error"); - } catch (FirebaseMessagingException error) { - checkExceptionFromHttpResponse(error, ErrorCode.INVALID_ARGUMENT, - MessagingErrorCode.UNREGISTERED); - } - checkBatchRequestHeader(interceptor.getLastRequest()); - } - } - - @Test - public void testSendAllErrorWithoutMessage() { - final String responseBody = "{\"error\": {\"status\": \"INVALID_ARGUMENT\", " - + "\"details\":[{\"@type\": \"type.googleapis.com/google.firebase.fcm" - + ".v1.FcmError\", \"errorCode\": \"UNREGISTERED\"}]}}"; - for (int code : HTTP_ERRORS) { - response.setStatusCode(code).setContent(responseBody); - - try { - client.sendAll(MESSAGE_LIST, DRY_RUN_DISABLED); - fail("No error thrown for HTTP error"); - } catch (FirebaseMessagingException error) { - checkExceptionFromHttpResponse(error, ErrorCode.INVALID_ARGUMENT, - MessagingErrorCode.UNREGISTERED, - "Unexpected HTTP response with status: " + code + "\n" + responseBody); - } - checkBatchRequestHeader(interceptor.getLastRequest()); - } - } @Test(expected = IllegalArgumentException.class) public void testBuilderNullProjectId() { @@ -563,18 +373,6 @@ private FirebaseMessagingClientImpl initMessagingClient( .build(); } - private FirebaseMessagingClientImpl initMessagingClientForBatchRequests( - String responsePayload, TestResponseInterceptor interceptor) { - MockLowLevelHttpResponse httpResponse = getBatchResponse(responsePayload); - return initMessagingClient(httpResponse, interceptor); - } - - private MockLowLevelHttpResponse getBatchResponse(String responsePayload) { - return new MockLowLevelHttpResponse() - .setContentType("multipart/mixed; boundary=test_boundary") - .setContent(responsePayload); - } - private FirebaseMessagingClientImpl initClientWithFaultyTransport() { HttpTransport transport = TestUtils.createFaultyHttpTransport(); return FirebaseMessagingClientImpl.builder() @@ -603,64 +401,6 @@ private void checkRequest( assertEquals(expected, parsed); } - private void assertBatchResponse( - BatchResponse batchResponse, TestResponseInterceptor interceptor, - int successCount, int failureCount) throws IOException { - - assertEquals(successCount, batchResponse.getSuccessCount()); - assertEquals(failureCount, batchResponse.getFailureCount()); - - List responses = batchResponse.getResponses(); - assertEquals(successCount + failureCount, responses.size()); - for (int i = 0; i < successCount; i++) { - SendResponse sendResponse = responses.get(i); - assertTrue(sendResponse.isSuccessful()); - assertEquals("projects/test-project/messages/" + (i + 1), sendResponse.getMessageId()); - assertNull(sendResponse.getException()); - } - - for (int i = successCount; i < failureCount; i++) { - SendResponse sendResponse = responses.get(i); - assertFalse(sendResponse.isSuccessful()); - assertNull(sendResponse.getMessageId()); - - FirebaseMessagingException exception = sendResponse.getException(); - assertNotNull(exception); - assertEquals(ErrorCode.INVALID_ARGUMENT, exception.getErrorCode()); - assertNull(exception.getCause()); - assertNull(exception.getHttpResponse()); - assertEquals(MessagingErrorCode.INVALID_ARGUMENT, exception.getMessagingErrorCode()); - } - - checkBatchRequestHeader(interceptor.getLastRequest()); - checkBatchRequest(interceptor.getLastRequest(), successCount + failureCount); - } - - private void checkBatchRequestHeader(HttpRequest request) { - assertEquals("POST", request.getRequestMethod()); - assertEquals("https://fcm.googleapis.com/batch", request.getUrl().toString()); - } - - private void checkBatchRequest(HttpRequest request, int expectedParts) throws IOException { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - request.getContent().writeTo(out); - String[] lines = out.toString().split("\n"); - assertEquals(expectedParts, countLinesWithPrefix(lines, "POST " + TEST_FCM_URL)); - assertEquals(expectedParts, countLinesWithPrefix(lines, "x-goog-api-format-version: 2")); - assertEquals(expectedParts, countLinesWithPrefix( - lines, "x-firebase-client: fire-admin-java/" + SdkUtils.getVersion())); - } - - private int countLinesWithPrefix(String[] lines, String prefix) { - int matchCount = 0; - for (String line : lines) { - if (line.trim().startsWith(prefix)) { - matchCount++; - } - } - return matchCount; - } - private FirebaseMessagingClientImpl.Builder fullyPopulatedBuilder() { return FirebaseMessagingClientImpl.builder() .setProjectId("test-project") diff --git a/src/test/java/com/google/firebase/messaging/FirebaseMessagingIT.java b/src/test/java/com/google/firebase/messaging/FirebaseMessagingIT.java index bebae6e4d..d9375781c 100644 --- a/src/test/java/com/google/firebase/messaging/FirebaseMessagingIT.java +++ b/src/test/java/com/google/firebase/messaging/FirebaseMessagingIT.java @@ -193,103 +193,6 @@ public void testSendEachForMulticast() throws Exception { } } - @Test - public void testSendAll() throws Exception { - List messages = new ArrayList<>(); - messages.add( - Message.builder() - .setNotification(Notification.builder() - .setTitle("Title") - .setBody("Body") - .build()) - .setTopic("foo-bar") - .build()); - messages.add( - Message.builder() - .setNotification(Notification.builder() - .setTitle("Title") - .setBody("Body") - .build()) - .setTopic("foo-bar") - .build()); - messages.add( - Message.builder() - .setNotification(Notification.builder() - .setTitle("Title") - .setBody("Body") - .build()) - .setToken("not-a-token") - .build()); - - BatchResponse response = FirebaseMessaging.getInstance().sendAll(messages, true); - - assertEquals(2, response.getSuccessCount()); - assertEquals(1, response.getFailureCount()); - - List responses = response.getResponses(); - assertEquals(3, responses.size()); - assertTrue(responses.get(0).isSuccessful()); - String id = responses.get(0).getMessageId(); - assertTrue(id != null && id.matches("^projects/.*/messages/.*$")); - - assertTrue(responses.get(1).isSuccessful()); - id = responses.get(1).getMessageId(); - assertTrue(id != null && id.matches("^projects/.*/messages/.*$")); - - assertFalse(responses.get(2).isSuccessful()); - assertNull(responses.get(2).getMessageId()); - FirebaseMessagingException exception = responses.get(2).getException(); - assertNotNull(exception); - assertEquals(ErrorCode.INVALID_ARGUMENT, exception.getErrorCode()); - } - - @Test - public void testSendFiveHundred() throws Exception { - List messages = new ArrayList<>(); - for (int i = 0; i < 500; i++) { - messages.add(Message.builder().setTopic("foo-bar-" + (i % 10)).build()); - } - - BatchResponse response = FirebaseMessaging.getInstance().sendAll(messages, true); - - assertEquals(500, response.getResponses().size()); - assertEquals(500, response.getSuccessCount()); - assertEquals(0, response.getFailureCount()); - for (SendResponse sendResponse : response.getResponses()) { - if (!sendResponse.isSuccessful()) { - sendResponse.getException().printStackTrace(); - } - assertTrue(sendResponse.isSuccessful()); - String id = sendResponse.getMessageId(); - assertTrue(id != null && id.matches("^projects/.*/messages/.*$")); - assertNull(sendResponse.getException()); - } - } - - @Test - public void testSendMulticast() throws Exception { - MulticastMessage multicastMessage = MulticastMessage.builder() - .setNotification(Notification.builder() - .setTitle("Title") - .setBody("Body") - .build()) - .addToken("not-a-token") - .addToken("also-not-a-token") - .build(); - - BatchResponse response = FirebaseMessaging.getInstance().sendMulticast( - multicastMessage, true); - - assertEquals(0, response.getSuccessCount()); - assertEquals(2, response.getFailureCount()); - assertEquals(2, response.getResponses().size()); - for (SendResponse sendResponse : response.getResponses()) { - assertFalse(sendResponse.isSuccessful()); - assertNull(sendResponse.getMessageId()); - assertNotNull(sendResponse.getException()); - } - } - @Test public void testSubscribe() throws Exception { FirebaseMessaging messaging = FirebaseMessaging.getInstance(); diff --git a/src/test/java/com/google/firebase/messaging/FirebaseMessagingTest.java b/src/test/java/com/google/firebase/messaging/FirebaseMessagingTest.java index dc07ce002..6d61f51de 100644 --- a/src/test/java/com/google/firebase/messaging/FirebaseMessagingTest.java +++ b/src/test/java/com/google/firebase/messaging/FirebaseMessagingTest.java @@ -545,260 +545,6 @@ public void testSendEachForMulticastAsyncFailure() throws Exception { assertFalse(client.isLastDryRun); } - @Test - public void testSendAllWithNull() throws FirebaseMessagingException { - MockFirebaseMessagingClient client = MockFirebaseMessagingClient.fromMessageId(null); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - - try { - messaging.sendAll(null); - fail("No error thrown for null message list"); - } catch (NullPointerException expected) { - // expected - } - - assertNull(client.lastBatch); - } - - @Test - public void testSendAllWithEmptyList() throws FirebaseMessagingException { - MockFirebaseMessagingClient client = MockFirebaseMessagingClient.fromMessageId(null); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - - try { - messaging.sendAll(ImmutableList.of()); - fail("No error thrown for empty message list"); - } catch (IllegalArgumentException expected) { - // expected - } - - assertNull(client.lastBatch); - } - - @Test - public void testSendAllWithTooManyMessages() throws FirebaseMessagingException { - MockFirebaseMessagingClient client = MockFirebaseMessagingClient.fromMessageId(null); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - ImmutableList.Builder listBuilder = ImmutableList.builder(); - for (int i = 0; i < 501; i++) { - listBuilder.add(Message.builder().setTopic("topic").build()); - } - - try { - messaging.sendAll(listBuilder.build(), false); - fail("No error thrown for too many messages in the list"); - } catch (IllegalArgumentException expected) { - // expected - } - - assertNull(client.lastBatch); - } - - @Test - public void testSendAll() throws FirebaseMessagingException { - BatchResponse batchResponse = getBatchResponse("test"); - MockFirebaseMessagingClient client = MockFirebaseMessagingClient - .fromBatchResponse(batchResponse); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - ImmutableList messages = ImmutableList.of(EMPTY_MESSAGE); - - BatchResponse response = messaging.sendAll(messages); - - assertSame(batchResponse, response); - assertSame(messages, client.lastBatch); - assertFalse(client.isLastDryRun); - } - - @Test - public void testSendAllDryRun() throws FirebaseMessagingException { - BatchResponse batchResponse = getBatchResponse("test"); - MockFirebaseMessagingClient client = MockFirebaseMessagingClient - .fromBatchResponse(batchResponse); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - ImmutableList messages = ImmutableList.of(EMPTY_MESSAGE); - - BatchResponse response = messaging.sendAll(messages, true); - - assertSame(batchResponse, response); - assertSame(messages, client.lastBatch); - assertTrue(client.isLastDryRun); - } - - @Test - public void testSendAllFailure() { - MockFirebaseMessagingClient client = MockFirebaseMessagingClient.fromException(TEST_EXCEPTION); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - ImmutableList messages = ImmutableList.of(EMPTY_MESSAGE); - - try { - messaging.sendAll(messages); - } catch (FirebaseMessagingException e) { - assertSame(TEST_EXCEPTION, e); - } - - assertSame(messages, client.lastBatch); - assertFalse(client.isLastDryRun); - } - - @Test - public void testSendAllAsync() throws Exception { - BatchResponse batchResponse = getBatchResponse("test"); - MockFirebaseMessagingClient client = MockFirebaseMessagingClient - .fromBatchResponse(batchResponse); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - ImmutableList messages = ImmutableList.of(EMPTY_MESSAGE); - - BatchResponse response = messaging.sendAllAsync(messages).get(); - - assertSame(batchResponse, response); - assertSame(messages, client.lastBatch); - assertFalse(client.isLastDryRun); - } - - @Test - public void testSendAllAsyncDryRun() throws Exception { - BatchResponse batchResponse = getBatchResponse("test"); - MockFirebaseMessagingClient client = MockFirebaseMessagingClient - .fromBatchResponse(batchResponse); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - ImmutableList messages = ImmutableList.of(EMPTY_MESSAGE); - - BatchResponse response = messaging.sendAllAsync(messages, true).get(); - - assertSame(batchResponse, response); - assertSame(messages, client.lastBatch); - assertTrue(client.isLastDryRun); - } - - @Test - public void testSendAllAsyncFailure() throws InterruptedException { - MockFirebaseMessagingClient client = MockFirebaseMessagingClient.fromException(TEST_EXCEPTION); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - ImmutableList messages = ImmutableList.of(EMPTY_MESSAGE); - - try { - messaging.sendAllAsync(messages).get(); - } catch (ExecutionException e) { - assertSame(TEST_EXCEPTION, e.getCause()); - } - - assertSame(messages, client.lastBatch); - assertFalse(client.isLastDryRun); - } - - @Test - public void testSendMulticastWithNull() throws FirebaseMessagingException { - MockFirebaseMessagingClient client = MockFirebaseMessagingClient.fromMessageId(null); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - - try { - messaging.sendMulticast(null); - fail("No error thrown for null multicast message"); - } catch (NullPointerException expected) { - // expected - } - - assertNull(client.lastBatch); - } - - @Test - public void testSendMulticast() throws FirebaseMessagingException { - BatchResponse batchResponse = getBatchResponse("test"); - MockFirebaseMessagingClient client = MockFirebaseMessagingClient - .fromBatchResponse(batchResponse); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - - BatchResponse response = messaging.sendMulticast(TEST_MULTICAST_MESSAGE); - - assertSame(batchResponse, response); - assertEquals(2, client.lastBatch.size()); - assertEquals("test-fcm-token1", client.lastBatch.get(0).getToken()); - assertEquals("test-fcm-token2", client.lastBatch.get(1).getToken()); - assertFalse(client.isLastDryRun); - } - - @Test - public void testSendMulticastDryRun() throws FirebaseMessagingException { - BatchResponse batchResponse = getBatchResponse("test"); - MockFirebaseMessagingClient client = MockFirebaseMessagingClient - .fromBatchResponse(batchResponse); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - - BatchResponse response = messaging.sendMulticast(TEST_MULTICAST_MESSAGE, true); - - assertSame(batchResponse, response); - assertEquals(2, client.lastBatch.size()); - assertEquals("test-fcm-token1", client.lastBatch.get(0).getToken()); - assertEquals("test-fcm-token2", client.lastBatch.get(1).getToken()); - assertTrue(client.isLastDryRun); - } - - @Test - public void testSendMulticastFailure() { - MockFirebaseMessagingClient client = MockFirebaseMessagingClient.fromException(TEST_EXCEPTION); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - - try { - messaging.sendMulticast(TEST_MULTICAST_MESSAGE); - } catch (FirebaseMessagingException e) { - assertSame(TEST_EXCEPTION, e); - } - - assertEquals(2, client.lastBatch.size()); - assertEquals("test-fcm-token1", client.lastBatch.get(0).getToken()); - assertEquals("test-fcm-token2", client.lastBatch.get(1).getToken()); - assertFalse(client.isLastDryRun); - } - - @Test - public void testSendMulticastAsync() throws Exception { - BatchResponse batchResponse = getBatchResponse("test"); - MockFirebaseMessagingClient client = MockFirebaseMessagingClient - .fromBatchResponse(batchResponse); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - - BatchResponse response = messaging.sendMulticastAsync(TEST_MULTICAST_MESSAGE).get(); - - assertSame(batchResponse, response); - assertEquals(2, client.lastBatch.size()); - assertEquals("test-fcm-token1", client.lastBatch.get(0).getToken()); - assertEquals("test-fcm-token2", client.lastBatch.get(1).getToken()); - assertFalse(client.isLastDryRun); - } - - @Test - public void testSendMulticastAsyncDryRun() throws Exception { - BatchResponse batchResponse = getBatchResponse("test"); - MockFirebaseMessagingClient client = MockFirebaseMessagingClient - .fromBatchResponse(batchResponse); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - - BatchResponse response = messaging.sendMulticastAsync(TEST_MULTICAST_MESSAGE, true).get(); - - assertSame(batchResponse, response); - assertEquals(2, client.lastBatch.size()); - assertEquals("test-fcm-token1", client.lastBatch.get(0).getToken()); - assertEquals("test-fcm-token2", client.lastBatch.get(1).getToken()); - assertTrue(client.isLastDryRun); - } - - @Test - public void testSendMulticastAsyncFailure() throws InterruptedException { - MockFirebaseMessagingClient client = MockFirebaseMessagingClient.fromException(TEST_EXCEPTION); - FirebaseMessaging messaging = getMessagingForSend(Suppliers.ofInstance(client)); - - try { - messaging.sendMulticastAsync(TEST_MULTICAST_MESSAGE).get(); - } catch (ExecutionException e) { - assertSame(TEST_EXCEPTION, e.getCause()); - } - - assertEquals(2, client.lastBatch.size()); - assertEquals("test-fcm-token1", client.lastBatch.get(0).getToken()); - assertEquals("test-fcm-token2", client.lastBatch.get(1).getToken()); - assertFalse(client.isLastDryRun); - } - @Test public void testInvalidSubscribe() throws FirebaseMessagingException { MockInstanceIdClient client = MockInstanceIdClient.fromResponse(null); @@ -947,14 +693,6 @@ private FirebaseMessaging getMessagingForTopicManagement( .build(); } - private BatchResponse getBatchResponse(String ...messageIds) { - ImmutableList.Builder listBuilder = ImmutableList.builder(); - for (String messageId : messageIds) { - listBuilder.add(SendResponse.fromMessageId(messageId)); - } - return new BatchResponseImpl(listBuilder.build()); - } - private static class MockFirebaseMessagingClient implements FirebaseMessagingClient { private String messageId; @@ -962,7 +700,6 @@ private static class MockFirebaseMessagingClient implements FirebaseMessagingCli private FirebaseMessagingException exception; private Message lastMessage; - private List lastBatch; private boolean isLastDryRun; private ImmutableMap messageMap; @@ -987,10 +724,6 @@ static MockFirebaseMessagingClient fromMessageMap(Map mes return new MockFirebaseMessagingClient(messageMap, null); } - static MockFirebaseMessagingClient fromBatchResponse(BatchResponse batchResponse) { - return new MockFirebaseMessagingClient(null, batchResponse, null); - } - static MockFirebaseMessagingClient fromException(FirebaseMessagingException exception) { return new MockFirebaseMessagingClient(null, null, exception); } @@ -1018,11 +751,6 @@ public String send(Message message, boolean dryRun) throws FirebaseMessagingExce @Override public BatchResponse sendAll( List messages, boolean dryRun) throws FirebaseMessagingException { - lastBatch = messages; - isLastDryRun = dryRun; - if (exception != null) { - throw exception; - } return batchResponse; } }