Skip to content

Commit

Permalink
test: Fix deprecated mock usage (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
gazbert committed Nov 14, 2024
1 parent 7eae671 commit 95f64f1
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.Date;
import java.util.List;
import org.assertj.core.util.DateUtil;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand Down Expand Up @@ -87,20 +88,27 @@ class TestJwtUtils {
private static final Date LAST_PASSWORD_RESET_DATE_YESTERDAY = DateUtil.yesterday();
private static final List<String> ROLES = Arrays.asList("ROLE_ADMIN", "ROLE_USER");

private AutoCloseable autoCloseable;

@InjectMocks private JwtUtils jwtUtils;
@MockBean private Claims claims;

/** Setup for all tests. */
@BeforeEach
void init() {
MockitoAnnotations.initMocks(this);
autoCloseable = MockitoAnnotations.openMocks(this);
ReflectionTestUtils.setField(jwtUtils, "expirationInSecs", EXPIRATION_PERIOD);
ReflectionTestUtils.setField(jwtUtils, "secret", SECRET_KEY);
ReflectionTestUtils.setField(jwtUtils, "allowedClockSkewInSecs", ALLOWED_CLOCK_SKEW_IN_SECS);
ReflectionTestUtils.setField(jwtUtils, "issuer", ISSUER);
ReflectionTestUtils.setField(jwtUtils, "audience", AUDIENCE);
}

@AfterEach
public void releaseMocks() throws Exception {
autoCloseable.close();
}

// ------------------------------------------------------------------------
// JWT Claims tests
// ------------------------------------------------------------------------
Expand Down

0 comments on commit 95f64f1

Please sign in to comment.