Assert instances (vs classes) in MockMvc/WebTestClient
Issue: SPR-16520
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -56,16 +56,21 @@ class DefaultControllerSpec extends AbstractMockServerSpec<WebTestClient.Control
|
||||
|
||||
DefaultControllerSpec(Object... controllers) {
|
||||
Assert.isTrue(!ObjectUtils.isEmpty(controllers), "At least one controller is required");
|
||||
Assert.isTrue(checkInstances(controllers), "Controller instances are required");
|
||||
this.controllers = Arrays.asList(controllers);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public DefaultControllerSpec controllerAdvice(Object... controllerAdvice) {
|
||||
Assert.isTrue(checkInstances(controllerAdvice), "ControllerAdvice instances are required");
|
||||
this.controllerAdvice.addAll(Arrays.asList(controllerAdvice));
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean checkInstances(Object[] objects) {
|
||||
return Arrays.stream(objects).noneMatch(Class.class::isInstance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DefaultControllerSpec contentTypeResolver(Consumer<RequestedContentTypeResolverBuilder> consumer) {
|
||||
this.configurer.contentTypeResolverConsumer = consumer;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -143,6 +143,7 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
|
||||
*/
|
||||
protected StandaloneMockMvcBuilder(Object... controllers) {
|
||||
Assert.isTrue(!ObjectUtils.isEmpty(controllers), "At least one controller is required");
|
||||
Assert.isTrue(checkInstances(controllers), "Controller instances are required");
|
||||
this.controllers = Arrays.asList(controllers);
|
||||
}
|
||||
|
||||
@@ -157,10 +158,15 @@ public class StandaloneMockMvcBuilder extends AbstractMockMvcBuilder<StandaloneM
|
||||
* @since 4.2
|
||||
*/
|
||||
public StandaloneMockMvcBuilder setControllerAdvice(Object... controllerAdvice) {
|
||||
Assert.isTrue(checkInstances(controllerAdvice), "ControllerAdvice instances are required");
|
||||
this.controllerAdvice = Arrays.asList(controllerAdvice);
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean checkInstances(Object[] objects) {
|
||||
return Arrays.stream(objects).noneMatch(Class.class::isInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the message converters to use in argument resolvers and in return value
|
||||
* handlers, which support reading and/or writing to the body of the request
|
||||
|
||||
Reference in New Issue
Block a user