### Question:
PushNotificationService { public void send(PushMessage message, String realm) throws PushNotificationException { PushNotificationDelegate delegate = getDelegateForRealm(realm); if (delegate == null) { throw new PushNotificationException("No delegate for supplied realm. Check service exists and init has " + "been called."); } delegate.send(message); } @Inject  PushNotificationService(@Named("frPush") Debug debug,
                                   ConcurrentMap<String, PushNotificationDelegate> pushRealmMap,
                                   ConcurrentMap<String, PushNotificationDelegateFactory> pushFactoryMap,
                                   PushNotificationServiceConfigHelperFactory configHelperFactory,
                                   MessageDispatcherFactory messageDispatcherFactory); void registerServiceListener(); void send(PushMessage message, String realm); void init(String realm); String getRegServiceAddress(String realm); MessageDispatcher getMessageDispatcher(String realm); String getAuthServiceAddress(String realm); Set<Predicate> getRegistrationMessagePredicatesFor(String realm); Set<Predicate> getAuthenticationMessagePredicatesFor(String realm);  }### Answer:
@Test public void shouldSendMessage() throws PushNotificationException { PushMessage pushMessage = new PushMessage("identity", "message", "subject", null); notificationService.send(pushMessage, "realm"); verify(mockDelegate, times(1)).send(pushMessage); }
@Test (expectedExceptions = PushNotificationException.class) public void shouldErrorIfRealmNotInitiated() throws PushNotificationException { PushMessage pushMessage = new PushMessage("identity", "message", "subject", null); given(mockHelper.getFactoryClass()) .willReturn("org.forgerock.openam.services.push.PushNotificationServiceTest$TestDelegateFactory"); notificationService.send(pushMessage, "realm2"); }
@Test (expectedExceptions = PushNotificationException.class) public void shouldFailWhenDelegateCannotLoad() throws PushNotificationException { PushMessage pushMessage = new PushMessage("identity", "message", "subject", null); given(mockHelper.getFactoryClass()).willReturn("invalid factory"); notificationService.send(pushMessage, "realm2"); }
@Test (expectedExceptions = PushNotificationException.class) public void shouldFailWhenConfigNotFound() throws PushNotificationException { PushMessage pushMessage = new PushMessage("identity", "message", "subject", null); notificationService.send(pushMessage, "realm4"); }
@Test (expectedExceptions = PushNotificationException.class) public void shouldFailWhenDelegateFactoryIsBroken() throws PushNotificationException { PushMessage pushMessage = new PushMessage("identity", "message", "subject", null); given(mockHelper.getFactoryClass()) .willReturn("org.forgerock.openam.services.push.PushNotificationServiceTest$TestBrokenDelegateFactory"); notificationService.send(pushMessage, "realm2"); }
@Test (expectedExceptions = PushNotificationException.class) public void shouldFailWhenConfigCannotBeCreated() throws PushNotificationException { PushMessage pushMessage = new PushMessage("identity", "message", "subject", null); given(mockHelper.getFactoryClass()) .willReturn("org.forgerock.openam.services.push.PushNotificationServiceTest$TestDelegateFactory"); given(mockHelper.getConfig()).willThrow(new PushNotificationException("Build sanity check failed")); notificationService.send(pushMessage, "realm2"); }