### Question:
UserDeviceServiceImpl implements UserDeviceService { @Nonnull @Override public UserDevice getUserDeviceById(@Nonnull final Long userDeviceId) { Assert.notNull(userDeviceId, "User device id should not be null"); LOGGER.debug("Retrieving user device for id - {}", userDeviceId); final UserDevice userDevice = userDeviceRepository.findById(userDeviceId).orElseThrow(() -> new UserDeviceNotFoundForIdException(userDeviceId)); LOGGER.debug("Successfully retrieved user device for id - {}, user device - {}", userDeviceId, userDevice); 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 testGetUserDeviceByIdWithInvalidArguments() { resetAll(); replayAll(); try { userDeviceService.getUserDeviceById(null); fail("Exception should be thrown"); } catch (final IllegalArgumentException ex) { } verifyAll(); }
@Test public void testGetUserDeviceByIdWithNotExistingId() { final Long deviceId = 1L; resetAll(); expect(userDeviceRepository.findById(eq(deviceId))).andReturn(Optional.empty()).once(); replayAll(); try { userDeviceService.getUserDeviceById(deviceId); fail("Exception should be thrown"); } catch (final UserDeviceNotFoundForIdException ex) { assertUserDeviceNotFoundForIdException(ex, deviceId); } verifyAll(); }
@Test public void testGetUserDeviceById() { final Long deviceId = 1L; final UserDevice userDevice = getServicesImplTestHelper().createUserDevice(); userDevice.setId(deviceId); resetAll(); expect(userDeviceRepository.findById(eq(deviceId))).andReturn(Optional.of(userDevice)).once(); replayAll(); final UserDevice result = userDeviceService.getUserDeviceById(deviceId); assertEquals(userDevice, result); verifyAll(); }