@Test public void test_should_save_new_token_with_given_identity_and_tenant() { final Token savedToken = Token.builder().build(); final TokenRequest tokenRequest = mock(TokenRequest.class); when(tokenRepository.save(any(Token.class))).thenReturn(savedToken); final Token actualToken = tokenService.create(tokenRequest); assertEquals(savedToken, actualToken); }
public Token create(TokenRequest tokenRequest) { tokenRequest.validate(); Token token = Token.builder().uuid(UUID.randomUUID().toString()).tenantId(tokenRequest.getTenantId()) .identity(tokenRequest.getIdentity()).number(randomNumeric(otpLength)) .timeToLiveInSeconds(tokenRequest.getTimeToLive()).build(); return tokenRepository.save(token); }
TokenService { public Token create(TokenRequest tokenRequest) { tokenRequest.validate(); Token token = Token.builder().uuid(UUID.randomUUID().toString()).tenantId(tokenRequest.getTenantId()) .identity(tokenRequest.getIdentity()).number(randomNumeric(otpLength)) .timeToLiveInSeconds(tokenRequest.getTimeToLive()).build(); return tokenRepository.save(token); } }
TokenService { public Token create(TokenRequest tokenRequest) { tokenRequest.validate(); Token token = Token.builder().uuid(UUID.randomUUID().toString()).tenantId(tokenRequest.getTenantId()) .identity(tokenRequest.getIdentity()).number(randomNumeric(otpLength)) .timeToLiveInSeconds(tokenRequest.getTimeToLive()).build(); return tokenRepository.save(token); } @Autowired  TokenService(TokenRepository tokenRepository); }
TokenService { public Token create(TokenRequest tokenRequest) { tokenRequest.validate(); Token token = Token.builder().uuid(UUID.randomUUID().toString()).tenantId(tokenRequest.getTenantId()) .identity(tokenRequest.getIdentity()).number(randomNumeric(otpLength)) .timeToLiveInSeconds(tokenRequest.getTimeToLive()).build(); return tokenRepository.save(token); } @Autowired  TokenService(TokenRepository tokenRepository); Token create(TokenRequest tokenRequest); Token validate(ValidateRequest validateRequest); Token search(TokenSearchCriteria searchCriteria); }
TokenService { public Token create(TokenRequest tokenRequest) { tokenRequest.validate(); Token token = Token.builder().uuid(UUID.randomUUID().toString()).tenantId(tokenRequest.getTenantId()) .identity(tokenRequest.getIdentity()).number(randomNumeric(otpLength)) .timeToLiveInSeconds(tokenRequest.getTimeToLive()).build(); return tokenRepository.save(token); } @Autowired  TokenService(TokenRepository tokenRepository); Token create(TokenRequest tokenRequest); Token validate(ValidateRequest validateRequest); Token search(TokenSearchCriteria searchCriteria);  }