Polish contribution

See gh-31320
This commit is contained in:
Stéphane Nicoll 2023-09-27 08:58:11 +02:00
parent d6a105c151
commit 7a05d23597
4 changed files with 50 additions and 13 deletions

View File

@ -86,10 +86,7 @@ public final class ParamsRequestCondition extends AbstractRequestCondition<Param
*/
@Override
public ParamsRequestCondition combine(ParamsRequestCondition other) {
if (isEmpty() && other.isEmpty()) {
return this;
}
else if (other.isEmpty()) {
if (other.isEmpty()) {
return this;
}
else if (isEmpty()) {

View File

@ -28,7 +28,9 @@ import static org.springframework.web.testfixture.http.server.reactive.MockServe
/**
* Unit tests for {@link ParamsRequestCondition}.
*
* @author Rossen Stoyanchev
* @author Stephane Nicoll
*/
public class ParamsRequestConditionTests {
@ -42,43 +44,43 @@ public class ParamsRequestConditionTests {
}
@Test
public void paramPresent() throws Exception {
public void paramPresent() {
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=")))).isNotNull();
}
@Test // SPR-15831
public void paramPresentNullValue() throws Exception {
public void paramPresentNullValue() {
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo")))).isNotNull();
}
@Test
public void paramPresentNoMatch() throws Exception {
public void paramPresentNoMatch() {
ParamsRequestCondition condition = new ParamsRequestCondition("foo");
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?bar=")))).isNull();
}
@Test
public void paramNotPresent() throws Exception {
public void paramNotPresent() {
MockServerWebExchange exchange = MockServerWebExchange.from(get("/"));
assertThat(new ParamsRequestCondition("!foo").getMatchingCondition(exchange)).isNotNull();
}
@Test
public void paramValueMatch() throws Exception {
public void paramValueMatch() {
ParamsRequestCondition condition = new ParamsRequestCondition("foo=bar");
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=bar")))).isNotNull();
}
@Test
public void paramValueNoMatch() throws Exception {
public void paramValueNoMatch() {
ParamsRequestCondition condition = new ParamsRequestCondition("foo=bar");
assertThat(condition.getMatchingCondition(MockServerWebExchange.from(get("/path?foo=bazz")))).isNull();
}
@Test
public void compareTo() throws Exception {
public void compareTo() {
ServerWebExchange exchange = MockServerWebExchange.from(get("/"));
ParamsRequestCondition condition1 = new ParamsRequestCondition("foo", "bar", "baz");
@ -112,6 +114,24 @@ public class ParamsRequestConditionTests {
assertThat(condition1.compareTo(condition2, exchange)).as("Negated match should not count as more specific").isEqualTo(0);
}
@Test
public void combineWitOtherEmpty() {
ParamsRequestCondition condition1 = new ParamsRequestCondition("foo=bar");
ParamsRequestCondition condition2 = new ParamsRequestCondition();
ParamsRequestCondition result = condition1.combine(condition2);
assertThat(result).isEqualTo(condition1);
}
@Test
public void combineWitThisEmpty() {
ParamsRequestCondition condition1 = new ParamsRequestCondition();
ParamsRequestCondition condition2 = new ParamsRequestCondition("foo=bar");
ParamsRequestCondition result = condition1.combine(condition2);
assertThat(result).isEqualTo(condition2);
}
@Test
public void combine() {
ParamsRequestCondition condition1 = new ParamsRequestCondition("foo=bar");

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2021 the original author or authors.
* Copyright 2002-2023 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.
@ -93,7 +93,7 @@ public final class ParamsRequestCondition extends AbstractRequestCondition<Param
if (other.isEmpty()) {
return this;
}
if (isEmpty()) {
else if (isEmpty()) {
return other;
}
Set<ParamExpression> set = new LinkedHashSet<>(this.expressions);

View File

@ -27,7 +27,9 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link ParamsRequestCondition}.
*
* @author Arjen Poutsma
* @author Stephane Nicoll
*/
public class ParamsRequestConditionTests {
@ -123,6 +125,24 @@ public class ParamsRequestConditionTests {
assertThat(condition1.compareTo(condition2, request)).as("Negated match should not count as more specific").isEqualTo(0);
}
@Test
public void combineWithOtherEmpty() {
ParamsRequestCondition condition1 = new ParamsRequestCondition("foo=bar");
ParamsRequestCondition condition2 = new ParamsRequestCondition();
ParamsRequestCondition result = condition1.combine(condition2);
assertThat(result).isEqualTo(condition1);
}
@Test
public void combineWithThisEmpty() {
ParamsRequestCondition condition1 = new ParamsRequestCondition();
ParamsRequestCondition condition2 = new ParamsRequestCondition("foo=bar");
ParamsRequestCondition result = condition1.combine(condition2);
assertThat(result).isEqualTo(condition2);
}
@Test
public void combine() {
ParamsRequestCondition condition1 = new ParamsRequestCondition("foo=bar");