Use noNullElements
Collection#contains(null) does not work for all collection types Issue gh-10703
This commit is contained in:
parent
e20449a542
commit
b2fe9149cf
|
@ -66,7 +66,7 @@ public class MediaTypeServerWebExchangeMatcher implements ServerWebExchangeMatch
|
||||||
*/
|
*/
|
||||||
public MediaTypeServerWebExchangeMatcher(Collection<MediaType> matchingMediaTypes) {
|
public MediaTypeServerWebExchangeMatcher(Collection<MediaType> matchingMediaTypes) {
|
||||||
Assert.notEmpty(matchingMediaTypes, "matchingMediaTypes cannot be null");
|
Assert.notEmpty(matchingMediaTypes, "matchingMediaTypes cannot be null");
|
||||||
Assert.isTrue(!matchingMediaTypes.contains(null),
|
Assert.noNullElements(matchingMediaTypes,
|
||||||
() -> "matchingMediaTypes cannot contain null. Got " + matchingMediaTypes);
|
() -> "matchingMediaTypes cannot contain null. Got " + matchingMediaTypes);
|
||||||
this.matchingMediaTypes = matchingMediaTypes;
|
this.matchingMediaTypes = matchingMediaTypes;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public final class AndRequestMatcher implements RequestMatcher {
|
||||||
*/
|
*/
|
||||||
public AndRequestMatcher(List<RequestMatcher> requestMatchers) {
|
public AndRequestMatcher(List<RequestMatcher> requestMatchers) {
|
||||||
Assert.notEmpty(requestMatchers, "requestMatchers must contain a value");
|
Assert.notEmpty(requestMatchers, "requestMatchers must contain a value");
|
||||||
Assert.isTrue(!requestMatchers.contains(null), "requestMatchers cannot contain null values");
|
Assert.noNullElements(requestMatchers, "requestMatchers cannot contain null values");
|
||||||
this.requestMatchers = requestMatchers;
|
this.requestMatchers = requestMatchers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ public final class OrRequestMatcher implements RequestMatcher {
|
||||||
*/
|
*/
|
||||||
public OrRequestMatcher(List<RequestMatcher> requestMatchers) {
|
public OrRequestMatcher(List<RequestMatcher> requestMatchers) {
|
||||||
Assert.notEmpty(requestMatchers, "requestMatchers must contain a value");
|
Assert.notEmpty(requestMatchers, "requestMatchers must contain a value");
|
||||||
Assert.isTrue(!requestMatchers.contains(null), "requestMatchers cannot contain null values");
|
Assert.noNullElements(requestMatchers, "requestMatchers cannot contain null values");
|
||||||
this.requestMatchers = requestMatchers;
|
this.requestMatchers = requestMatchers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,11 @@ public class MediaTypeServerWebExchangeMatcherTests {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> new MediaTypeServerWebExchangeMatcher(types));
|
assertThatIllegalArgumentException().isThrownBy(() -> new MediaTypeServerWebExchangeMatcher(types));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void constructorListOfDoesNotThrowNullPointerException() {
|
||||||
|
new MediaTypeServerWebExchangeMatcher(List.of(MediaType.ALL));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void constructorMediaTypeArrayWhenContainsNullThenThrowsIllegalArgumentException() {
|
public void constructorMediaTypeArrayWhenContainsNullThenThrowsIllegalArgumentException() {
|
||||||
MediaType[] types = { null };
|
MediaType[] types = { null };
|
||||||
|
|
|
@ -55,6 +55,11 @@ public class AndRequestMatcherTests {
|
||||||
assertThatNullPointerException().isThrownBy(() -> new AndRequestMatcher((RequestMatcher[]) null));
|
assertThatNullPointerException().isThrownBy(() -> new AndRequestMatcher((RequestMatcher[]) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void constructorListOfDoesNotThrowNullPointer() {
|
||||||
|
new AndRequestMatcher(List.of(new AntPathRequestMatcher("/test")));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void constructorArrayContainsNull() {
|
public void constructorArrayContainsNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> new AndRequestMatcher((RequestMatcher) null));
|
assertThatIllegalArgumentException().isThrownBy(() -> new AndRequestMatcher((RequestMatcher) null));
|
||||||
|
|
|
@ -55,6 +55,11 @@ public class OrRequestMatcherTests {
|
||||||
assertThatNullPointerException().isThrownBy(() -> new OrRequestMatcher((RequestMatcher[]) null));
|
assertThatNullPointerException().isThrownBy(() -> new OrRequestMatcher((RequestMatcher[]) null));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void constructorListOfDoesNotThrowNullPointer() {
|
||||||
|
new OrRequestMatcher(List.of(new AntPathRequestMatcher("/test")));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void constructorArrayContainsNull() {
|
public void constructorArrayContainsNull() {
|
||||||
assertThatIllegalArgumentException().isThrownBy(() -> new OrRequestMatcher((RequestMatcher) null));
|
assertThatIllegalArgumentException().isThrownBy(() -> new OrRequestMatcher((RequestMatcher) null));
|
||||||
|
|
Loading…
Reference in New Issue