@Test public void should_check_token() { when(accountRepository.findByToken("token")).thenReturn(new Account().setTokenExpiration(LocalDateTime.now().plus(Duration.ofHours(1)))); assertThat(tokenService.checkToken("token")).isNotNull(); }
public Account checkToken(String token) { Account account = accountRepository.findByToken(token); if (account == null) { throw new InvalidTokenException(); } if (account.getTokenExpiration() == null || LocalDateTime.now().minus(Duration.ofHours(3)).compareTo(account.getTokenExpiration()) > 0) { throw new ExpiredTokenException(); } return account; }
TokenService { public Account checkToken(String token) { Account account = accountRepository.findByToken(token); if (account == null) { throw new InvalidTokenException(); } if (account.getTokenExpiration() == null || LocalDateTime.now().minus(Duration.ofHours(3)).compareTo(account.getTokenExpiration()) > 0) { throw new ExpiredTokenException(); } return account; } }
TokenService { public Account checkToken(String token) { Account account = accountRepository.findByToken(token); if (account == null) { throw new InvalidTokenException(); } if (account.getTokenExpiration() == null || LocalDateTime.now().minus(Duration.ofHours(3)).compareTo(account.getTokenExpiration()) > 0) { throw new ExpiredTokenException(); } return account; }  }
TokenService { public Account checkToken(String token) { Account account = accountRepository.findByToken(token); if (account == null) { throw new InvalidTokenException(); } if (account.getTokenExpiration() == null || LocalDateTime.now().minus(Duration.ofHours(3)).compareTo(account.getTokenExpiration()) > 0) { throw new ExpiredTokenException(); } return account; }  void generateNewToken(Account account); void reinitTokenValidity(Account account); Account checkToken(String token); Account getCredentialsForToken(String token); Member tryToLinkWithActualMember(Account account); }
TokenService { public Account checkToken(String token) { Account account = accountRepository.findByToken(token); if (account == null) { throw new InvalidTokenException(); } if (account.getTokenExpiration() == null || LocalDateTime.now().minus(Duration.ofHours(3)).compareTo(account.getTokenExpiration()) > 0) { throw new ExpiredTokenException(); } return account; }  void generateNewToken(Account account); void reinitTokenValidity(Account account); Account checkToken(String token); Account getCredentialsForToken(String token); Member tryToLinkWithActualMember(Account account);  }