### Question:
AbstractUserTokenService extends AbstractTokenService<E, D> { @Override @Transactional(readOnly = true) public void validateToken(E userToken) throws Exception { super.validateToken(userToken); if (userToken.getUser() == null) { throw new Exception("There is no user associated with this token."); } } @SuppressWarnings("unchecked")  AbstractUserTokenService(); protected  AbstractUserTokenService(Class<E> entityClass); @Transactional(readOnly = true) E findByUser(User user); @Override @Transactional(readOnly = true) void validateToken(E userToken);  }### Answer:
@Test public void validateToken_shouldSuccessfullyValidate() throws Exception { crudService.validateToken(implToTest); assertNotNull(implToTest); }
@Test public void validateToken_shouldThrowIfTokenIsNull() { try { crudService.validateToken(null); fail("Should have thrown Exception, but did not!"); } catch (Exception e) { final String msg = e.getMessage(); assertEquals(msg, "The provided token is null."); } }
@Test public void validateToken_shouldThrowIfTokenExpired() { final E expiredUserToken = getExpiredUserToken(); try { crudService.validateToken(expiredUserToken); fail("Should have thrown Exception, but did not!"); } catch (Exception e) { final String msg = e.getMessage(); assertEquals(msg, "The token '" + expiredUserToken.getToken() + "' expired on '" + expiredUserToken.getExpirationDate() + "'"); } }
@Test public void validateToken_shouldThrowIfTokenHasNoAssociatedUser() { final E expiredUserToken = getUserTokenWithoutUser(); try { crudService.validateToken(expiredUserToken); fail("Should have thrown Exception, but did not!"); } catch (Exception e) { final String msg = e.getMessage(); assertEquals(msg, "There is no user associated with this token."); } }