### Question:
UserDeviceServiceImpl implements UserDeviceService { @Nonnull @Override public UserDevice getUserDeviceByUuId(@Nonnull final Long userId, @Nonnull final String uuId) { assertUserId(userId); assertUuIdNotNull(uuId); LOGGER.debug("Getting user device for user with id - {}, device uuid - {}", userId, uuId); final User user = userService.getUserById(userId); final UserDevice userDevice = userDeviceRepository.findByUserAndUuId(user, uuId); assertUserDeviceNotNullForUuId(userDevice, userId, uuId); LOGGER.debug("Successfully retrieved user device with id - {} for user with id - {}, device uuid - {}", userDevice.getId(), userId, uuId); return userDevice; } UserDeviceServiceImpl(); @Nonnull @Override UserDevice getUserDeviceById(@Nonnull final Long userDeviceId); @Transactional @Nonnull @Override UserDevice createUserDevice(@Nonnull final Long userId, @Nonnull final UserDeviceDto userDeviceDto); @Nonnull @Override UserDevice getUserDeviceByUuId(@Nonnull final Long userId, @Nonnull final String uuId); @Nonnull @Override boolean checkIfUserDeviceExistsForUuId(@Nonnull final Long userId, @Nonnull final String uuId); @Transactional @Nonnull @Override UserDevice getOrCreateUserDevice(@Nonnull final Long userId, @Nonnull final UserDeviceDto userDeviceDto); UserDeviceRepository getUserDeviceRepository(); void setUserDeviceRepository(final UserDeviceRepository userDeviceRepository);  }### Answer:
@Test public void testGetUserDeviceByUuIdWithNotExistingUuId() { final Long userId = 1L; final User user = getServicesImplTestHelper().createUser(); final String deviceUuId = "JBIYITCTUFFVIFIFOYFTII"; resetAll(); expect(userService.getUserById(eq(userId))).andReturn(user).once(); expect(userDeviceRepository.findByUserAndUuId(eq(user), eq(deviceUuId))).andReturn(null).once(); replayAll(); try { userDeviceService.getUserDeviceByUuId(userId, deviceUuId); fail("Exception should be thrown"); } catch (final UserDeviceNotFoundForUuIdException ex) { assertUserDeviceNotFoundForUuIdException(ex, userId, deviceUuId); } verifyAll(); }
@Test public void testGetUserDeviceByUuId() { final Long userId = 1L; final User user = getServicesImplTestHelper().createUser(); final Long deviceId = 2L; final UserDevice userDevice = getServicesImplTestHelper().createUserDevice(); userDevice.setId(deviceId); final String deviceUuId = userDevice.getUuId(); resetAll(); expect(userService.getUserById(eq(userId))).andReturn(user).once(); expect(userDeviceRepository.findByUserAndUuId(eq(user), eq(deviceUuId))).andReturn(userDevice).once(); replayAll(); final UserDevice result = userDeviceService.getUserDeviceByUuId(userId, deviceUuId); assertEquals(userDevice, result); verifyAll(); }
@Test public void testGetUserDeviceByUuIdWithInvalidArguments() { final Long userId = 1L; final String deviceUuId = "JBIYITCTUFFVIFIFOYFTII"; resetAll(); replayAll(); try { userDeviceService.getUserDeviceByUuId(null, deviceUuId); fail("Exception should be thrown"); } catch (final IllegalArgumentException ex) { } try { userDeviceService.getUserDeviceByUuId(userId, null); fail("Exception should be thrown"); } catch (final IllegalArgumentException ex) { } verifyAll(); }