### Question:
PushNotificationSubscriptionServiceImpl implements PushNotificationSubscriptionService { @Nonnull @Override public PushNotificationSubscription getPushNotificationSubscriptionForUser(@Nonnull final Long userId) { assertUserIdNotNull(userId); LOGGER.debug("Getting push notification subscription for user with id - {}", userId); final User user = userService.getUserById(userId); final PushNotificationSubscription subscription = pushNotificationSubscriptionRepository.findByUser(user); assertPushNotificationSubscriptionNotNullForUser(subscription, user); LOGGER.debug("Successfully retrieved push notification subscription for user with id - {}, subscription - {}", user.getId(), subscription); return subscription; } PushNotificationSubscriptionServiceImpl(); @Nonnull @Override boolean checkIfPushNotificationSubscriptionExistsForUser(@Nonnull final Long userId); @Nonnull @Override PushNotificationSubscription getPushNotificationSubscriptionForUser(@Nonnull final Long userId); @Transactional @Nonnull @Override PushNotificationSubscription createPushNotificationSubscription(@Nonnull final Long userId, @Nonnull final PushNotificationSubscriptionDto subscriptionDto); @Nonnull @Override PushNotificationSubscription getPushNotificationSubscriptionById(@Nonnull final Long subscriptionId); PushNotificationSubscriptionRepository getPushNotificationSubscriptionRepository(); void setPushNotificationSubscriptionRepository(final PushNotificationSubscriptionRepository pushNotificationSubscriptionRepository); UserService getUserService(); void setUserService(final UserService userService);  }### Answer:
@Test public void testGetPushNotificationSubscriptionForUserWithInvalidArguments() { resetAll(); replayAll(); try { pushNotificationSubscriptionService.getPushNotificationSubscriptionForUser(null); fail("Exception should be thrown"); } catch (final IllegalArgumentException ex) { } verifyAll(); }
@Test public void testGetPushNotificationSubscriptionForUserWhenNoSubscriptionExists() { final Long userId = 1L; final User user = getServicesImplTestHelper().createUser(); user.setId(userId); resetAll(); expect(userService.getUserById(eq(userId))).andReturn(user).once(); expect(pushNotificationSubscriptionRepository.findByUser(eq(user))).andReturn(null).once(); replayAll(); try { pushNotificationSubscriptionService.getPushNotificationSubscriptionForUser(userId); fail("Exception should be thrown"); } catch (final PushNotificationSubscriptionNotFoundForUserException ex) { assertPushNotificationSubscriptionNotFoundForUserException(ex, userId); } verifyAll(); }
@Test public void testGetPushNotificationSubscriptionForUser() { final Long userId = 1L; final User user = getServicesImplTestHelper().createUser(); user.setId(userId); final Long subscriptionId = 2L; final PushNotificationSubscription subscription = getServicesImplTestHelper().createPushNotificationSubscription(); subscription.setId(subscriptionId); resetAll(); expect(userService.getUserById(eq(userId))).andReturn(user).once(); expect(pushNotificationSubscriptionRepository.findByUser(eq(user))).andReturn(subscription).once(); replayAll(); final PushNotificationSubscription result = pushNotificationSubscriptionService.getPushNotificationSubscriptionForUser(userId); assertEquals(subscription, result); verifyAll(); }