PKSendPushNotificationUtil implements AutoCloseable { public PushNotificationFuture<SimpleApnsPushNotification, PushNotificationResponse<SimpleApnsPushNotification>> sendPushNotificationAsync(final String pushtoken) { LOGGER.debug("Sending Push notification for key: {}", pushtoken); final ApnsPayloadBuilder payloadBuilder = new ApnsPayloadBuilder(); payloadBuilder.setAlertBody(EMPTY_PUSH_JSON_STRING); final String payload = payloadBuilder.buildWithDefaultMaximumLength(); final String token = TokenUtil.sanitizeTokenString(pushtoken); Assert.state(!this.topics.isEmpty(), "APNS topic is required for sending a push notification"); String topic = null; if (!this.topics.isEmpty()) { topic = this.topics.iterator().next(); if (this.topics.size() > 1) { LOGGER.warn("Multiple APNS topics detected, using {} (first value out of {} available) for sending a push notification", topic, this.topics.size()); } } SimpleApnsPushNotification pushNotification = new SimpleApnsPushNotification(token, topic, payload); LOGGER.debug("Send Push notification for key: {}", pushtoken); return client.sendNotification(pushNotification); } PKSendPushNotificationUtil(String keyStorePath, char [] keyStorePassword);  PKSendPushNotificationUtil(String keyStorePath, char [] keyStorePassword, int poolSize); @Deprecated  PKSendPushNotificationUtil(String keyStorePath, String keyStorePassword); @Deprecated  PKSendPushNotificationUtil(String keyStorePath, String keyStorePassword, int poolSize); void setClient(ApnsClient client); @Deprecated void sendPushNotification(final String pushtoken); PushNotificationFuture<SimpleApnsPushNotification, PushNotificationResponse<SimpleApnsPushNotification>> sendPushNotificationAsync(final String pushtoken); @Deprecated void sendMultiplePushNotifications(final List<String> pushtokens); @Override void close();  }
@Test public void sendPushNotificationWithMockAPNS() throws Exception { final PushNotificationResponse<SimpleApnsPushNotification> response = mockPushUtil.sendPushNotificationAsync("ABC1234").get(); assertThat(response.isAccepted()).isTrue(); }
@Test public void sendPushNotificationWithBadCertificate() { assertThatThrownBy(new ThrowableAssert.ThrowingCallable() { @Override public void call() throws Exception { badCertPushUtil.sendPushNotificationAsync("ABC1234").get(); } }).isInstanceOf(IllegalStateException.class).hasMessage("APNS topic is required for sending a push notification"); }