diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-12-20 18:38:08 +0100 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2021-12-21 01:18:09 +0100 |
commit | e8f31cbe437ee969f4dd0490a0409b62b2fd045d (patch) | |
tree | 694203ae0423448b259c924c167ecb5584c36229 /jdisc-security-filters | |
parent | 5d6f586ccff9880a40366d51f75db5234795c0fc (diff) |
GC deprecated junit assertThat.
Diffstat (limited to 'jdisc-security-filters')
3 files changed, 23 insertions, 29 deletions
diff --git a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzAuthorizationFilterTest.java b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzAuthorizationFilterTest.java index 8be552c1da0..63223f3c221 100644 --- a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzAuthorizationFilterTest.java +++ b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzAuthorizationFilterTest.java @@ -39,14 +39,10 @@ import static com.yahoo.jdisc.http.filter.security.athenz.AthenzAuthorizationFil import static com.yahoo.security.SignatureAlgorithm.SHA256_WITH_ECDSA; import static com.yahoo.security.SubjectAlternativeName.Type.RFC822_NAME; import static com.yahoo.vespa.athenz.zpe.AuthorizationResult.Type; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.hasItem; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; @@ -240,13 +236,13 @@ public class AthenzAuthorizationFilterTest { } private void assertMetrics(MetricMock metric, String metricName, Map<String, String> dimensions) { - assertThat(metric.addInvocations.keySet(), hasItem(metricName)); + assertTrue(metric.addInvocations.keySet().contains(metricName)); SimpleMetricContext metricContext = metric.addInvocations.get(metricName); assertNotNull("Metric not found " + metricName, metricName); for (Map.Entry<String, String> entry : dimensions.entrySet()) { String dimensionName = entry.getKey(); String expected = entry.getValue(); - assertThat(metricContext.dimensions.keySet(), hasItem(dimensionName)); + assertTrue(metricContext.dimensions.keySet().contains(dimensionName)); assertEquals(expected, metricContext.dimensions.get(dimensionName)); } } @@ -307,8 +303,8 @@ public class AthenzAuthorizationFilterTest { private static void assertStatusCode(MockResponseHandler responseHandler, int statusCode) { Response response = responseHandler.getResponse(); - assertThat(response, notNullValue()); - assertThat(response.getStatus(), equalTo(statusCode)); + assertNotNull(response); + assertEquals(statusCode, response.getStatus()); } private static void assertMatchedCredentialType(DiscFilterRequest request, EnabledCredentials.Enum expectedType) { @@ -316,7 +312,7 @@ public class AthenzAuthorizationFilterTest { } private static void assertRequestNotFiltered(MockResponseHandler responseHandler) { - assertThat(responseHandler.getResponse(), nullValue()); + assertNull(responseHandler.getResponse()); } private static void assertMatchedRole(DiscFilterRequest request, AthenzRole role) { @@ -325,9 +321,9 @@ public class AthenzAuthorizationFilterTest { private static void assertErrorMessage(MockResponseHandler responseHandler, String errorMessage) { Response response = responseHandler.getResponse(); - assertThat(response, notNullValue()); + assertNotNull(response); String content = responseHandler.readAll(); - assertThat(content, containsString(errorMessage)); + assertTrue(content.contains(errorMessage)); } private static class AllowingZpe implements Zpe { diff --git a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzPrincipalFilterTest.java b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzPrincipalFilterTest.java index 23b1b7c569e..d670c969e5c 100644 --- a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzPrincipalFilterTest.java +++ b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/athenz/AthenzPrincipalFilterTest.java @@ -31,11 +31,10 @@ import static com.yahoo.security.SignatureAlgorithm.SHA256_WITH_ECDSA; import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static java.util.stream.Collectors.joining; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -91,7 +90,7 @@ public class AthenzPrincipalFilterTest { AthenzPrincipalFilter filter = createFilter(true); filter.filter(request, responseHandler); - assertThat(responseHandler.response, nullValue()); + assertNull(responseHandler.response); } private DiscFilterRequest createRequestMock() { @@ -103,9 +102,9 @@ public class AthenzPrincipalFilterTest { } private static void assertUnauthorized(DiscFilterRequest request, ResponseHandlerMock responseHandler, String expectedMessageSubstring) { - assertThat(responseHandler.response, notNullValue()); - assertThat(responseHandler.response.getStatus(), equalTo(UNAUTHORIZED)); - assertThat(responseHandler.getResponseContent(), containsString(expectedMessageSubstring)); + assertNotNull(responseHandler.response); + assertEquals(UNAUTHORIZED, responseHandler.response.getStatus()); + assertTrue(responseHandler.getResponseContent().contains(expectedMessageSubstring)); verify(request).setAttribute(AthenzPrincipalFilter.RESULT_ERROR_CODE_ATTRIBUTE, UNAUTHORIZED); } diff --git a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/base/JsonSecurityRequestFilterBaseTest.java b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/base/JsonSecurityRequestFilterBaseTest.java index a2746e84e1c..0f5512a6ec5 100644 --- a/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/base/JsonSecurityRequestFilterBaseTest.java +++ b/jdisc-security-filters/src/test/java/com/yahoo/jdisc/http/filter/security/base/JsonSecurityRequestFilterBaseTest.java @@ -11,9 +11,8 @@ import org.junit.Test; import java.io.IOException; import java.util.Optional; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.mock; /** @@ -34,12 +33,12 @@ public class JsonSecurityRequestFilterBaseTest { filter.filter(request, responseHandler); Response response = responseHandler.getResponse(); - assertThat(response, notNullValue()); - assertThat(response.getStatus(), equalTo(statusCode)); + assertNotNull(response); + assertEquals(statusCode, response.getStatus()); JsonNode jsonNode = mapper.readTree(responseHandler.readAll()); - assertThat(jsonNode.get("message").asText(), equalTo(message)); - assertThat(jsonNode.get("code").asInt(), equalTo(statusCode)); + assertEquals(message, jsonNode.get("message").asText()); + assertEquals(statusCode, jsonNode.get("code").asInt()); } private static class SimpleSecurityRequestFilter extends JsonSecurityRequestFilterBase { |