User Assert4J
This commit is contained in:
@@ -31,7 +31,6 @@ import java.util.stream.Stream;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import reactor.retry.Repeat;
|
||||
import reactor.retry.Retry;
|
||||
|
||||
@@ -84,6 +83,7 @@ import org.springframework.cloud.gateway.filter.factory.rewrite.RewriteFunction;
|
||||
import org.springframework.cloud.gateway.filter.ratelimit.RateLimiter;
|
||||
import org.springframework.cloud.gateway.route.Route;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.util.unit.DataSize;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
@@ -26,7 +26,6 @@ import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.assertj.core.util.Maps;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -200,7 +199,7 @@ public class GatewayControllerEndpointTests {
|
||||
.expectBody(ResponseEntity.class)
|
||||
.consumeWith(result -> {
|
||||
HttpStatusCode httpStatus = result.getStatus();
|
||||
Assertions.assertEquals(HttpStatus.OK, httpStatus);
|
||||
assertThat(HttpStatus.OK).isEqualTo(httpStatus);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.cloud.gateway.filter;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import reactor.core.publisher.Mono;
|
||||
@@ -32,6 +31,7 @@ import org.springframework.web.server.ServerWebExchange;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
@@ -64,7 +64,7 @@ public class RouteToRequestUrlFilterTests {
|
||||
|
||||
@Test
|
||||
public void invalidHost() {
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> {
|
||||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.get("http://localhost/getb").build();
|
||||
testFilter(request, "lb://my_host");
|
||||
});
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.cloud.gateway.filter.ratelimit;
|
||||
|
||||
import io.lettuce.core.RedisException;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -32,6 +31,7 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.data.MapEntry.entry;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
@@ -78,7 +78,8 @@ public class RedisRateLimiterUnitTests {
|
||||
|
||||
@Test
|
||||
public void shouldThrowWhenNotInitialized() {
|
||||
Assertions.assertThrows(IllegalStateException.class, () -> redisRateLimiter.isAllowed(ROUTE_ID, REQUEST_ID));
|
||||
assertThatExceptionOfType(IllegalStateException.class)
|
||||
.isThrownBy(() -> redisRateLimiter.isAllowed(ROUTE_ID, REQUEST_ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -18,13 +18,14 @@ package org.springframework.cloud.gateway.handler;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class AsyncPredicateTest {
|
||||
|
||||
@Test
|
||||
@@ -110,12 +111,12 @@ public class AsyncPredicateTest {
|
||||
|
||||
@DisplayName("predicate must have been tested")
|
||||
public void assertTested() {
|
||||
Assertions.assertTrue(tested);
|
||||
assertThat(tested).isTrue();
|
||||
}
|
||||
|
||||
@DisplayName("predicate must not have been tested")
|
||||
public void assertUntested() {
|
||||
Assertions.assertFalse(tested);
|
||||
assertThat(tested).isFalse();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.gateway.handler;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mockito;
|
||||
@@ -32,6 +31,8 @@ import org.springframework.cloud.gateway.route.RouteLocator;
|
||||
import org.springframework.mock.env.MockEnvironment;
|
||||
import org.springframework.web.server.ServerWebExchange;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Simon Baslé
|
||||
*/
|
||||
@@ -57,8 +58,8 @@ public class RoutePredicateHandlerMappingTests {
|
||||
final Mono<Route> routeMono = mapping.lookupRoute(Mockito.mock(ServerWebExchange.class));
|
||||
|
||||
StepVerifier.create(routeMono.map(Route::getId)).expectNext("routeTrue").verifyComplete();
|
||||
Assertions.assertTrue(capturedOutput.getOut().contains("Error applying predicate for route: routeFail"));
|
||||
Assertions.assertTrue(capturedOutput.getOut().contains("java.lang.IllegalStateException: boom"));
|
||||
assertThat(capturedOutput.getOut().contains("Error applying predicate for route: routeFail")).isTrue();
|
||||
assertThat(capturedOutput.getOut().contains("java.lang.IllegalStateException: boom")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,11 +90,11 @@ public class RoutePredicateHandlerMappingTests {
|
||||
|
||||
StepVerifier.create(routeMono.map(Route::getId)).expectNext("routeTrue").verifyComplete();
|
||||
|
||||
Assertions.assertTrue(capturedOutput.getOut().contains("Error applying predicate for route: routeError"));
|
||||
Assertions.assertTrue(capturedOutput.getOut().contains("java.lang.IllegalStateException: boom1"));
|
||||
assertThat(capturedOutput.getOut().contains("Error applying predicate for route: routeError")).isTrue();
|
||||
assertThat(capturedOutput.getOut().contains("java.lang.IllegalStateException: boom1")).isTrue();
|
||||
|
||||
Assertions.assertTrue(capturedOutput.getOut().contains("Error applying predicate for route: routeFail"));
|
||||
Assertions.assertTrue(capturedOutput.getOut().contains("java.lang.IllegalStateException: boom2"));
|
||||
assertThat(capturedOutput.getOut().contains("Error applying predicate for route: routeFail")).isTrue();
|
||||
assertThat(capturedOutput.getOut().contains("java.lang.IllegalStateException: boom2")).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import jakarta.validation.constraints.Max;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.context.properties.bind.BindException;
|
||||
@@ -30,6 +29,7 @@ import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
public class ConfigurationServiceTests {
|
||||
|
||||
@@ -37,7 +37,7 @@ public class ConfigurationServiceTests {
|
||||
public void validationOnCreateWorks() {
|
||||
Map<String, Object> map = Collections.singletonMap("config.value", 11);
|
||||
|
||||
Assertions.assertThrows(BindException.class, () -> ConfigurationService
|
||||
assertThatExceptionOfType(BindException.class).isThrownBy(() -> ConfigurationService
|
||||
.bindOrCreate(Bindable.of(ValidatedConfig.class), map, "config", getValidator(), null));
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ConfigurationServiceTests {
|
||||
|
||||
ValidatedConfig config = new ValidatedConfig();
|
||||
|
||||
Assertions.assertThrows(BindException.class, () -> ConfigurationService
|
||||
assertThatExceptionOfType(BindException.class).isThrownBy(() -> ConfigurationService
|
||||
.bindOrCreate(Bindable.ofInstance(config), map, "config", getValidator(), null));
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.cloud.gateway.test;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.DisabledForJreRange;
|
||||
@@ -24,6 +23,8 @@ import org.junit.jupiter.api.condition.JRE;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* @author Tim Ysewyn
|
||||
*/
|
||||
@@ -34,7 +35,7 @@ public class CustomBlockHoundIntegrationTest {
|
||||
// Disable this test for now flaky on GitHub Actions
|
||||
@Disabled
|
||||
public void shouldThrowErrorForBlockingCallWithCustomBlockHoundIntegration() {
|
||||
Assertions.assertThrows(RuntimeException.class, () -> Mono.fromCallable(() -> {
|
||||
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> Mono.fromCallable(() -> {
|
||||
Thread.sleep(1);
|
||||
return null;
|
||||
}).subscribeOn(Schedulers.parallel()).block());
|
||||
|
||||
Reference in New Issue
Block a user