### Question:
PushNotificationServiceFacadeImpl extends AbstractNotificationServiceFacadeImpl implements PushNotificationServiceFacade { @Nonnull @Override public ResultResponseModel<CreatePushNotificationResponse> createPushNotifications(@Nonnull final CreatePushNotificationRequest request) { Assert.notNull(request, "Request should not be null"); logger.debug("Creating push notifications for request - {}", request); final List<ErrorResponseModel> errors = request.validateRequiredFields(); if (!errors.isEmpty()) { return new ResultResponseModel<>(errors); } final User user = getUserService().getOrCreateUserForUuId(request.getUserUuId()); final PushNotificationDto pushNotificationDto = new PushNotificationDto(request.getBody(), request.getSubject(), request.getClientIpAddress(), providerType); pushNotificationDto.setTemplateName(request.getTemplateName()); pushNotificationDto.setLocale(request.getLocale()); pushNotificationDto.setProperties(request.getProperties()); final List<PushNotification> pushNotifications = pushNotificationService.createNotificationsForUserActiveRecipients(user.getId(), pushNotificationDto); pushNotifications.forEach(pushNotification -> applicationEventDistributionService.publishAsynchronousEvent(new StartSendingNotificationEvent(pushNotification.getId()))); final List<PushNotificationModel> pushNotificationModels = pushNotifications.stream().map(PushNotificationServiceFacadeImpl::createPushNotificationModel).collect(Collectors.toCollection(ArrayList::new)); final CreatePushNotificationResponse response = new CreatePushNotificationResponse(pushNotificationModels); logger.debug("Successfully created push notification response - {} for request - {}", response, request); return new ResultResponseModel<>(response); } PushNotificationServiceFacadeImpl(); @Nonnull @Override ResultResponseModel<CreatePushNotificationResponse> createPushNotifications(@Nonnull final CreatePushNotificationRequest request); @Nonnull @Override ResultResponseModel<UpdatePushNotificationSubscriptionResponse> updatePushNotificationSubscription(@Nonnull final UpdatePushNotificationSubscriptionRequest request);  }### Answer:
@Test public void testCreatePushNotificationsWithInvalidArguments() { resetAll(); replayAll(); try { pushNotificationServiceFacade.createPushNotifications(null); fail("Exception should be thrown"); } catch (final IllegalArgumentException ex) { } verifyAll(); }
@Test public void testCreatePushNotificationsWithValidationErrors() { final CreatePushNotificationRequest request = new CreatePushNotificationRequest(); resetAll(); replayAll(); final ResultResponseModel<CreatePushNotificationResponse> result = pushNotificationServiceFacade.createPushNotifications(request); assertNotNull(result); assertNull(result.getResponse()); assertNotNull(result.getErrors()); assertErrorExists(result.getErrors(), ErrorType.NOTIFICATION_BODY_MISSING); assertErrorExists(result.getErrors(), ErrorType.NOTIFICATION_USER_MISSING); verifyAll(); }
@Test public void testCreatePushNotifications() { final CreatePushNotificationRequest request = getServiceFacadeImplTestHelper().createCreatePushNotificationRequest(); final Long userId = 1L; final User user = getServiceFacadeImplTestHelper().createUser(); user.setUuId(request.getUserUuId()); user.setId(userId); final PushNotificationDto pushNotificationDto = new PushNotificationDto(request.getBody(), request.getSubject(), request.getClientIpAddress()); pushNotificationDto.setProperties(request.getProperties()); final List<PushNotification> pushNotifications = createPushNotifications(10); resetAll(); expect(userService.getOrCreateUserForUuId(eq(user.getUuId()))).andReturn(user).once(); expect(pushNotificationService.createNotificationsForUserActiveRecipients(eq(user.getId()), eq(pushNotificationDto))).andReturn(pushNotifications).once(); pushNotifications.forEach(pushNotification -> { applicationEventDistributionService.publishAsynchronousEvent(eq(new StartSendingNotificationEvent(pushNotification.getId()))); expectLastCall().once(); }); replayAll(); final ResultResponseModel<CreatePushNotificationResponse> result = pushNotificationServiceFacade.createPushNotifications(request); assertNotNull(result); assertNotNull(result.getResponse()); assertEquals(0, result.getErrors().size()); final MutableInt counter = new MutableInt(0); result.getResponse().getNotifications().forEach(pushNotificationModel -> { getServiceFacadeImplTestHelper().assertPushNotificationModel(pushNotifications.get(counter.intValue()), pushNotificationModel); counter.increment(); }); verifyAll(); }