TokenService { public void generateNewToken(Account account) { Objects.requireNonNull(account); Objects.requireNonNull(account.getOauthId()); account.setToken(UUID.randomUUID().toString()); reinitTokenValidity(account); }  void generateNewToken(Account account); void reinitTokenValidity(Account account); Account checkToken(String token); Account getCredentialsForToken(String token); Member tryToLinkWithActualMember(Account account);  }
@Test(expected = NullPointerException.class) public void should_not_generate_token_when_account_is_null() { tokenService.generateNewToken(null); }
@Test(expected = NullPointerException.class) public void should_not_generate_token_when_oauthid_is_null() { tokenService.generateNewToken(new Account()); }
@Test public void should_generate_token() { Account account = new Account().setOauthId("anOAUTHID"); tokenService.generateNewToken(account); assertThat(account.getToken()).isNotEmpty(); }
@Test public void should_generate_token_with_an_expiration_date_in_3_hour() { Account account = new Account().setOauthId("anOAUTHID"); tokenService.generateNewToken(account); assertThat(account.getTokenExpiration()).isNotNull().isAfter(LocalDateTime.now().minus(Duration.ofDays(3))); }