Migrate Hamcrest assertions to AssertJ
Migrate all existing `assertThat(..., Matcher)` assertions to AssertJ and add checkstyle rules to ensure they don't return. See gh-23022
This commit is contained in:
@@ -28,10 +28,9 @@ import javax.servlet.ServletResponse;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -84,8 +83,8 @@ public class MockFilterChainTests {
|
||||
MockFilterChain chain = new MockFilterChain();
|
||||
chain.doFilter(this.request, this.response);
|
||||
|
||||
assertThat(chain.getRequest(), is(request));
|
||||
assertThat(chain.getResponse(), is(response));
|
||||
assertThat(chain.getRequest()).isEqualTo(request);
|
||||
assertThat(chain.getResponse()).isEqualTo(response);
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
chain.doFilter(this.request, this.response))
|
||||
|
||||
@@ -34,9 +34,7 @@ import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.HierarchyMode;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -95,21 +93,21 @@ public class ContextHierarchyDirtiesContextTests {
|
||||
Result result = jUnitCore.run(testClass);
|
||||
assertTrue("all tests passed", result.wasSuccessful());
|
||||
|
||||
assertThat(ContextHierarchyDirtiesContextTests.context, notNullValue());
|
||||
assertThat(ContextHierarchyDirtiesContextTests.context).isNotNull();
|
||||
|
||||
ConfigurableApplicationContext bazContext = (ConfigurableApplicationContext) ContextHierarchyDirtiesContextTests.context;
|
||||
assertEquals("baz", ContextHierarchyDirtiesContextTests.baz);
|
||||
assertThat("bazContext#isActive()", bazContext.isActive(), is(isBazContextActive));
|
||||
assertThat(bazContext.isActive()).isEqualTo(isBazContextActive);
|
||||
|
||||
ConfigurableApplicationContext barContext = (ConfigurableApplicationContext) bazContext.getParent();
|
||||
assertThat(barContext, notNullValue());
|
||||
assertThat(barContext).isNotNull();
|
||||
assertEquals("bar", ContextHierarchyDirtiesContextTests.bar);
|
||||
assertThat("barContext#isActive()", barContext.isActive(), is(isBarContextActive));
|
||||
assertThat(barContext.isActive()).isEqualTo(isBarContextActive);
|
||||
|
||||
ConfigurableApplicationContext fooContext = (ConfigurableApplicationContext) barContext.getParent();
|
||||
assertThat(fooContext, notNullValue());
|
||||
assertThat(fooContext).isNotNull();
|
||||
assertEquals("foo", ContextHierarchyDirtiesContextTests.foo);
|
||||
assertThat("fooContext#isActive()", fooContext.isActive(), is(isFooContextActive));
|
||||
assertThat(fooContext.isActive()).isEqualTo(isFooContextActive);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -26,8 +26,7 @@ import org.junit.Test;
|
||||
|
||||
import static java.util.Arrays.stream;
|
||||
import static java.util.stream.Collectors.toCollection;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
@@ -76,7 +75,7 @@ public class TestContextConcurrencyTests {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
});
|
||||
assertThat(actualMethods, equalTo(expectedMethods));
|
||||
assertThat(actualMethods).isEqualTo(expectedMethods);
|
||||
});
|
||||
assertEquals(0, tcm.getTestContext().attributeNames().length);
|
||||
}
|
||||
|
||||
@@ -24,8 +24,8 @@ import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
@@ -40,8 +40,8 @@ public class TestPropertySourceInterfaceTests implements TestPropertySourceTestI
|
||||
|
||||
@Test
|
||||
public void propertiesAreAvailableInEnvironment() {
|
||||
assertThat(property("foo"), is("bar"));
|
||||
assertThat(property("enigma"), is("42"));
|
||||
assertThat(property("foo")).isEqualTo("bar");
|
||||
assertThat(property("enigma")).isEqualTo("42");
|
||||
}
|
||||
|
||||
private String property(String key) {
|
||||
|
||||
@@ -27,8 +27,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.springframework.test.context.support.TestPropertySourceUtils.INLINED_PROPERTIES_PROPERTY_SOURCE_NAME;
|
||||
|
||||
@@ -56,16 +55,16 @@ public class InlinedPropertiesTestPropertySourceTests {
|
||||
@Test
|
||||
public void propertiesAreAvailableInEnvironment() {
|
||||
// Simple key/value pairs
|
||||
assertThat(property("foo"), is("bar"));
|
||||
assertThat(property("baz"), is("quux"));
|
||||
assertThat(property("enigma"), is("42"));
|
||||
assertThat(property("foo")).isEqualTo("bar");
|
||||
assertThat(property("baz")).isEqualTo("quux");
|
||||
assertThat(property("enigma")).isEqualTo("42");
|
||||
|
||||
// Values containing key/value delimiters (":", "=", " ")
|
||||
assertThat(property("x.y.z"), is("a=b=c"));
|
||||
assertThat(property("server.url"), is("https://example.com"));
|
||||
assertThat(property("key.value.1"), is("key=value"));
|
||||
assertThat(property("key.value.2"), is("key=value"));
|
||||
assertThat(property("key.value.3"), is("key:value"));
|
||||
assertThat(property("x.y.z")).isEqualTo("a=b=c");
|
||||
assertThat(property("server.url")).isEqualTo("https://example.com");
|
||||
assertThat(property("key.value.1")).isEqualTo("key=value");
|
||||
assertThat(property("key.value.2")).isEqualTo("key=value");
|
||||
assertThat(property("key.value.3")).isEqualTo("key:value");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -51,10 +51,8 @@ import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.startsWith;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.only;
|
||||
@@ -147,11 +145,11 @@ public class EventPublishingTestExecutionListenerIntegrationTests {
|
||||
|
||||
testContextManager.beforeTestMethod(testInstance, method);
|
||||
|
||||
assertThat(countDownLatch.await(2, TimeUnit.SECONDS), equalTo(true));
|
||||
assertThat(countDownLatch.await(2, TimeUnit.SECONDS)).isEqualTo(true);
|
||||
|
||||
verify(listener, only()).beforeTestMethod(testContext);
|
||||
assertThat(TrackingAsyncUncaughtExceptionHandler.asyncException.getMessage(),
|
||||
startsWith("Asynchronous exception for test method [" + methodName + "] in thread [" + THREAD_NAME_PREFIX));
|
||||
assertThat(TrackingAsyncUncaughtExceptionHandler.asyncException.getMessage())
|
||||
.startsWith("Asynchronous exception for test method [" + methodName + "] in thread [" + THREAD_NAME_PREFIX);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -33,9 +33,7 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.test.context.TestContext;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.willCallRealMethod;
|
||||
@@ -158,8 +156,8 @@ public class EventPublishingTestExecutionListenerTests {
|
||||
|
||||
// Verify the type of event that was published.
|
||||
ApplicationEvent event = eventFactory.getValue().apply(testContext);
|
||||
assertThat(event, instanceOf(eventClass));
|
||||
assertThat(event.getSource(), equalTo(testContext));
|
||||
assertThat(event).isInstanceOf(eventClass);
|
||||
assertThat(event.getSource()).isEqualTo(testContext);
|
||||
}
|
||||
|
||||
private void assertNoEvent(Class<? extends TestContextEvent> eventClass, Consumer<TestContext> callback) {
|
||||
@@ -175,8 +173,8 @@ public class EventPublishingTestExecutionListenerTests {
|
||||
// In any case, we can still verify the type of event that would have
|
||||
// been published.
|
||||
ApplicationEvent event = eventFactory.getValue().apply(testContext);
|
||||
assertThat(event, instanceOf(eventClass));
|
||||
assertThat(event.getSource(), equalTo(testContext));
|
||||
assertThat(event).isInstanceOf(eventClass);
|
||||
assertThat(event.getSource()).isEqualTo(testContext);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.test.context.junit.jupiter;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
@@ -30,16 +29,9 @@ import org.springframework.test.context.TestContextManager;
|
||||
import org.springframework.test.context.junit.SpringJUnitJupiterTestSuite;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.endsWith;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -63,8 +55,9 @@ class DisabledIfConditionTests {
|
||||
|
||||
@Test
|
||||
void missingDisabledIf() {
|
||||
assertResult(condition.evaluateExecutionCondition(buildExtensionContext("missingDisabledIf")), false,
|
||||
endsWith("missingDisabledIf() is enabled since @DisabledIf is not present"));
|
||||
ConditionEvaluationResult result = condition.evaluateExecutionCondition(buildExtensionContext("missingDisabledIf"));
|
||||
assertThat(result.isDisabled()).isFalse();
|
||||
assertThat(result.getReason().get()).endsWith("missingDisabledIf() is enabled since @DisabledIf is not present");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,8 +78,7 @@ class DisabledIfConditionTests {
|
||||
|
||||
Method method = ReflectionUtils.findMethod(getClass(), methodName);
|
||||
|
||||
assertThat(exception.getMessage(),
|
||||
is(equalTo("@DisabledIf(\"#{6 * 7}\") on " + method + " must evaluate to a String or a Boolean, not java.lang.Integer")));
|
||||
assertThat(exception).hasMessage("@DisabledIf(\"#{6 * 7}\") on " + method + " must evaluate to a String or a Boolean, not java.lang.Integer");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,25 +89,28 @@ class DisabledIfConditionTests {
|
||||
|
||||
Method method = ReflectionUtils.findMethod(getClass(), methodName);
|
||||
|
||||
assertThat(exception.getMessage(),
|
||||
is(equalTo("@DisabledIf(\"#{'enigma'}\") on " + method + " must evaluate to \"true\" or \"false\", not \"enigma\"")));
|
||||
assertThat(exception).hasMessage("@DisabledIf(\"#{'enigma'}\") on " + method + " must evaluate to \"true\" or \"false\", not \"enigma\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
void disabledWithCustomReason() {
|
||||
assertResult(condition.evaluateExecutionCondition(buildExtensionContext("customReason")), true, is(equalTo("Because... 42!")));
|
||||
ConditionEvaluationResult result = condition.evaluateExecutionCondition(buildExtensionContext("customReason"));
|
||||
assertThat(result.isDisabled()).isTrue();
|
||||
assertThat(result.getReason()).contains("Because... 42!");
|
||||
}
|
||||
|
||||
@Test
|
||||
void disabledWithDefaultReason() {
|
||||
assertResult(condition.evaluateExecutionCondition(buildExtensionContext("defaultReason")), true,
|
||||
endsWith("defaultReason() is disabled because @DisabledIf(\"#{1 + 1 eq 2}\") evaluated to true"));
|
||||
ConditionEvaluationResult result = condition.evaluateExecutionCondition(buildExtensionContext("defaultReason"));
|
||||
assertThat(result.isDisabled()).isTrue();
|
||||
assertThat(result.getReason().get()).endsWith("defaultReason() is disabled because @DisabledIf(\"#{1 + 1 eq 2}\") evaluated to true");
|
||||
}
|
||||
|
||||
@Test
|
||||
void notDisabledWithDefaultReason() {
|
||||
assertResult(condition.evaluateExecutionCondition(buildExtensionContext("neverDisabledWithDefaultReason")), false, endsWith(
|
||||
"neverDisabledWithDefaultReason() is enabled because @DisabledIf(\"false\") did not evaluate to true"));
|
||||
ConditionEvaluationResult result = condition.evaluateExecutionCondition(buildExtensionContext("neverDisabledWithDefaultReason"));
|
||||
assertThat(result.isDisabled()).isFalse();
|
||||
assertThat(result.getReason().get()).endsWith("neverDisabledWithDefaultReason() is enabled because @DisabledIf(\"false\") did not evaluate to true");
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@@ -137,22 +132,7 @@ class DisabledIfConditionTests {
|
||||
IllegalStateException exception = assertThrows(IllegalStateException.class,
|
||||
() -> condition.evaluateExecutionCondition(buildExtensionContext(methodName)));
|
||||
|
||||
assertThat(exception.getMessage(), containsString("must not be blank"));
|
||||
}
|
||||
|
||||
private void assertResult(ConditionEvaluationResult result, boolean disabled, Matcher<String> matcher) {
|
||||
assertNotNull(result);
|
||||
|
||||
if (disabled) {
|
||||
assertTrue(result.isDisabled());
|
||||
}
|
||||
else {
|
||||
assertFalse(result.isDisabled());
|
||||
}
|
||||
|
||||
Optional<String> reason = result.getReason();
|
||||
assertTrue(reason.isPresent());
|
||||
assertThat(reason.get(), matcher);
|
||||
assertThat(exception.getMessage()).contains("must not be blank");
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.springframework.http.MediaType.APPLICATION_JSON;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@@ -24,8 +24,7 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests to verify claims made in <a
|
||||
@@ -50,8 +49,8 @@ public class AutowiredQualifierTests {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
assertThat(foo, equalTo("normal"));
|
||||
assertThat(customFoo, equalTo("custom"));
|
||||
assertThat(foo).isEqualTo("normal");
|
||||
assertThat(customFoo).isEqualTo("custom");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,11 +31,8 @@ import org.springframework.test.context.ContextConfigurationAttributes;
|
||||
import org.springframework.test.context.ContextHierarchy;
|
||||
import org.springframework.test.context.ContextLoader;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.hasItems;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
@@ -127,7 +124,7 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf
|
||||
List<ContextConfigurationAttributes> configAttributesListClassLevel1 = hierarchyAttributes.get(0);
|
||||
debugConfigAttributes(configAttributesListClassLevel1);
|
||||
assertEquals(1, configAttributesListClassLevel1.size());
|
||||
assertThat(configAttributesListClassLevel1.get(0).getLocations()[0], equalTo("one.xml"));
|
||||
assertThat(configAttributesListClassLevel1.get(0).getLocations()[0]).isEqualTo("one.xml");
|
||||
|
||||
List<ContextConfigurationAttributes> configAttributesListClassLevel2 = hierarchyAttributes.get(1);
|
||||
debugConfigAttributes(configAttributesListClassLevel2);
|
||||
@@ -138,7 +135,7 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf
|
||||
List<ContextConfigurationAttributes> configAttributesListClassLevel3 = hierarchyAttributes.get(2);
|
||||
debugConfigAttributes(configAttributesListClassLevel3);
|
||||
assertEquals(1, configAttributesListClassLevel3.size());
|
||||
assertThat(configAttributesListClassLevel3.get(0).getLocations()[0], equalTo("three.xml"));
|
||||
assertThat(configAttributesListClassLevel3.get(0).getLocations()[0]).isEqualTo("three.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -149,7 +146,7 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf
|
||||
List<ContextConfigurationAttributes> configAttributesListClassLevel1 = hierarchyAttributes.get(0);
|
||||
debugConfigAttributes(configAttributesListClassLevel1);
|
||||
assertEquals(1, configAttributesListClassLevel1.size());
|
||||
assertThat(configAttributesListClassLevel1.get(0).getLocations()[0], equalTo("A.xml"));
|
||||
assertThat(configAttributesListClassLevel1.get(0).getLocations()[0]).isEqualTo("A.xml");
|
||||
assertAttributes(configAttributesListClassLevel1.get(0),
|
||||
TestClass1WithSingleLevelContextHierarchyFromMetaAnnotation.class, new String[] { "A.xml" },
|
||||
EMPTY_CLASS_ARRAY, ContextLoader.class, true);
|
||||
@@ -167,7 +164,7 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf
|
||||
List<ContextConfigurationAttributes> configAttributesListClassLevel3 = hierarchyAttributes.get(2);
|
||||
debugConfigAttributes(configAttributesListClassLevel3);
|
||||
assertEquals(1, configAttributesListClassLevel3.size());
|
||||
assertThat(configAttributesListClassLevel3.get(0).getLocations()[0], equalTo("C.xml"));
|
||||
assertThat(configAttributesListClassLevel3.get(0).getLocations()[0]).isEqualTo("C.xml");
|
||||
assertAttributes(configAttributesListClassLevel3.get(0),
|
||||
TestClass3WithSingleLevelContextHierarchyFromMetaAnnotation.class, new String[] { "C.xml" },
|
||||
EMPTY_CLASS_ARRAY, ContextLoader.class, true);
|
||||
@@ -182,10 +179,10 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf
|
||||
debugConfigAttributes(configAttributesListClassLevel2);
|
||||
|
||||
assertEquals(1, configAttributesListClassLevel1.size());
|
||||
assertThat(configAttributesListClassLevel1.get(0).getLocations()[0], equalTo("one.xml"));
|
||||
assertThat(configAttributesListClassLevel1.get(0).getLocations()[0]).isEqualTo("one.xml");
|
||||
|
||||
assertEquals(1, configAttributesListClassLevel2.size());
|
||||
assertThat(configAttributesListClassLevel2.get(0).getLocations()[0], equalTo("two.xml"));
|
||||
assertThat(configAttributesListClassLevel2.get(0).getLocations()[0]).isEqualTo("two.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -216,45 +213,44 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf
|
||||
List<ContextConfigurationAttributes> configAttributesListClassLevel1 = hierarchyAttributes.get(0);
|
||||
debugConfigAttributes(configAttributesListClassLevel1);
|
||||
assertEquals(2, configAttributesListClassLevel1.size());
|
||||
assertThat(configAttributesListClassLevel1.get(0).getLocations()[0], equalTo("1-A.xml"));
|
||||
assertThat(configAttributesListClassLevel1.get(1).getLocations()[0], equalTo("1-B.xml"));
|
||||
assertThat(configAttributesListClassLevel1.get(0).getLocations()[0]).isEqualTo("1-A.xml");
|
||||
assertThat(configAttributesListClassLevel1.get(1).getLocations()[0]).isEqualTo("1-B.xml");
|
||||
|
||||
List<ContextConfigurationAttributes> configAttributesListClassLevel2 = hierarchyAttributes.get(1);
|
||||
debugConfigAttributes(configAttributesListClassLevel2);
|
||||
assertEquals(2, configAttributesListClassLevel2.size());
|
||||
assertThat(configAttributesListClassLevel2.get(0).getLocations()[0], equalTo("2-A.xml"));
|
||||
assertThat(configAttributesListClassLevel2.get(1).getLocations()[0], equalTo("2-B.xml"));
|
||||
assertThat(configAttributesListClassLevel2.get(0).getLocations()[0]).isEqualTo("2-A.xml");
|
||||
assertThat(configAttributesListClassLevel2.get(1).getLocations()[0]).isEqualTo("2-B.xml");
|
||||
|
||||
List<ContextConfigurationAttributes> configAttributesListClassLevel3 = hierarchyAttributes.get(2);
|
||||
debugConfigAttributes(configAttributesListClassLevel3);
|
||||
assertEquals(3, configAttributesListClassLevel3.size());
|
||||
assertThat(configAttributesListClassLevel3.get(0).getLocations()[0], equalTo("3-A.xml"));
|
||||
assertThat(configAttributesListClassLevel3.get(1).getLocations()[0], equalTo("3-B.xml"));
|
||||
assertThat(configAttributesListClassLevel3.get(2).getLocations()[0], equalTo("3-C.xml"));
|
||||
assertThat(configAttributesListClassLevel3.get(0).getLocations()[0]).isEqualTo("3-A.xml");
|
||||
assertThat(configAttributesListClassLevel3.get(1).getLocations()[0]).isEqualTo("3-B.xml");
|
||||
assertThat(configAttributesListClassLevel3.get(2).getLocations()[0]).isEqualTo("3-C.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildContextHierarchyMapForTestClassHierarchyWithMultiLevelContextHierarchies() {
|
||||
Map<String, List<ContextConfigurationAttributes>> map = buildContextHierarchyMap(TestClass3WithMultiLevelContextHierarchy.class);
|
||||
|
||||
assertThat(map.size(), is(3));
|
||||
assertThat(map.keySet(), hasItems("alpha", "beta", "gamma"));
|
||||
assertThat(map).hasSize(3).containsKeys("alpha", "beta", "gamma");
|
||||
|
||||
List<ContextConfigurationAttributes> alphaConfig = map.get("alpha");
|
||||
assertThat(alphaConfig.size(), is(3));
|
||||
assertThat(alphaConfig.get(0).getLocations()[0], is("1-A.xml"));
|
||||
assertThat(alphaConfig.get(1).getLocations()[0], is("2-A.xml"));
|
||||
assertThat(alphaConfig.get(2).getLocations()[0], is("3-A.xml"));
|
||||
assertThat(alphaConfig).hasSize(3);
|
||||
assertThat(alphaConfig.get(0).getLocations()[0]).isEqualTo("1-A.xml");
|
||||
assertThat(alphaConfig.get(1).getLocations()[0]).isEqualTo("2-A.xml");
|
||||
assertThat(alphaConfig.get(2).getLocations()[0]).isEqualTo("3-A.xml");
|
||||
|
||||
List<ContextConfigurationAttributes> betaConfig = map.get("beta");
|
||||
assertThat(betaConfig.size(), is(3));
|
||||
assertThat(betaConfig.get(0).getLocations()[0], is("1-B.xml"));
|
||||
assertThat(betaConfig.get(1).getLocations()[0], is("2-B.xml"));
|
||||
assertThat(betaConfig.get(2).getLocations()[0], is("3-B.xml"));
|
||||
assertThat(betaConfig).hasSize(3);
|
||||
assertThat(betaConfig.get(0).getLocations()[0]).isEqualTo("1-B.xml");
|
||||
assertThat(betaConfig.get(1).getLocations()[0]).isEqualTo("2-B.xml");
|
||||
assertThat(betaConfig.get(2).getLocations()[0]).isEqualTo("3-B.xml");
|
||||
|
||||
List<ContextConfigurationAttributes> gammaConfig = map.get("gamma");
|
||||
assertThat(gammaConfig.size(), is(1));
|
||||
assertThat(gammaConfig.get(0).getLocations()[0], is("3-C.xml"));
|
||||
assertThat(gammaConfig).hasSize(1);
|
||||
assertThat(gammaConfig.get(0).getLocations()[0]).isEqualTo("3-C.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -269,26 +265,25 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf
|
||||
String level6 = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + 6;
|
||||
String level7 = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + 7;
|
||||
|
||||
assertThat(map.size(), is(7));
|
||||
assertThat(map.keySet(), hasItems(level1, level2, level3, level4, level5, level6, level7));
|
||||
assertThat(map).hasSize(7).containsKeys(level1, level2, level3, level4, level5, level6, level7);
|
||||
|
||||
List<ContextConfigurationAttributes> level1Config = map.get(level1);
|
||||
assertThat(level1Config.size(), is(1));
|
||||
assertThat(level1Config.get(0).getLocations()[0], is("1-A.xml"));
|
||||
assertThat(level1Config).hasSize(1);
|
||||
assertThat(level1Config.get(0).getLocations()[0]).isEqualTo("1-A.xml");
|
||||
|
||||
List<ContextConfigurationAttributes> level2Config = map.get(level2);
|
||||
assertThat(level2Config.size(), is(1));
|
||||
assertThat(level2Config.get(0).getLocations()[0], is("1-B.xml"));
|
||||
assertThat(level2Config).hasSize(1);
|
||||
assertThat(level2Config.get(0).getLocations()[0]).isEqualTo("1-B.xml");
|
||||
|
||||
List<ContextConfigurationAttributes> level3Config = map.get(level3);
|
||||
assertThat(level3Config.size(), is(1));
|
||||
assertThat(level3Config.get(0).getLocations()[0], is("2-A.xml"));
|
||||
assertThat(level3Config).hasSize(1);
|
||||
assertThat(level3Config.get(0).getLocations()[0]).isEqualTo("2-A.xml");
|
||||
|
||||
// ...
|
||||
|
||||
List<ContextConfigurationAttributes> level7Config = map.get(level7);
|
||||
assertThat(level7Config.size(), is(1));
|
||||
assertThat(level7Config.get(0).getLocations()[0], is("3-C.xml"));
|
||||
assertThat(level7Config).hasSize(1);
|
||||
assertThat(level7Config.get(0).getLocations()[0]).isEqualTo("3-C.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -299,25 +294,24 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf
|
||||
String level2 = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + 2;
|
||||
String level3 = GENERATED_CONTEXT_HIERARCHY_LEVEL_PREFIX + 3;
|
||||
|
||||
assertThat(map.size(), is(3));
|
||||
assertThat(map.keySet(), hasItems(level1, level2, level3));
|
||||
assertThat(map).hasSize(3).containsKeys(level1, level2, level3);
|
||||
Iterator<String> levels = map.keySet().iterator();
|
||||
assertThat(levels.next(), is(level1));
|
||||
assertThat(levels.next(), is(level2));
|
||||
assertThat(levels.next(), is(level3));
|
||||
assertThat(levels.next()).isEqualTo(level1);
|
||||
assertThat(levels.next()).isEqualTo(level2);
|
||||
assertThat(levels.next()).isEqualTo(level3);
|
||||
|
||||
List<ContextConfigurationAttributes> level1Config = map.get(level1);
|
||||
assertThat(level1Config.size(), is(2));
|
||||
assertThat(level1Config.get(0).getLocations()[0], is("1-A.xml"));
|
||||
assertThat(level1Config.get(1).getLocations()[0], is("2-A.xml"));
|
||||
assertThat(level1Config).hasSize(2);
|
||||
assertThat(level1Config.get(0).getLocations()[0]).isEqualTo("1-A.xml");
|
||||
assertThat(level1Config.get(1).getLocations()[0]).isEqualTo("2-A.xml");
|
||||
|
||||
List<ContextConfigurationAttributes> level2Config = map.get(level2);
|
||||
assertThat(level2Config.size(), is(1));
|
||||
assertThat(level2Config.get(0).getLocations()[0], is("1-B.xml"));
|
||||
assertThat(level2Config).hasSize(1);
|
||||
assertThat(level2Config.get(0).getLocations()[0]).isEqualTo("1-B.xml");
|
||||
|
||||
List<ContextConfigurationAttributes> level3Config = map.get(level3);
|
||||
assertThat(level3Config.size(), is(1));
|
||||
assertThat(level3Config.get(0).getLocations()[0], is("2-C.xml"));
|
||||
assertThat(level3Config).hasSize(1);
|
||||
assertThat(level3Config.get(0).getLocations()[0]).isEqualTo("2-C.xml");
|
||||
}
|
||||
|
||||
private void assertContextConfigEntriesAreNotUnique(Class<?> testClass) {
|
||||
@@ -344,25 +338,24 @@ public class ContextLoaderUtilsContextHierarchyTests extends AbstractContextConf
|
||||
public void buildContextHierarchyMapForTestClassHierarchyWithMultiLevelContextHierarchiesAndOverriddenInitializers() {
|
||||
Map<String, List<ContextConfigurationAttributes>> map = buildContextHierarchyMap(TestClass2WithMultiLevelContextHierarchyWithOverriddenInitializers.class);
|
||||
|
||||
assertThat(map.size(), is(2));
|
||||
assertThat(map.keySet(), hasItems("alpha", "beta"));
|
||||
assertThat(map).hasSize(2).containsKeys("alpha", "beta");
|
||||
|
||||
List<ContextConfigurationAttributes> alphaConfig = map.get("alpha");
|
||||
assertThat(alphaConfig.size(), is(2));
|
||||
assertThat(alphaConfig.get(0).getLocations().length, is(1));
|
||||
assertThat(alphaConfig.get(0).getLocations()[0], is("1-A.xml"));
|
||||
assertThat(alphaConfig.get(0).getInitializers().length, is(0));
|
||||
assertThat(alphaConfig.get(1).getLocations().length, is(0));
|
||||
assertThat(alphaConfig.get(1).getInitializers().length, is(1));
|
||||
assertThat(alphaConfig).hasSize(2);
|
||||
assertThat(alphaConfig.get(0).getLocations().length).isEqualTo(1);
|
||||
assertThat(alphaConfig.get(0).getLocations()[0]).isEqualTo("1-A.xml");
|
||||
assertThat(alphaConfig.get(0).getInitializers().length).isEqualTo(0);
|
||||
assertThat(alphaConfig.get(1).getLocations().length).isEqualTo(0);
|
||||
assertThat(alphaConfig.get(1).getInitializers().length).isEqualTo(1);
|
||||
assertEquals(DummyApplicationContextInitializer.class, alphaConfig.get(1).getInitializers()[0]);
|
||||
|
||||
List<ContextConfigurationAttributes> betaConfig = map.get("beta");
|
||||
assertThat(betaConfig.size(), is(2));
|
||||
assertThat(betaConfig.get(0).getLocations().length, is(1));
|
||||
assertThat(betaConfig.get(0).getLocations()[0], is("1-B.xml"));
|
||||
assertThat(betaConfig.get(0).getInitializers().length, is(0));
|
||||
assertThat(betaConfig.get(1).getLocations().length, is(0));
|
||||
assertThat(betaConfig.get(1).getInitializers().length, is(1));
|
||||
assertThat(betaConfig).hasSize(2);
|
||||
assertThat(betaConfig.get(0).getLocations().length).isEqualTo(1);
|
||||
assertThat(betaConfig.get(0).getLocations()[0]).isEqualTo("1-B.xml");
|
||||
assertThat(betaConfig.get(0).getInitializers().length).isEqualTo(0);
|
||||
assertThat(betaConfig.get(1).getLocations().length).isEqualTo(0);
|
||||
assertThat(betaConfig.get(1).getInitializers().length).isEqualTo(1);
|
||||
assertEquals(DummyApplicationContextInitializer.class, betaConfig.get(1).getInitializers()[0]);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,8 +23,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
@@ -45,21 +44,21 @@ public class JdbcTestUtilsTests {
|
||||
public void deleteWithoutWhereClause() throws Exception {
|
||||
given(jdbcTemplate.update("DELETE FROM person")).willReturn(10);
|
||||
int deleted = JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "person", null);
|
||||
assertThat(deleted, equalTo(10));
|
||||
assertThat(deleted).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteWithWhereClause() throws Exception {
|
||||
given(jdbcTemplate.update("DELETE FROM person WHERE name = 'Bob' and age > 25")).willReturn(10);
|
||||
int deleted = JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "person", "name = 'Bob' and age > 25");
|
||||
assertThat(deleted, equalTo(10));
|
||||
assertThat(deleted).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deleteWithWhereClauseAndArguments() throws Exception {
|
||||
given(jdbcTemplate.update("DELETE FROM person WHERE name = ? and age > ?", "Bob", 25)).willReturn(10);
|
||||
int deleted = JdbcTestUtils.deleteFromTableWhere(jdbcTemplate, "person", "name = ? and age > ?", "Bob", 25);
|
||||
assertThat(deleted, equalTo(10));
|
||||
assertThat(deleted).isEqualTo(10);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,9 +21,8 @@ import org.junit.Test;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertNotSame;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -131,7 +130,7 @@ public class AopTestUtilsTests {
|
||||
pf.addInterface(Foo.class);
|
||||
Foo proxy = (Foo) pf.getProxy();
|
||||
assertTrue("Proxy is a JDK dynamic proxy", AopUtils.isJdkDynamicProxy(proxy));
|
||||
assertThat(proxy, instanceOf(Foo.class));
|
||||
assertThat(proxy).isInstanceOf(Foo.class);
|
||||
return proxy;
|
||||
}
|
||||
|
||||
@@ -141,7 +140,7 @@ public class AopTestUtilsTests {
|
||||
pf.setProxyTargetClass(true);
|
||||
Foo proxy = (Foo) pf.getProxy();
|
||||
assertTrue("Proxy is a CGLIB proxy", AopUtils.isCglibProxy(proxy));
|
||||
assertThat(proxy, instanceOf(FooImpl.class));
|
||||
assertThat(proxy).isInstanceOf(FooImpl.class);
|
||||
return proxy;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.util.MultiValueMap;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hamcrest.Matchers.hasXPath;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ContentRequestMatchers}.
|
||||
*
|
||||
|
||||
@@ -23,7 +23,8 @@ import org.junit.Test;
|
||||
import org.springframework.mock.http.client.MockClientHttpRequest;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for {@link JsonPathRequestMatchers}.
|
||||
|
||||
@@ -25,7 +25,7 @@ import org.junit.Test;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.mock.http.client.MockClientHttpRequest;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
@@ -83,7 +83,7 @@ public class MockRestRequestMatchersTests {
|
||||
|
||||
AssertionError error = assertThrows(AssertionError.class,
|
||||
() -> MockRestRequestMatchers.method(HttpMethod.GET).match(this.request));
|
||||
assertThat(error.getMessage(), containsString("expected:<GET> but was:<POST>"));
|
||||
assertThat(error.getMessage()).contains("expected:<GET> but was:<POST>");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,7 +97,7 @@ public class MockRestRequestMatchersTests {
|
||||
public void headerMissing() throws Exception {
|
||||
AssertionError error = assertThrows(AssertionError.class,
|
||||
() -> MockRestRequestMatchers.header("foo", "bar").match(this.request));
|
||||
assertThat(error.getMessage(), containsString("was null"));
|
||||
assertThat(error.getMessage()).contains("was null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -106,7 +106,7 @@ public class MockRestRequestMatchersTests {
|
||||
|
||||
AssertionError error = assertThrows(AssertionError.class,
|
||||
() -> MockRestRequestMatchers.header("foo", "bad").match(this.request));
|
||||
assertThat(error.getMessage(), containsString("expected:<bad> but was:<bar>"));
|
||||
assertThat(error.getMessage()).contains("expected:<bad> but was:<bar>");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,7 +120,7 @@ public class MockRestRequestMatchersTests {
|
||||
public void headerContainsWithMissingHeader() throws Exception {
|
||||
AssertionError error = assertThrows(AssertionError.class,
|
||||
() -> MockRestRequestMatchers.header("foo", containsString("baz")).match(this.request));
|
||||
assertThat(error.getMessage(), containsString("but was null"));
|
||||
assertThat(error.getMessage()).contains("but was null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,7 +129,7 @@ public class MockRestRequestMatchersTests {
|
||||
|
||||
AssertionError error = assertThrows(AssertionError.class,
|
||||
() -> MockRestRequestMatchers.header("foo", containsString("bx")).match(this.request));
|
||||
assertThat(error.getMessage(), containsString("was \"bar\""));
|
||||
assertThat(error.getMessage()).contains("was \"bar\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -143,7 +143,7 @@ public class MockRestRequestMatchersTests {
|
||||
public void headersWithMissingHeader() throws Exception {
|
||||
AssertionError error = assertThrows(AssertionError.class,
|
||||
() -> MockRestRequestMatchers.header("foo", "bar").match(this.request));
|
||||
assertThat(error.getMessage(), containsString("but was null"));
|
||||
assertThat(error.getMessage()).contains("but was null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -152,7 +152,7 @@ public class MockRestRequestMatchersTests {
|
||||
|
||||
AssertionError error = assertThrows(AssertionError.class,
|
||||
() -> MockRestRequestMatchers.header("foo", "bar", "baz").match(this.request));
|
||||
assertThat(error.getMessage(), containsString("to have at least <2> values"));
|
||||
assertThat(error.getMessage()).contains("to have at least <2> values");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -168,7 +168,7 @@ public class MockRestRequestMatchersTests {
|
||||
|
||||
AssertionError error = assertThrows(AssertionError.class,
|
||||
() -> MockRestRequestMatchers.queryParam("foo", "bar").match(this.request));
|
||||
assertThat(error.getMessage(), containsString("but was null"));
|
||||
assertThat(error.getMessage()).contains("but was null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -177,7 +177,7 @@ public class MockRestRequestMatchersTests {
|
||||
|
||||
AssertionError error = assertThrows(AssertionError.class,
|
||||
() -> MockRestRequestMatchers.queryParam("foo", "bad").match(this.request));
|
||||
assertThat(error.getMessage(), containsString("expected:<bad> but was:<bar>"));
|
||||
assertThat(error.getMessage()).contains("expected:<bad> but was:<bar>");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -193,7 +193,7 @@ public class MockRestRequestMatchersTests {
|
||||
|
||||
AssertionError error = assertThrows(AssertionError.class,
|
||||
() -> MockRestRequestMatchers.queryParam("foo", containsString("bx")).match(this.request));
|
||||
assertThat(error.getMessage(), containsString("was \"bar\""));
|
||||
assertThat(error.getMessage()).contains("was \"bar\"");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.mock.http.client.reactive.MockClientHttpResponse;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,8 +27,7 @@ import org.springframework.web.server.WebFilter;
|
||||
import org.springframework.web.server.WebFilterChain;
|
||||
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.StringContains.containsString;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AbstractMockServerSpec}.
|
||||
@@ -56,7 +55,7 @@ public class MockServerSpecTests {
|
||||
.exchange()
|
||||
.expectBody(String.class)
|
||||
.consumeWith(result -> assertThat(
|
||||
result.getResponseBody(), containsString("test-attribute=:A:B")));
|
||||
result.getResponseBody()).contains("test-attribute=:A:B"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,7 +79,7 @@ public class MockServerSpecTests {
|
||||
.exchange()
|
||||
.expectBody(String.class)
|
||||
.consumeWith(result -> assertThat(
|
||||
result.getResponseBody(), containsString("test-attribute=:Fwk-A:Fwk-B:App-A:App-B")));
|
||||
result.getResponseBody()).contains("test-attribute=:Fwk-A:Fwk-B:App-A:App-B"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Samples of tests using {@link WebTestClient} with serialized JSON content.
|
||||
*
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hamcrest.MatcherAssert;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
@@ -40,10 +39,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static java.time.Duration.ofMillis;
|
||||
import static org.hamcrest.CoreMatchers.endsWith;
|
||||
import static org.hamcrest.CoreMatchers.hasItem;
|
||||
import static org.hamcrest.CoreMatchers.startsWith;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.springframework.http.MediaType.TEXT_EVENT_STREAM;
|
||||
|
||||
@@ -110,7 +107,7 @@ public class ResponseEntityTests {
|
||||
.expectStatus().isOk()
|
||||
.expectHeader().contentType(MediaType.APPLICATION_JSON)
|
||||
.expectBodyList(Person.class).value(people ->
|
||||
MatcherAssert.assertThat(people, hasItem(new Person("Jason")))
|
||||
assertThat(people).contains(new Person("Jason"))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -141,7 +138,7 @@ public class ResponseEntityTests {
|
||||
StepVerifier.create(result.getResponseBody())
|
||||
.expectNext(new Person("N0"), new Person("N1"), new Person("N2"))
|
||||
.expectNextCount(4)
|
||||
.consumeNextWith(person -> assertThat(person.getName(), endsWith("7")))
|
||||
.consumeNextWith(person -> assertThat(person.getName()).endsWith("7"))
|
||||
.thenCancel()
|
||||
.verify();
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Samples of tests using {@link WebTestClient} with XML content.
|
||||
*
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request;
|
||||
|
||||
@@ -39,11 +39,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.tests.Assume;
|
||||
import org.springframework.tests.TestGroup;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.sameInstance;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.isEmptyString;
|
||||
import static org.hamcrest.core.IsNot.not;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
@@ -95,7 +91,7 @@ public class DelegatingWebConnectionTests {
|
||||
given(defaultConnection.getResponse(request)).willReturn(expectedResponse);
|
||||
WebResponse response = webConnection.getResponse(request);
|
||||
|
||||
assertThat(response, sameInstance(expectedResponse));
|
||||
assertThat(response).isSameAs(expectedResponse);
|
||||
verify(matcher1).matches(request);
|
||||
verify(matcher2).matches(request);
|
||||
verifyNoMoreInteractions(connection1, connection2);
|
||||
@@ -108,7 +104,7 @@ public class DelegatingWebConnectionTests {
|
||||
given(connection1.getResponse(request)).willReturn(expectedResponse);
|
||||
WebResponse response = webConnection.getResponse(request);
|
||||
|
||||
assertThat(response, sameInstance(expectedResponse));
|
||||
assertThat(response).isSameAs(expectedResponse);
|
||||
verify(matcher1).matches(request);
|
||||
verifyNoMoreInteractions(matcher2, connection2, defaultConnection);
|
||||
verify(connection1).getResponse(request);
|
||||
@@ -120,7 +116,7 @@ public class DelegatingWebConnectionTests {
|
||||
given(connection2.getResponse(request)).willReturn(expectedResponse);
|
||||
WebResponse response = webConnection.getResponse(request);
|
||||
|
||||
assertThat(response, sameInstance(expectedResponse));
|
||||
assertThat(response).isSameAs(expectedResponse);
|
||||
verify(matcher1).matches(request);
|
||||
verify(matcher2).matches(request);
|
||||
verifyNoMoreInteractions(connection1, defaultConnection);
|
||||
@@ -142,8 +138,8 @@ public class DelegatingWebConnectionTests {
|
||||
new DelegatingWebConnection(mockConnection, new DelegateWebConnection(cdnMatcher, httpConnection)));
|
||||
|
||||
Page page = webClient.getPage("https://code.jquery.com/jquery-1.11.0.min.js");
|
||||
assertThat(page.getWebResponse().getStatusCode(), equalTo(200));
|
||||
assertThat(page.getWebResponse().getContentAsString(), not(isEmptyString()));
|
||||
assertThat(page.getWebResponse().getStatusCode()).isEqualTo(200);
|
||||
assertThat(page.getWebResponse().getContentAsString()).isNotEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -19,9 +19,9 @@ package org.springframework.test.web.servlet.htmlunit;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import javax.servlet.ServletContext;
|
||||
@@ -45,16 +45,8 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.isEmptyString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
|
||||
/**
|
||||
@@ -119,8 +111,8 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getAuthType(), equalTo("Basic"));
|
||||
assertThat(actualRequest.getHeader("Authorization"), equalTo(authzHeaderValue));
|
||||
assertThat(actualRequest.getAuthType()).isEqualTo("Basic");
|
||||
assertThat(actualRequest.getHeader("Authorization")).isEqualTo(authzHeaderValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,14 +121,14 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getCharacterEncoding(), equalTo("UTF-8"));
|
||||
assertThat(actualRequest.getCharacterEncoding()).isEqualTo("UTF-8");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestDefaultCharacterEncoding() {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getCharacterEncoding(), equalTo("ISO-8859-1"));
|
||||
assertThat(actualRequest.getCharacterEncoding()).isEqualTo("ISO-8859-1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,7 +139,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getContentLength(), equalTo(content.length()));
|
||||
assertThat(actualRequest.getContentLength()).isEqualTo(content.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,8 +149,8 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getContentType(), equalTo(contentType));
|
||||
assertThat(actualRequest.getHeader("Content-Type"), equalTo(contentType));
|
||||
assertThat(actualRequest.getContentType()).isEqualTo(contentType);
|
||||
assertThat(actualRequest.getHeader("Content-Type")).isEqualTo(contentType);
|
||||
}
|
||||
|
||||
@Test // SPR-14916
|
||||
@@ -167,9 +159,9 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getContentType(), equalTo("application/x-www-form-urlencoded"));
|
||||
assertThat(actualRequest.getHeader("Content-Type"),
|
||||
equalTo("application/x-www-form-urlencoded;charset=ISO-8859-1"));
|
||||
assertThat(actualRequest.getContentType()).isEqualTo("application/x-www-form-urlencoded");
|
||||
assertThat(actualRequest.getHeader("Content-Type"))
|
||||
.isEqualTo("application/x-www-form-urlencoded;charset=ISO-8859-1");
|
||||
}
|
||||
|
||||
|
||||
@@ -177,7 +169,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
public void buildRequestContextPathUsesFirstSegmentByDefault() {
|
||||
String contextPath = requestBuilder.buildRequest(servletContext).getContextPath();
|
||||
|
||||
assertThat(contextPath, equalTo("/test"));
|
||||
assertThat(contextPath).isEqualTo("/test");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -185,7 +177,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
webRequest.setUrl(new URL("http://example.com/"));
|
||||
String contextPath = requestBuilder.buildRequest(servletContext).getContextPath();
|
||||
|
||||
assertThat(contextPath, equalTo(""));
|
||||
assertThat(contextPath).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -203,7 +195,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
String contextPath = requestBuilder.buildRequest(servletContext).getContextPath();
|
||||
|
||||
assertThat(contextPath, equalTo(expected));
|
||||
assertThat(contextPath).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -213,7 +205,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
String contextPath = requestBuilder.buildRequest(servletContext).getContextPath();
|
||||
|
||||
assertThat(contextPath, equalTo(expected));
|
||||
assertThat(contextPath).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -223,14 +215,14 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
String contextPath = requestBuilder.buildRequest(servletContext).getContextPath();
|
||||
|
||||
assertThat(contextPath, equalTo(expected));
|
||||
assertThat(contextPath).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestCookiesNull() {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getCookies(), nullValue());
|
||||
assertThat(actualRequest.getCookies()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -240,9 +232,9 @@ public class HtmlUnitRequestBuilderTests {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
Cookie[] cookies = actualRequest.getCookies();
|
||||
assertThat(cookies.length, equalTo(1));
|
||||
assertThat(cookies[0].getName(), equalTo("name"));
|
||||
assertThat(cookies[0].getValue(), equalTo("value"));
|
||||
assertThat(cookies.length).isEqualTo(1);
|
||||
assertThat(cookies[0].getName()).isEqualTo("name");
|
||||
assertThat(cookies[0].getValue()).isEqualTo("value");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -252,13 +244,13 @@ public class HtmlUnitRequestBuilderTests {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
Cookie[] cookies = actualRequest.getCookies();
|
||||
assertThat(cookies.length, equalTo(2));
|
||||
assertThat(cookies.length).isEqualTo(2);
|
||||
Cookie cookie = cookies[0];
|
||||
assertThat(cookie.getName(), equalTo("name"));
|
||||
assertThat(cookie.getValue(), equalTo("value"));
|
||||
assertThat(cookie.getName()).isEqualTo("name");
|
||||
assertThat(cookie.getValue()).isEqualTo("value");
|
||||
cookie = cookies[1];
|
||||
assertThat(cookie.getName(), equalTo("name2"));
|
||||
assertThat(cookie.getValue(), equalTo("value2"));
|
||||
assertThat(cookie.getName()).isEqualTo("name2");
|
||||
assertThat(cookie.getValue()).isEqualTo("value2");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -270,21 +262,21 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(IOUtils.toString(actualRequest.getInputStream()), equalTo(content));
|
||||
assertThat(IOUtils.toString(actualRequest.getInputStream())).isEqualTo(content);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestLocalAddr() {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getLocalAddr(), equalTo("127.0.0.1"));
|
||||
assertThat(actualRequest.getLocalAddr()).isEqualTo("127.0.0.1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestLocaleDefault() {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getLocale(), equalTo(Locale.getDefault()));
|
||||
assertThat(actualRequest.getLocale()).isEqualTo(Locale.getDefault());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -293,7 +285,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getLocale(), equalTo(new Locale("da")));
|
||||
assertThat(actualRequest.getLocale()).isEqualTo(new Locale("da"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -302,7 +294,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getLocale(), equalTo(new Locale("en", "gb")));
|
||||
assertThat(actualRequest.getLocale()).isEqualTo(new Locale("en", "gb"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -311,7 +303,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getLocale(), equalTo(new Locale("en", "")));
|
||||
assertThat(actualRequest.getLocale()).isEqualTo(new Locale("en", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -320,7 +312,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getLocale(), equalTo(Locale.US));
|
||||
assertThat(actualRequest.getLocale()).isEqualTo(Locale.US);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -329,7 +321,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getLocale(), equalTo(Locale.FRENCH));
|
||||
assertThat(actualRequest.getLocale()).isEqualTo(Locale.FRENCH);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -338,22 +330,22 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
List<Locale> expected = asList(new Locale("da"), new Locale("en", "gb"), new Locale("en", ""));
|
||||
assertThat(Collections.list(actualRequest.getLocales()), equalTo(expected));
|
||||
assertThat(Collections.list(actualRequest.getLocales()))
|
||||
.containsExactly(new Locale("da"), new Locale("en", "gb"), new Locale("en", ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestLocalName() {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getLocalName(), equalTo("localhost"));
|
||||
assertThat(actualRequest.getLocalName()).isEqualTo("localhost");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestLocalPort() {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getLocalPort(), equalTo(80));
|
||||
assertThat(actualRequest.getLocalPort()).isEqualTo(80);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -361,7 +353,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
webRequest.setUrl(new URL("http://localhost/test/this"));
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getLocalPort(), equalTo(-1));
|
||||
assertThat(actualRequest.getLocalPort()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -369,59 +361,59 @@ public class HtmlUnitRequestBuilderTests {
|
||||
for (HttpMethod expectedMethod : HttpMethod.values()) {
|
||||
webRequest.setHttpMethod(expectedMethod);
|
||||
String actualMethod = requestBuilder.buildRequest(servletContext).getMethod();
|
||||
assertThat(actualMethod, equalTo(expectedMethod.name()));
|
||||
assertThat(actualMethod).isEqualTo(expectedMethod.name());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParam() {
|
||||
webRequest.setRequestParameters(asList(new NameValuePair("name", "value")));
|
||||
webRequest.setRequestParameters(Arrays.asList(new NameValuePair("name", "value")));
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getParameterMap().size(), equalTo(1));
|
||||
assertThat(actualRequest.getParameter("name"), equalTo("value"));
|
||||
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
||||
assertThat(actualRequest.getParameter("name")).isEqualTo("value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParamWithNullValue() {
|
||||
webRequest.setRequestParameters(asList(new NameValuePair("name", null)));
|
||||
webRequest.setRequestParameters(Arrays.asList(new NameValuePair("name", null)));
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getParameterMap().size(), equalTo(1));
|
||||
assertThat(actualRequest.getParameter("name"), nullValue());
|
||||
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
||||
assertThat(actualRequest.getParameter("name")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParamWithEmptyValue() {
|
||||
webRequest.setRequestParameters(asList(new NameValuePair("name", "")));
|
||||
webRequest.setRequestParameters(Arrays.asList(new NameValuePair("name", "")));
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getParameterMap().size(), equalTo(1));
|
||||
assertThat(actualRequest.getParameter("name"), equalTo(""));
|
||||
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
||||
assertThat(actualRequest.getParameter("name")).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithSingleRequestParamWithValueSetToSpace() {
|
||||
webRequest.setRequestParameters(asList(new NameValuePair("name", " ")));
|
||||
webRequest.setRequestParameters(Arrays.asList(new NameValuePair("name", " ")));
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getParameterMap().size(), equalTo(1));
|
||||
assertThat(actualRequest.getParameter("name"), equalTo(" "));
|
||||
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
||||
assertThat(actualRequest.getParameter("name")).isEqualTo(" ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestParameterMapViaWebRequestDotSetRequestParametersWithMultipleRequestParams() {
|
||||
webRequest.setRequestParameters(asList(new NameValuePair("name1", "value1"), new NameValuePair("name2", "value2")));
|
||||
webRequest.setRequestParameters(Arrays.asList(new NameValuePair("name1", "value1"), new NameValuePair("name2", "value2")));
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getParameterMap().size(), equalTo(2));
|
||||
assertThat(actualRequest.getParameter("name1"), equalTo("value1"));
|
||||
assertThat(actualRequest.getParameter("name2"), equalTo("value2"));
|
||||
assertThat(actualRequest.getParameterMap().size()).isEqualTo(2);
|
||||
assertThat(actualRequest.getParameter("name1")).isEqualTo("value1");
|
||||
assertThat(actualRequest.getParameter("name2")).isEqualTo("value2");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -430,8 +422,8 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getParameterMap().size(), equalTo(1));
|
||||
assertThat(actualRequest.getParameter("name"), equalTo("value"));
|
||||
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
||||
assertThat(actualRequest.getParameter("name")).isEqualTo("value");
|
||||
}
|
||||
|
||||
// SPR-14177
|
||||
@@ -441,8 +433,8 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getParameterMap().size(), equalTo(1));
|
||||
assertThat(actualRequest.getParameter("row[0]"), equalTo("value"));
|
||||
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
||||
assertThat(actualRequest.getParameter("row[0]")).isEqualTo("value");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -451,8 +443,8 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getParameterMap().size(), equalTo(1));
|
||||
assertThat(actualRequest.getParameter("name"), equalTo("row[0]"));
|
||||
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
||||
assertThat(actualRequest.getParameter("name")).isEqualTo("row[0]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -461,8 +453,8 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getParameterMap().size(), equalTo(1));
|
||||
assertThat(actualRequest.getParameter("name"), equalTo(""));
|
||||
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
||||
assertThat(actualRequest.getParameter("name")).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -471,8 +463,8 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getParameterMap().size(), equalTo(1));
|
||||
assertThat(actualRequest.getParameter("name"), equalTo(""));
|
||||
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
||||
assertThat(actualRequest.getParameter("name")).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -481,8 +473,8 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getParameterMap().size(), equalTo(1));
|
||||
assertThat(actualRequest.getParameter("name"), equalTo(" "));
|
||||
assertThat(actualRequest.getParameterMap().size()).isEqualTo(1);
|
||||
assertThat(actualRequest.getParameter("name")).isEqualTo(" ");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -491,16 +483,16 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getParameterMap().size(), equalTo(2));
|
||||
assertThat(actualRequest.getParameter("name"), equalTo("value"));
|
||||
assertThat(actualRequest.getParameter("param2"), equalTo("value 2"));
|
||||
assertThat(actualRequest.getParameterMap().size()).isEqualTo(2);
|
||||
assertThat(actualRequest.getParameter("name")).isEqualTo("value");
|
||||
assertThat(actualRequest.getParameter("param2")).isEqualTo("value 2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestPathInfo() throws Exception {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getPathInfo(), nullValue());
|
||||
assertThat(actualRequest.getPathInfo()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -509,7 +501,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getPathInfo(), nullValue());
|
||||
assertThat(actualRequest.getPathInfo()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -519,15 +511,15 @@ public class HtmlUnitRequestBuilderTests {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
// verify it is going to work with Spring Security's AntPathRequestMatcher
|
||||
assertThat(actualRequest.getPathInfo(), nullValue());
|
||||
assertThat(actualRequest.getServletPath(), equalTo("/login/authenticate"));
|
||||
assertThat(actualRequest.getPathInfo()).isNull();
|
||||
assertThat(actualRequest.getServletPath()).isEqualTo("/login/authenticate");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestProtocol() throws Exception {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getProtocol(), equalTo("HTTP/1.1"));
|
||||
assertThat(actualRequest.getProtocol()).isEqualTo("HTTP/1.1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -537,7 +529,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getQueryString(), equalTo(expectedQuery));
|
||||
assertThat(actualRequest.getQueryString()).isEqualTo(expectedQuery);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -547,7 +539,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getQueryString(), equalTo(expectedQuery));
|
||||
assertThat(actualRequest.getQueryString()).isEqualTo(expectedQuery);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -557,7 +549,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getQueryString(), equalTo(expectedQuery));
|
||||
assertThat(actualRequest.getQueryString()).isEqualTo(expectedQuery);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -567,7 +559,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getQueryString(), equalTo(expectedQuery));
|
||||
assertThat(actualRequest.getQueryString()).isEqualTo(expectedQuery);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -577,7 +569,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getQueryString(), equalTo(expectedQuery));
|
||||
assertThat(actualRequest.getQueryString()).isEqualTo(expectedQuery);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -588,28 +580,28 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(IOUtils.toString(actualRequest.getReader()), equalTo(expectedBody));
|
||||
assertThat(IOUtils.toString(actualRequest.getReader())).isEqualTo(expectedBody);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestRemoteAddr() throws Exception {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getRemoteAddr(), equalTo("127.0.0.1"));
|
||||
assertThat(actualRequest.getRemoteAddr()).isEqualTo("127.0.0.1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestRemoteHost() throws Exception {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getRemoteAddr(), equalTo("127.0.0.1"));
|
||||
assertThat(actualRequest.getRemoteAddr()).isEqualTo("127.0.0.1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestRemotePort() throws Exception {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getRemotePort(), equalTo(80));
|
||||
assertThat(actualRequest.getRemotePort()).isEqualTo(80);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -618,7 +610,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getRemotePort(), equalTo(8080));
|
||||
assertThat(actualRequest.getRemotePort()).isEqualTo(8080);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -627,7 +619,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getRemotePort(), equalTo(80));
|
||||
assertThat(actualRequest.getRemotePort()).isEqualTo(80);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -636,33 +628,33 @@ public class HtmlUnitRequestBuilderTests {
|
||||
webRequest.setAdditionalHeader("Cookie", "JSESSIONID=" + sessionId);
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getRequestedSessionId(), equalTo(sessionId));
|
||||
assertThat(actualRequest.getRequestedSessionId()).isEqualTo(sessionId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestRequestedSessionIdNull() throws Exception {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getRequestedSessionId(), nullValue());
|
||||
assertThat(actualRequest.getRequestedSessionId()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestUri() {
|
||||
String uri = requestBuilder.buildRequest(servletContext).getRequestURI();
|
||||
assertThat(uri, equalTo("/test/this/here"));
|
||||
assertThat(uri).isEqualTo("/test/this/here");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestUrl() {
|
||||
String uri = requestBuilder.buildRequest(servletContext).getRequestURL().toString();
|
||||
assertThat(uri, equalTo("http://example.com/test/this/here"));
|
||||
assertThat(uri).isEqualTo("http://example.com/test/this/here");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestSchemeHttp() throws Exception {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getScheme(), equalTo("http"));
|
||||
assertThat(actualRequest.getScheme()).isEqualTo("http");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -670,21 +662,21 @@ public class HtmlUnitRequestBuilderTests {
|
||||
webRequest.setUrl(new URL("https://example.com/"));
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getScheme(), equalTo("https"));
|
||||
assertThat(actualRequest.getScheme()).isEqualTo("https");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestServerName() throws Exception {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getServerName(), equalTo("example.com"));
|
||||
assertThat(actualRequest.getServerName()).isEqualTo("example.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestServerPort() throws Exception {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getServerPort(), equalTo(80));
|
||||
assertThat(actualRequest.getServerPort()).isEqualTo(80);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -692,21 +684,21 @@ public class HtmlUnitRequestBuilderTests {
|
||||
webRequest.setUrl(new URL("https://example.com/"));
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getServerPort(), equalTo(-1));
|
||||
assertThat(actualRequest.getServerPort()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestServletContext() throws Exception {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getServletContext(), equalTo(servletContext));
|
||||
assertThat(actualRequest.getServletContext()).isEqualTo(servletContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestServletPath() throws Exception {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getServletPath(), equalTo("/this/here"));
|
||||
assertThat(actualRequest.getServletPath()).isEqualTo("/this/here");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -714,7 +706,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
HttpSession newSession = actualRequest.getSession();
|
||||
assertThat(newSession, notNullValue());
|
||||
assertThat(newSession).isNotNull();
|
||||
assertSingleSessionCookie(
|
||||
"JSESSIONID=" + newSession.getId() + "; Path=/test; Domain=example.com");
|
||||
|
||||
@@ -723,7 +715,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
requestBuilder = new HtmlUnitRequestBuilder(sessions, webClient, webRequest);
|
||||
actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getSession(), sameInstance(newSession));
|
||||
assertThat(actualRequest.getSession()).isSameAs(newSession);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -733,16 +725,16 @@ public class HtmlUnitRequestBuilderTests {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
HttpSession session = actualRequest.getSession();
|
||||
assertThat(session.getId(), equalTo(sessionId));
|
||||
assertThat(session.getId()).isEqualTo(sessionId);
|
||||
assertSingleSessionCookie("JSESSIONID=" + session.getId() + "; Path=/test; Domain=example.com");
|
||||
|
||||
requestBuilder = new HtmlUnitRequestBuilder(sessions, webClient, webRequest);
|
||||
actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
assertThat(actualRequest.getSession(), equalTo(session));
|
||||
assertThat(actualRequest.getSession()).isEqualTo(session);
|
||||
|
||||
webRequest.setAdditionalHeader("Cookie", "JSESSIONID=" + sessionId + "NEW");
|
||||
actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
assertThat(actualRequest.getSession(), not(equalTo(session)));
|
||||
assertThat(actualRequest.getSession()).isNotEqualTo(session);
|
||||
assertSingleSessionCookie("JSESSIONID=" + actualRequest.getSession().getId()
|
||||
+ "; Path=/test; Domain=example.com");
|
||||
}
|
||||
@@ -752,7 +744,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
HttpSession session = actualRequest.getSession(true);
|
||||
assertThat(session, notNullValue());
|
||||
assertThat(session).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -760,7 +752,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
HttpSession session = actualRequest.getSession(false);
|
||||
assertThat(session, nullValue());
|
||||
assertThat(session).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -770,14 +762,14 @@ public class HtmlUnitRequestBuilderTests {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
HttpSession session = actualRequest.getSession(false);
|
||||
assertThat(session, notNullValue());
|
||||
assertThat(session).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildRequestSessionIsNew() throws Exception {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getSession().isNew(), equalTo(true));
|
||||
assertThat(actualRequest.getSession().isNew()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -787,7 +779,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getSession().isNew(), equalTo(false));
|
||||
assertThat(actualRequest.getSession().isNew()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -799,7 +791,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
HttpSession sessionToRemove = actualRequest.getSession();
|
||||
sessionToRemove.invalidate();
|
||||
|
||||
assertThat(sessions.containsKey(sessionToRemove.getId()), equalTo(false));
|
||||
assertThat(sessions.containsKey(sessionToRemove.getId())).isEqualTo(false);
|
||||
assertSingleSessionCookie("JSESSIONID=" + sessionToRemove.getId()
|
||||
+ "; Expires=Thu, 01-Jan-1970 00:00:01 GMT; Path=/test; Domain=example.com");
|
||||
|
||||
@@ -808,8 +800,8 @@ public class HtmlUnitRequestBuilderTests {
|
||||
|
||||
actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getSession().isNew(), equalTo(true));
|
||||
assertThat(sessions.containsKey(sessionToRemove.getId()), equalTo(false));
|
||||
assertThat(actualRequest.getSession().isNew()).isEqualTo(true);
|
||||
assertThat(sessions.containsKey(sessionToRemove.getId())).isEqualTo(false);
|
||||
}
|
||||
|
||||
// --- setContextPath
|
||||
@@ -818,14 +810,14 @@ public class HtmlUnitRequestBuilderTests {
|
||||
public void setContextPathNull() {
|
||||
requestBuilder.setContextPath(null);
|
||||
|
||||
assertThat(getContextPath(), nullValue());
|
||||
assertThat(getContextPath()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setContextPathEmptyString() {
|
||||
requestBuilder.setContextPath("");
|
||||
|
||||
assertThat(getContextPath(), isEmptyString());
|
||||
assertThat(getContextPath()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -845,7 +837,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
String expectedContextPath = "/abc/def";
|
||||
requestBuilder.setContextPath(expectedContextPath);
|
||||
|
||||
assertThat(getContextPath(), equalTo(expectedContextPath));
|
||||
assertThat(getContextPath()).isEqualTo(expectedContextPath);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -856,7 +848,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
.defaultRequest(get("/").header(headerName, headerValue))
|
||||
.build();
|
||||
|
||||
assertThat(mockMvc.perform(requestBuilder).andReturn().getRequest().getHeader(headerName), equalTo(headerValue));
|
||||
assertThat(mockMvc.perform(requestBuilder).andReturn().getRequest().getHeader(headerName)).isEqualTo(headerValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -867,7 +859,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
.defaultRequest(get("/").sessionAttr(attrName, attrValue))
|
||||
.build();
|
||||
|
||||
assertThat(mockMvc.perform(requestBuilder).andReturn().getRequest().getSession().getAttribute(attrName), equalTo(attrValue));
|
||||
assertThat(mockMvc.perform(requestBuilder).andReturn().getRequest().getSession().getAttribute(attrName)).isEqualTo(attrValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -876,7 +868,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
.defaultRequest(get("/"))
|
||||
.build();
|
||||
|
||||
assertThat(mockMvc.perform(requestBuilder).andReturn().getRequest().getSession(false), nullValue());
|
||||
assertThat(mockMvc.perform(requestBuilder).andReturn().getRequest().getSession(false)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -889,7 +881,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
.build();
|
||||
|
||||
MockHttpServletRequest performedRequest = mockMvc.perform(requestBuilder).andReturn().getRequest();
|
||||
assertThat(asList(performedRequest.getParameterValues(paramName)), contains(paramValue, paramValue2));
|
||||
assertThat(performedRequest.getParameterValues(paramName)).containsExactly(paramValue, paramValue2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -901,11 +893,11 @@ public class HtmlUnitRequestBuilderTests {
|
||||
.build();
|
||||
|
||||
Cookie[] cookies = mockMvc.perform(requestBuilder).andReturn().getRequest().getCookies();
|
||||
assertThat(cookies, notNullValue());
|
||||
assertThat(cookies.length, equalTo(1));
|
||||
assertThat(cookies).isNotNull();
|
||||
assertThat(cookies.length).isEqualTo(1);
|
||||
Cookie cookie = cookies[0];
|
||||
assertThat(cookie.getName(), equalTo(cookieName));
|
||||
assertThat(cookie.getValue(), equalTo(cookieValue));
|
||||
assertThat(cookie.getName()).isEqualTo(cookieName);
|
||||
assertThat(cookie.getValue()).isEqualTo(cookieValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -916,7 +908,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
.defaultRequest(get("/").requestAttr(attrName, attrValue))
|
||||
.build();
|
||||
|
||||
assertThat(mockMvc.perform(requestBuilder).andReturn().getRequest().getAttribute(attrName), equalTo(attrValue));
|
||||
assertThat(mockMvc.perform(requestBuilder).andReturn().getRequest().getAttribute(attrName)).isEqualTo(attrValue);
|
||||
}
|
||||
|
||||
@Test // SPR-14584
|
||||
@@ -926,22 +918,22 @@ public class HtmlUnitRequestBuilderTests {
|
||||
.defaultRequest(get("/"))
|
||||
.build();
|
||||
|
||||
assertThat(mockMvc.perform(get(pathInfo)).andReturn().getRequest().getPathInfo(), equalTo(pathInfo));
|
||||
assertThat(mockMvc.perform(get(pathInfo)).andReturn().getRequest().getPathInfo()).isEqualTo(pathInfo);
|
||||
|
||||
mockMvc.perform(requestBuilder);
|
||||
|
||||
assertThat(mockMvc.perform(get(pathInfo)).andReturn().getRequest().getPathInfo(), equalTo(pathInfo));
|
||||
assertThat(mockMvc.perform(get(pathInfo)).andReturn().getRequest().getPathInfo()).isEqualTo(pathInfo);
|
||||
}
|
||||
|
||||
|
||||
private void assertSingleSessionCookie(String expected) {
|
||||
com.gargoylesoftware.htmlunit.util.Cookie jsessionidCookie = webClient.getCookieManager().getCookie("JSESSIONID");
|
||||
if (expected == null || expected.contains("Expires=Thu, 01-Jan-1970 00:00:01 GMT")) {
|
||||
assertThat(jsessionidCookie, nullValue());
|
||||
assertThat(jsessionidCookie).isNull();
|
||||
return;
|
||||
}
|
||||
String actual = jsessionidCookie.getValue();
|
||||
assertThat("JSESSIONID=" + actual + "; Path=/test; Domain=example.com", equalTo(expected));
|
||||
assertThat("JSESSIONID=" + actual + "; Path=/test; Domain=example.com").isEqualTo(expected);
|
||||
}
|
||||
|
||||
private String getContextPath() {
|
||||
|
||||
@@ -40,11 +40,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -123,22 +120,22 @@ public class MockMvcConnectionBuilderSupportTests {
|
||||
@Test
|
||||
public void defaultContextPathEmpty() throws Exception {
|
||||
WebConnection conn = this.builder.createConnection(this.client);
|
||||
assertThat(getResponse(conn, "http://localhost/abc").getContentAsString(), equalTo(""));
|
||||
assertThat(getResponse(conn, "http://localhost/abc").getContentAsString()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultContextPathCustom() throws Exception {
|
||||
WebConnection conn = this.builder.contextPath("/abc").createConnection(this.client);
|
||||
assertThat(getResponse(conn, "http://localhost/abc/def").getContentAsString(), equalTo("/abc"));
|
||||
assertThat(getResponse(conn, "http://localhost/abc/def").getContentAsString()).isEqualTo("/abc");
|
||||
}
|
||||
|
||||
|
||||
private void assertMockMvcUsed(WebConnection connection, String url) throws Exception {
|
||||
assertThat(getResponse(connection, url), notNullValue());
|
||||
assertThat(getResponse(connection, url)).isNotNull();
|
||||
}
|
||||
|
||||
private void assertMockMvcNotUsed(WebConnection connection, String url) throws Exception {
|
||||
assertThat(getResponse(connection, url), nullValue());
|
||||
assertThat(getResponse(connection, url)).isNull();
|
||||
}
|
||||
|
||||
private WebResponse getResponse(WebConnection connection, String url) throws IOException {
|
||||
|
||||
@@ -48,10 +48,9 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Integration tests for {@link MockMvcWebClientBuilder}.
|
||||
@@ -112,9 +111,9 @@ public class MockMvcWebClientBuilderTests {
|
||||
this.mockMvc = MockMvcBuilders.standaloneSetup(new CookieController()).build();
|
||||
WebClient client = MockMvcWebClientBuilder.mockMvcSetup(this.mockMvc).build();
|
||||
|
||||
assertThat(getResponse(client, "http://localhost/").getContentAsString(), equalTo("NA"));
|
||||
assertThat(getResponse(client, "http://localhost/").getContentAsString()).isEqualTo("NA");
|
||||
client.getCookieManager().addCookie(new Cookie("localhost", "cookie", "cookieManagerShared"));
|
||||
assertThat(getResponse(client, "http://localhost/").getContentAsString(), equalTo("cookieManagerShared"));
|
||||
assertThat(getResponse(client, "http://localhost/").getContentAsString()).isEqualTo("cookieManagerShared");
|
||||
}
|
||||
|
||||
@Test // SPR-14265
|
||||
@@ -122,19 +121,19 @@ public class MockMvcWebClientBuilderTests {
|
||||
this.mockMvc = MockMvcBuilders.standaloneSetup(new CookieController()).build();
|
||||
WebClient client = MockMvcWebClientBuilder.mockMvcSetup(this.mockMvc).build();
|
||||
|
||||
assertThat(getResponse(client, "http://localhost/").getContentAsString(), equalTo("NA"));
|
||||
assertThat(postResponse(client, "http://localhost/?cookie=foo").getContentAsString(), equalTo("Set"));
|
||||
assertThat(getResponse(client, "http://localhost/").getContentAsString(), equalTo("foo"));
|
||||
assertThat(deleteResponse(client, "http://localhost/").getContentAsString(), equalTo("Delete"));
|
||||
assertThat(getResponse(client, "http://localhost/").getContentAsString(), equalTo("NA"));
|
||||
assertThat(getResponse(client, "http://localhost/").getContentAsString()).isEqualTo("NA");
|
||||
assertThat(postResponse(client, "http://localhost/?cookie=foo").getContentAsString()).isEqualTo("Set");
|
||||
assertThat(getResponse(client, "http://localhost/").getContentAsString()).isEqualTo("foo");
|
||||
assertThat(deleteResponse(client, "http://localhost/").getContentAsString()).isEqualTo("Delete");
|
||||
assertThat(getResponse(client, "http://localhost/").getContentAsString()).isEqualTo("NA");
|
||||
}
|
||||
|
||||
private void assertMockMvcUsed(WebClient client, String url) throws Exception {
|
||||
assertThat(getResponse(client, url).getContentAsString(), equalTo("mvc"));
|
||||
assertThat(getResponse(client, url).getContentAsString()).isEqualTo("mvc");
|
||||
}
|
||||
|
||||
private void assertMockMvcNotUsed(WebClient client, String url) throws Exception {
|
||||
assertThat(getResponse(client, url).getContentAsString(), not(equalTo("mvc")));
|
||||
assertThat(getResponse(client, url).getContentAsString()).isNotEqualTo("mvc");
|
||||
}
|
||||
|
||||
private WebResponse getResponse(WebClient client, String url) throws IOException {
|
||||
|
||||
@@ -29,8 +29,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Integration tests for {@link MockMvcWebConnection}.
|
||||
@@ -50,14 +49,14 @@ public class MockMvcWebConnectionTests {
|
||||
public void contextPathNull() throws IOException {
|
||||
this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, null));
|
||||
Page page = this.webClient.getPage("http://localhost/context/a");
|
||||
assertThat(page.getWebResponse().getStatusCode(), equalTo(200));
|
||||
assertThat(page.getWebResponse().getStatusCode()).isEqualTo(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contextPathExplicit() throws IOException {
|
||||
this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, "/context"));
|
||||
Page page = this.webClient.getPage("http://localhost/context/a");
|
||||
assertThat(page.getWebResponse().getStatusCode(), equalTo(200));
|
||||
assertThat(page.getWebResponse().getStatusCode()).isEqualTo(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,7 +77,7 @@ public class MockMvcWebConnectionTests {
|
||||
public void forward() throws IOException {
|
||||
this.webClient.setWebConnection(new MockMvcWebConnection(this.mockMvc, this.webClient, ""));
|
||||
Page page = this.webClient.getPage("http://localhost/forward");
|
||||
assertThat(page.getWebResponse().getContentAsString(), equalTo("hello"));
|
||||
assertThat(page.getWebResponse().getContentAsString()).isEqualTo("hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -29,11 +29,9 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.hamcrest.CoreMatchers.endsWith;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.startsWith;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
|
||||
/**
|
||||
* Tests for {@link MockWebResponseBuilder}.
|
||||
@@ -79,7 +77,7 @@ public class MockWebResponseBuilderTests {
|
||||
this.response.getWriter().write("expected content");
|
||||
WebResponse webResponse = this.responseBuilder.build();
|
||||
|
||||
assertThat(webResponse.getContentAsString(), equalTo("expected content"));
|
||||
assertThat(webResponse.getContentAsString()).isEqualTo("expected content");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,7 +85,7 @@ public class MockWebResponseBuilderTests {
|
||||
this.response.addHeader("Content-Type", "text/html; charset=UTF-8");
|
||||
WebResponse webResponse = this.responseBuilder.build();
|
||||
|
||||
assertThat(webResponse.getContentCharset(), equalTo(StandardCharsets.UTF_8));
|
||||
assertThat(webResponse.getContentCharset()).isEqualTo(StandardCharsets.UTF_8);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,7 +93,7 @@ public class MockWebResponseBuilderTests {
|
||||
this.response.addHeader("Content-Type", "text/html; charset-UTF-8");
|
||||
WebResponse webResponse = this.responseBuilder.build();
|
||||
|
||||
assertThat(webResponse.getContentType(), equalTo("text/html"));
|
||||
assertThat(webResponse.getContentType()).isEqualTo("text/html");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,17 +110,18 @@ public class MockWebResponseBuilderTests {
|
||||
WebResponse webResponse = this.responseBuilder.build();
|
||||
|
||||
List<NameValuePair> responseHeaders = webResponse.getResponseHeaders();
|
||||
assertThat(responseHeaders.size(), equalTo(3));
|
||||
assertThat(responseHeaders.size()).isEqualTo(3);
|
||||
NameValuePair header = responseHeaders.get(0);
|
||||
assertThat(header.getName(), equalTo("Content-Type"));
|
||||
assertThat(header.getValue(), equalTo("text/html"));
|
||||
assertThat(header.getName()).isEqualTo("Content-Type");
|
||||
assertThat(header.getValue()).isEqualTo("text/html");
|
||||
header = responseHeaders.get(1);
|
||||
assertThat(header.getName(), equalTo("X-Test"));
|
||||
assertThat(header.getValue(), equalTo("value"));
|
||||
assertThat(header.getName()).isEqualTo("X-Test");
|
||||
assertThat(header.getValue()).isEqualTo("value");
|
||||
header = responseHeaders.get(2);
|
||||
assertThat(header.getName(), equalTo("Set-Cookie"));
|
||||
assertThat(header.getValue(), startsWith("cookieA=valueA; Path=/path; Domain=domain; Max-Age=1800; Expires="));
|
||||
assertThat(header.getValue(), endsWith("; Secure; HttpOnly"));
|
||||
assertThat(header.getName()).isEqualTo("Set-Cookie");
|
||||
assertThat(header.getValue())
|
||||
.startsWith("cookieA=valueA; Path=/path; Domain=domain; Max-Age=1800; Expires=")
|
||||
.endsWith("; Secure; HttpOnly");
|
||||
}
|
||||
|
||||
// SPR-14169
|
||||
@@ -133,18 +132,18 @@ public class MockWebResponseBuilderTests {
|
||||
WebResponse webResponse = this.responseBuilder.build();
|
||||
|
||||
List<NameValuePair> responseHeaders = webResponse.getResponseHeaders();
|
||||
assertThat(responseHeaders.size(), equalTo(1));
|
||||
assertThat(responseHeaders.size()).isEqualTo(1);
|
||||
NameValuePair header = responseHeaders.get(0);
|
||||
assertThat(header.getName(), equalTo("Set-Cookie"));
|
||||
assertThat(header.getValue(), equalTo("cookieA=valueA"));
|
||||
assertThat(header.getName()).isEqualTo("Set-Cookie");
|
||||
assertThat(header.getValue()).isEqualTo("cookieA=valueA");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildStatus() throws Exception {
|
||||
WebResponse webResponse = this.responseBuilder.build();
|
||||
|
||||
assertThat(webResponse.getStatusCode(), equalTo(200));
|
||||
assertThat(webResponse.getStatusMessage(), equalTo("OK"));
|
||||
assertThat(webResponse.getStatusCode()).isEqualTo(200);
|
||||
assertThat(webResponse.getStatusMessage()).isEqualTo("OK");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -152,8 +151,8 @@ public class MockWebResponseBuilderTests {
|
||||
this.response.setStatus(401);
|
||||
WebResponse webResponse = this.responseBuilder.build();
|
||||
|
||||
assertThat(webResponse.getStatusCode(), equalTo(401));
|
||||
assertThat(webResponse.getStatusMessage(), equalTo("Unauthorized"));
|
||||
assertThat(webResponse.getStatusCode()).isEqualTo(401);
|
||||
assertThat(webResponse.getStatusMessage()).isEqualTo("Unauthorized");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -161,15 +160,15 @@ public class MockWebResponseBuilderTests {
|
||||
this.response.sendError(401, "Custom");
|
||||
WebResponse webResponse = this.responseBuilder.build();
|
||||
|
||||
assertThat(webResponse.getStatusCode(), equalTo(401));
|
||||
assertThat(webResponse.getStatusMessage(), equalTo("Custom"));
|
||||
assertThat(webResponse.getStatusCode()).isEqualTo(401);
|
||||
assertThat(webResponse.getStatusMessage()).isEqualTo("Custom");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildWebRequest() throws Exception {
|
||||
WebResponse webResponse = this.responseBuilder.build();
|
||||
|
||||
assertThat(webResponse.getWebRequest(), equalTo(this.webRequest));
|
||||
assertThat(webResponse.getWebRequest()).isEqualTo(this.webRequest);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,11 +40,8 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -124,19 +121,19 @@ public class MockMvcHtmlUnitDriverBuilderTests {
|
||||
this.driver = MockMvcHtmlUnitDriverBuilder.mockMvcSetup(this.mockMvc)
|
||||
.withDelegate(otherDriver).build();
|
||||
|
||||
assertThat(get("http://localhost/"), equalTo(""));
|
||||
assertThat(get("http://localhost/")).isEqualTo("");
|
||||
Cookie cookie = new Cookie("localhost", "cookie", "cookieManagerShared");
|
||||
otherDriver.getWebClient().getCookieManager().addCookie(cookie);
|
||||
assertThat(get("http://localhost/"), equalTo("cookieManagerShared"));
|
||||
assertThat(get("http://localhost/")).isEqualTo("cookieManagerShared");
|
||||
}
|
||||
|
||||
|
||||
private void assertMockMvcUsed(String url) throws Exception {
|
||||
assertThat(get(url), containsString(EXPECTED_BODY));
|
||||
assertThat(get(url)).contains(EXPECTED_BODY);
|
||||
}
|
||||
|
||||
private void assertMockMvcNotUsed(String url) throws Exception {
|
||||
assertThat(get(url), not(containsString(EXPECTED_BODY)));
|
||||
assertThat(get(url)).doesNotContain(EXPECTED_BODY);
|
||||
}
|
||||
|
||||
private String get(String url) throws IOException {
|
||||
|
||||
@@ -27,11 +27,9 @@ import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.openqa.selenium.WebDriverException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
@@ -58,7 +56,7 @@ public class WebConnectionHtmlUnitDriverTests {
|
||||
|
||||
@Test
|
||||
public void getWebConnectionDefaultNotNull() {
|
||||
assertThat(this.driver.getWebConnection(), notNullValue());
|
||||
assertThat(this.driver.getWebConnection()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,7 +68,7 @@ public class WebConnectionHtmlUnitDriverTests {
|
||||
@Test
|
||||
public void setWebConnection() {
|
||||
this.driver.setWebConnection(this.connection);
|
||||
assertThat(this.driver.getWebConnection(), equalTo(this.connection));
|
||||
assertThat(this.driver.getWebConnection()).isEqualTo(this.connection);
|
||||
assertThatExceptionOfType(WebDriverException.class).isThrownBy(() ->
|
||||
this.driver.get("https://example.com"));
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for
|
||||
* {@link org.springframework.test.web.servlet.result.ModelResultMatchers}.
|
||||
|
||||
@@ -41,10 +41,7 @@ import org.springframework.web.context.support.GenericWebApplicationContext;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
|
||||
@@ -93,12 +90,12 @@ public class CustomRequestAttributesRequestContextHolderTests {
|
||||
@After
|
||||
public void verifyCustomRequestAttributesAreRestored() {
|
||||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||
assertThat(requestAttributes, instanceOf(ServletRequestAttributes.class));
|
||||
assertThat(requestAttributes).isInstanceOf(ServletRequestAttributes.class);
|
||||
HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
|
||||
|
||||
assertThat(request.getAttribute(FROM_CUSTOM_MOCK), is(FROM_CUSTOM_MOCK));
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_DEFAULT), is(nullValue()));
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_MOCK), is(nullValue()));
|
||||
assertThat(request.getAttribute(FROM_CUSTOM_MOCK)).isEqualTo(FROM_CUSTOM_MOCK);
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_DEFAULT)).isNull();
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_MOCK)).isNull();
|
||||
|
||||
RequestContextHolder.resetRequestAttributes();
|
||||
this.wac.close();
|
||||
@@ -128,14 +125,14 @@ public class CustomRequestAttributesRequestContextHolderTests {
|
||||
|
||||
private static void assertRequestAttributes() {
|
||||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||
assertThat(requestAttributes, instanceOf(ServletRequestAttributes.class));
|
||||
assertThat(requestAttributes).isInstanceOf(ServletRequestAttributes.class);
|
||||
assertRequestAttributes(((ServletRequestAttributes) requestAttributes).getRequest());
|
||||
}
|
||||
|
||||
private static void assertRequestAttributes(ServletRequest request) {
|
||||
assertThat(request.getAttribute(FROM_CUSTOM_MOCK), is(nullValue()));
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_DEFAULT), is(FROM_MVC_TEST_DEFAULT));
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_MOCK), is(FROM_MVC_TEST_MOCK));
|
||||
assertThat(request.getAttribute(FROM_CUSTOM_MOCK)).isNull();
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_DEFAULT)).isEqualTo(FROM_MVC_TEST_DEFAULT);
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_MOCK)).isEqualTo(FROM_MVC_TEST_MOCK);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,10 +51,7 @@ import org.springframework.web.filter.GenericFilterBean;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
@@ -303,7 +300,7 @@ public class RequestContextHolderTests {
|
||||
|
||||
private static void assertRequestAttributes(boolean withinMockMvc) {
|
||||
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
|
||||
assertThat(requestAttributes, instanceOf(ServletRequestAttributes.class));
|
||||
assertThat(requestAttributes).isInstanceOf(ServletRequestAttributes.class);
|
||||
assertRequestAttributes(((ServletRequestAttributes) requestAttributes).getRequest(), withinMockMvc);
|
||||
}
|
||||
|
||||
@@ -313,18 +310,18 @@ public class RequestContextHolderTests {
|
||||
|
||||
private static void assertRequestAttributes(ServletRequest request, boolean withinMockMvc) {
|
||||
if (withinMockMvc) {
|
||||
assertThat(request.getAttribute(FROM_TCF_MOCK), is(nullValue()));
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_DEFAULT), is(FROM_MVC_TEST_DEFAULT));
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_MOCK), is(FROM_MVC_TEST_MOCK));
|
||||
assertThat(request.getAttribute(FROM_REQUEST_FILTER), is(FROM_REQUEST_FILTER));
|
||||
assertThat(request.getAttribute(FROM_REQUEST_ATTRIBUTES_FILTER), is(FROM_REQUEST_ATTRIBUTES_FILTER));
|
||||
assertThat(request.getAttribute(FROM_TCF_MOCK)).isNull();
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_DEFAULT)).isEqualTo(FROM_MVC_TEST_DEFAULT);
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_MOCK)).isEqualTo(FROM_MVC_TEST_MOCK);
|
||||
assertThat(request.getAttribute(FROM_REQUEST_FILTER)).isEqualTo(FROM_REQUEST_FILTER);
|
||||
assertThat(request.getAttribute(FROM_REQUEST_ATTRIBUTES_FILTER)).isEqualTo(FROM_REQUEST_ATTRIBUTES_FILTER);
|
||||
}
|
||||
else {
|
||||
assertThat(request.getAttribute(FROM_TCF_MOCK), is(FROM_TCF_MOCK));
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_DEFAULT), is(nullValue()));
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_MOCK), is(nullValue()));
|
||||
assertThat(request.getAttribute(FROM_REQUEST_FILTER), is(nullValue()));
|
||||
assertThat(request.getAttribute(FROM_REQUEST_ATTRIBUTES_FILTER), is(nullValue()));
|
||||
assertThat(request.getAttribute(FROM_TCF_MOCK)).isEqualTo(FROM_TCF_MOCK);
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_DEFAULT)).isNull();
|
||||
assertThat(request.getAttribute(FROM_MVC_TEST_MOCK)).isNull();
|
||||
assertThat(request.getAttribute(FROM_REQUEST_FILTER)).isNull();
|
||||
assertThat(request.getAttribute(FROM_REQUEST_ATTRIBUTES_FILTER)).isNull();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,11 +35,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.context.request.WebRequest;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.equalTo;
|
||||
import static org.hamcrest.CoreMatchers.hasItems;
|
||||
import static org.hamcrest.CoreMatchers.nullValue;
|
||||
import static org.hamcrest.CoreMatchers.startsWith;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
@@ -31,9 +31,10 @@ import org.springframework.mock.web.MockFilterConfig;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author Rob Winch
|
||||
@@ -66,14 +67,14 @@ public class ConditionalDelegatingFilterProxyTests {
|
||||
FilterConfig config = new MockFilterConfig();
|
||||
filter = new PatternMappingFilterProxy(delegate, "/");
|
||||
filter.init(config);
|
||||
assertThat(delegate.filterConfig, is(config));
|
||||
assertThat(delegate.filterConfig).isEqualTo(config);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void destroy() throws Exception {
|
||||
filter = new PatternMappingFilterProxy(delegate, "/");
|
||||
filter.destroy();
|
||||
assertThat(delegate.destroy, is(true));
|
||||
assertThat(delegate.destroy).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -235,12 +236,12 @@ public class ConditionalDelegatingFilterProxyTests {
|
||||
filter = new PatternMappingFilterProxy(delegate, pattern);
|
||||
filter.doFilter(request, response, filterChain);
|
||||
|
||||
assertThat(delegate.request, equalTo((ServletRequest) null));
|
||||
assertThat(delegate.response, equalTo((ServletResponse) null));
|
||||
assertThat(delegate.chain, equalTo((FilterChain) null));
|
||||
assertThat(delegate.request).isNull();
|
||||
assertThat(delegate.response).isNull();
|
||||
assertThat(delegate.chain).isNull();
|
||||
|
||||
assertThat(filterChain.getRequest(), equalTo((ServletRequest) request));
|
||||
assertThat(filterChain.getResponse(), equalTo((ServletResponse) response));
|
||||
assertThat(filterChain.getRequest()).isEqualTo(request);
|
||||
assertThat(filterChain.getResponse()).isEqualTo(response);
|
||||
filterChain = new MockFilterChain();
|
||||
}
|
||||
|
||||
@@ -249,9 +250,9 @@ public class ConditionalDelegatingFilterProxyTests {
|
||||
filter = new PatternMappingFilterProxy(delegate, pattern);
|
||||
filter.doFilter(request, response, filterChain);
|
||||
|
||||
assertThat(delegate.request, equalTo((ServletRequest) request));
|
||||
assertThat(delegate.response, equalTo((ServletResponse) response));
|
||||
assertThat(delegate.chain, equalTo((FilterChain) filterChain));
|
||||
assertThat(delegate.request).isEqualTo(request);
|
||||
assertThat(delegate.response).isEqualTo(response);
|
||||
assertThat(delegate.chain).isEqualTo(filterChain);
|
||||
delegate = new MockFilter();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user