Skip to content

Commit

Permalink
Tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
dukris committed Jan 19, 2024
1 parent f8bad0d commit 19e768c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
13 changes: 2 additions & 11 deletions src/test/java/git/tracehub/pmo/security/ClaimOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;

/**
* Test suite for {@link ClaimOf}.
Expand All @@ -36,12 +35,6 @@
@ExtendWith(MockitoExtension.class)
final class ClaimOfTest {

/**
* Token.
*/
@Mock
private JwtAuthenticationToken token;

/**
* JWT.
*/
Expand All @@ -51,9 +44,8 @@ final class ClaimOfTest {
@Test
void returnsValueWhenClaimExists() {
final String value = "value";
Mockito.when(this.token.getCredentials()).thenReturn(this.jwt);
Mockito.when(this.jwt.getClaim("claim")).thenReturn(value);
final String claim = new ClaimOf(this.token, "claim").value();
final String claim = new ClaimOf(this.jwt, "claim").value();
MatcherAssert.assertThat(
"Claim value %s is not %s".formatted(claim, value),
claim,
Expand All @@ -63,9 +55,8 @@ void returnsValueWhenClaimExists() {

@Test
void returnsValueWhenClaimDoesNotExist() {
Mockito.when(this.token.getCredentials()).thenReturn(this.jwt);
Mockito.when(this.jwt.getClaim("claim")).thenReturn(null);
final String claim = new ClaimOf(this.token, "claim").value();
final String claim = new ClaimOf(this.jwt, "claim").value();
MatcherAssert.assertThat(
"Claim value %s is not null".formatted(claim),
claim,
Expand Down
13 changes: 2 additions & 11 deletions src/test/java/git/tracehub/pmo/security/ExistsRoleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;

/**
* Test suite for {@link ExistsRole}.
Expand All @@ -38,12 +37,6 @@
@ExtendWith(MockitoExtension.class)
final class ExistsRoleTest {

/**
* Token.
*/
@Mock
private JwtAuthenticationToken token;

/**
* JWT.
*/
Expand All @@ -52,30 +45,28 @@ final class ExistsRoleTest {

@Test
void returnsTrueIfRoleExists() {
Mockito.when(this.token.getCredentials()).thenReturn(this.jwt);
Mockito.when(this.jwt.getClaimAsMap("realm_access")).thenReturn(
new MapOf<>(
new MapEntry<>("roles", new ListOf<>("role"))
)
);
MatcherAssert.assertThat(
"Role doesn't exist",
new ExistsRole(this.token, "role").value(),
new ExistsRole(this.jwt, "role").value(),
new IsEqual<>(true)
);
}

@Test
void returnsFalseIfRoleDoesNotExist() {
Mockito.when(this.token.getCredentials()).thenReturn(this.jwt);
Mockito.when(this.jwt.getClaimAsMap("realm_access")).thenReturn(
new MapOf<>(
new MapEntry<>("roles", new ListOf<>())
)
);
MatcherAssert.assertThat(
"Role exists",
new ExistsRole(this.token, "role").value(),
new ExistsRole(this.jwt, "role").value(),
new IsEqual<>(false)
);
}
Expand Down

0 comments on commit 19e768c

Please sign in to comment.