Refactor AssertJ assertions into more idiomatic ones
This commit refactors some AssertJ assertions into more idiomatic and readable ones. Using the dedicated assertion instead of a generic one will produce more meaningful error messages. For instance, consider collection size: ``` // expected: 5 but was: 2 assertThat(collection.size()).equals(5); // Expected size: 5 but was: 2 in: [1, 2] assertThat(collection).hasSize(5); ``` Closes gh-30104
This commit is contained in:
@@ -382,7 +382,7 @@ class MockHttpServletRequestTests {
|
||||
void emptyAcceptLanguageHeader() {
|
||||
request.addHeader("Accept-Language", "");
|
||||
assertThat(request.getLocale()).isEqualTo(Locale.ENGLISH);
|
||||
assertThat(request.getHeader("Accept-Language")).isEqualTo("");
|
||||
assertThat(request.getHeader("Accept-Language")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -107,7 +107,7 @@ class MockHttpSessionTests {
|
||||
|
||||
session.setAttribute(bindingListenerName, bindingListener);
|
||||
|
||||
assertThat(1).isEqualTo(bindingListener.getCounter());
|
||||
assertThat(bindingListener.getCounter()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -118,7 +118,7 @@ class MockHttpSessionTests {
|
||||
session.setAttribute(bindingListenerName, bindingListener);
|
||||
session.removeAttribute(bindingListenerName);
|
||||
|
||||
assertThat(0).isEqualTo(bindingListener.getCounter());
|
||||
assertThat(bindingListener.getCounter()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,7 +129,7 @@ class MockHttpSessionTests {
|
||||
session.setAttribute(bindingListenerName, bindingListener);
|
||||
session.setAttribute(bindingListenerName, bindingListener);
|
||||
|
||||
assertThat(1).isEqualTo(bindingListener.getCounter());
|
||||
assertThat(bindingListener.getCounter()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,8 +141,8 @@ class MockHttpSessionTests {
|
||||
session.setAttribute(bindingListenerName, bindingListener1);
|
||||
session.setAttribute(bindingListenerName, bindingListener2);
|
||||
|
||||
assertThat(0).isEqualTo(bindingListener1.getCounter());
|
||||
assertThat(1).isEqualTo(bindingListener2.getCounter());
|
||||
assertThat(bindingListener1.getCounter()).isEqualTo(0);
|
||||
assertThat(bindingListener2.getCounter()).isEqualTo(1);
|
||||
}
|
||||
|
||||
private static class CountingHttpSessionBindingListener
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -99,7 +99,7 @@ class MockMultipartHttpServletRequestTests {
|
||||
assertThat(fileMap.get("file2")).isEqualTo(file2);
|
||||
|
||||
assertThat(file1.getName()).isEqualTo("file1");
|
||||
assertThat(file1.getOriginalFilename()).isEqualTo("");
|
||||
assertThat(file1.getOriginalFilename()).isEmpty();
|
||||
assertThat(file1.getContentType()).isNull();
|
||||
assertThat(ObjectUtils.nullSafeEquals("myContent1".getBytes(), file1.getBytes())).isTrue();
|
||||
assertThat(ObjectUtils.nullSafeEquals("myContent1".getBytes(),
|
||||
|
||||
@@ -240,7 +240,7 @@ class MergedContextConfigurationTests {
|
||||
void equalsBasics() {
|
||||
MergedContextConfiguration mergedConfig = new MergedContextConfiguration(null, null, null, null, null);
|
||||
assertThat(mergedConfig).isEqualTo(mergedConfig);
|
||||
assertThat(mergedConfig).isNotEqualTo(null);
|
||||
assertThat(mergedConfig).isNotNull();
|
||||
assertThat(mergedConfig).isNotEqualTo(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -86,8 +86,8 @@ class GroovySpringContextTests implements BeanNameAware, InitializingBean {
|
||||
|
||||
@Test
|
||||
void verifyBeanNameSet() {
|
||||
assertThat(this.beanName.startsWith(getClass().getName())).as("The bean name of this test instance should have been set to the fully qualified class name " +
|
||||
"due to BeanNameAware semantics.").isTrue();
|
||||
assertThat(this.beanName).as("The bean name of this test instance should have been set to the fully qualified class name " +
|
||||
"due to BeanNameAware semantics.").startsWith(getClass().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -244,10 +244,10 @@ class MergedSqlConfigTests {
|
||||
private void assertDefaults(MergedSqlConfig cfg) {
|
||||
assertSoftly(softly -> {
|
||||
softly.assertThat(cfg).isNotNull();
|
||||
softly.assertThat(cfg.getDataSource()).as("dataSource").isEqualTo("");
|
||||
softly.assertThat(cfg.getTransactionManager()).as("transactionManager").isEqualTo("");
|
||||
softly.assertThat(cfg.getDataSource()).as("dataSource").isEmpty();
|
||||
softly.assertThat(cfg.getTransactionManager()).as("transactionManager").isEmpty();
|
||||
softly.assertThat(cfg.getTransactionMode()).as("transactionMode").isEqualTo(INFERRED);
|
||||
softly.assertThat(cfg.getEncoding()).as("encoding").isEqualTo("");
|
||||
softly.assertThat(cfg.getEncoding()).as("encoding").isEmpty();
|
||||
softly.assertThat(cfg.getSeparator()).as("separator").isEqualTo(DEFAULT_STATEMENT_SEPARATOR);
|
||||
softly.assertThat(cfg.getCommentPrefixes()).as("commentPrefixes").isEqualTo(DEFAULT_COMMENT_PREFIXES);
|
||||
softly.assertThat(cfg.getBlockCommentStartDelimiter()).as("blockCommentStartDelimiter").isEqualTo(DEFAULT_BLOCK_COMMENT_START_DELIMITER);
|
||||
@@ -270,8 +270,8 @@ class MergedSqlConfigTests {
|
||||
|
||||
assertSoftly(softly -> {
|
||||
softly.assertThat(cfg).isNotNull();
|
||||
softly.assertThat(cfg.getDataSource()).as("dataSource").isEqualTo("");
|
||||
softly.assertThat(cfg.getTransactionManager()).as("transactionManager").isEqualTo("");
|
||||
softly.assertThat(cfg.getDataSource()).as("dataSource").isEmpty();
|
||||
softly.assertThat(cfg.getTransactionManager()).as("transactionManager").isEmpty();
|
||||
softly.assertThat(cfg.getTransactionMode()).as("transactionMode").isEqualTo(INFERRED);
|
||||
softly.assertThat(cfg.getEncoding()).as("encoding").isEqualTo("global");
|
||||
softly.assertThat(cfg.getSeparator()).as("separator").isEqualTo("\n");
|
||||
@@ -289,8 +289,8 @@ class MergedSqlConfigTests {
|
||||
|
||||
assertSoftly(softly -> {
|
||||
softly.assertThat(cfg).isNotNull();
|
||||
softly.assertThat(cfg.getDataSource()).as("dataSource").isEqualTo("");
|
||||
softly.assertThat(cfg.getTransactionManager()).as("transactionManager").isEqualTo("");
|
||||
softly.assertThat(cfg.getDataSource()).as("dataSource").isEmpty();
|
||||
softly.assertThat(cfg.getTransactionManager()).as("transactionManager").isEmpty();
|
||||
softly.assertThat(cfg.getTransactionMode()).as("transactionMode").isEqualTo(INFERRED);
|
||||
softly.assertThat(cfg.getEncoding()).as("encoding").isEqualTo("local");
|
||||
softly.assertThat(cfg.getSeparator()).as("separator").isEqualTo("@@");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -135,7 +135,7 @@ class RegisterExtensionSpringExtensionTests {
|
||||
@Test
|
||||
void autowiredParameterAsJavaUtilOptional(@Autowired Optional<Dog> dog) {
|
||||
assertThat(dog).as("Optional dog should have been @Autowired by Spring").isNotNull();
|
||||
assertThat(dog.isPresent()).as("Value of Optional should be 'present'").isTrue();
|
||||
assertThat(dog).as("Value of Optional should be 'present'").isPresent();
|
||||
assertThat(dog.get().getName()).as("Dog's name").isEqualTo("Dogbert");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -119,8 +119,8 @@ public class ConcreteTransactionalJUnit4SpringContextTests extends AbstractTrans
|
||||
@Transactional(propagation = Propagation.NOT_SUPPORTED)
|
||||
public void verifyBeanNameSet() {
|
||||
assertThatTransaction().isNotActive();
|
||||
assertThat(this.beanName.startsWith(getClass().getName())).as("The bean name of this test instance should have been set to the fully qualified class name " +
|
||||
"due to BeanNameAware semantics.").isTrue();
|
||||
assertThat(this.beanName).as("The bean name of this test instance should have been set to the fully qualified class name " +
|
||||
"due to BeanNameAware semantics.").startsWith(getClass().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -163,7 +163,8 @@ public class SpringJUnit4ClassRunnerAppCtxTests implements ApplicationContextAwa
|
||||
|
||||
@Test
|
||||
public void verifyBeanNameSet() {
|
||||
assertThat(this.beanName.startsWith(getClass().getName())).as("The bean name of this test instance should have been set due to BeanNameAware semantics.").isTrue();
|
||||
assertThat(this.beanName).as("The bean name of this test instance should have been set due to BeanNameAware semantics.")
|
||||
.startsWith(getClass().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -201,7 +202,7 @@ public class SpringJUnit4ClassRunnerAppCtxTests implements ApplicationContextAwa
|
||||
assertThat(this.literalFieldValue).as("Literal @Value field should have been autowired").isNotNull();
|
||||
assertThat(this.spelFieldValue).as("SpEL @Value field should have been autowired.").isNotNull();
|
||||
assertThat(this.literalFieldValue).isEqualTo("enigma");
|
||||
assertThat(this.spelFieldValue).isEqualTo(Boolean.TRUE);
|
||||
assertThat(this.spelFieldValue).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -209,7 +210,7 @@ public class SpringJUnit4ClassRunnerAppCtxTests implements ApplicationContextAwa
|
||||
assertThat(this.literalParameterValue).as("Literal @Value method parameter should have been autowired.").isNotNull();
|
||||
assertThat(this.spelParameterValue).as("SpEL @Value method parameter should have been autowired.").isNotNull();
|
||||
assertThat(this.literalParameterValue).isEqualTo("enigma");
|
||||
assertThat(this.spelParameterValue).isEqualTo(Boolean.TRUE);
|
||||
assertThat(this.spelParameterValue).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -93,7 +93,7 @@ public class StandardJUnit4FeaturesTests {
|
||||
|
||||
@Test
|
||||
public void verifyBeforeAnnotation() {
|
||||
assertThat(this.beforeCounter).isEqualTo(1);
|
||||
assertThat(this.beforeCounter).isOne();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,7 +101,7 @@ public class StandardJUnit4FeaturesTests {
|
||||
// Instead of testing for equality to 1, we just assert that the value
|
||||
// was incremented at least once, since this test class may serve as a
|
||||
// parent class to other tests in a suite, etc.
|
||||
assertThat(StandardJUnit4FeaturesTests.staticBeforeCounter > 0).isTrue();
|
||||
assertThat(StandardJUnit4FeaturesTests.staticBeforeCounter).isGreaterThan(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -91,46 +91,46 @@ class AnnotationConfigContextLoaderTests {
|
||||
void detectDefaultConfigurationClassesForAnnotatedInnerClass() {
|
||||
Class<?>[] configClasses = contextLoader.detectDefaultConfigurationClasses(ContextConfigurationInnerClassTestCase.class);
|
||||
assertThat(configClasses).isNotNull();
|
||||
assertThat(configClasses.length).as("annotated static ContextConfiguration should be considered.").isEqualTo(1);
|
||||
assertThat(configClasses).as("annotated static ContextConfiguration should be considered.").hasSize(1);
|
||||
|
||||
configClasses = contextLoader.detectDefaultConfigurationClasses(AnnotatedFooConfigInnerClassTestCase.class);
|
||||
assertThat(configClasses).isNotNull();
|
||||
assertThat(configClasses.length).as("annotated static FooConfig should be considered.").isEqualTo(1);
|
||||
assertThat(configClasses).as("annotated static FooConfig should be considered.").hasSize(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void detectDefaultConfigurationClassesForMultipleAnnotatedInnerClasses() {
|
||||
Class<?>[] configClasses = contextLoader.detectDefaultConfigurationClasses(MultipleStaticConfigurationClassesTestCase.class);
|
||||
assertThat(configClasses).isNotNull();
|
||||
assertThat(configClasses.length).as("multiple annotated static classes should be considered.").isEqualTo(2);
|
||||
assertThat(configClasses).as("multiple annotated static classes should be considered.").hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void detectDefaultConfigurationClassesForNonAnnotatedInnerClass() {
|
||||
Class<?>[] configClasses = contextLoader.detectDefaultConfigurationClasses(PlainVanillaFooConfigInnerClassTestCase.class);
|
||||
assertThat(configClasses).isNotNull();
|
||||
assertThat(configClasses.length).as("non-annotated static FooConfig should NOT be considered.").isEqualTo(0);
|
||||
assertThat(configClasses).as("non-annotated static FooConfig should NOT be considered.").isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void detectDefaultConfigurationClassesForFinalAnnotatedInnerClass() {
|
||||
Class<?>[] configClasses = contextLoader.detectDefaultConfigurationClasses(FinalConfigInnerClassTestCase.class);
|
||||
assertThat(configClasses).isNotNull();
|
||||
assertThat(configClasses.length).as("final annotated static Config should NOT be considered.").isEqualTo(0);
|
||||
assertThat(configClasses).as("final annotated static Config should NOT be considered.").isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void detectDefaultConfigurationClassesForPrivateAnnotatedInnerClass() {
|
||||
Class<?>[] configClasses = contextLoader.detectDefaultConfigurationClasses(PrivateConfigInnerClassTestCase.class);
|
||||
assertThat(configClasses).isNotNull();
|
||||
assertThat(configClasses.length).as("private annotated inner classes should NOT be considered.").isEqualTo(0);
|
||||
assertThat(configClasses).as("private annotated inner classes should NOT be considered.").isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
void detectDefaultConfigurationClassesForNonStaticAnnotatedInnerClass() {
|
||||
Class<?>[] configClasses = contextLoader.detectDefaultConfigurationClasses(NonStaticConfigInnerClassesTestCase.class);
|
||||
assertThat(configClasses).isNotNull();
|
||||
assertThat(configClasses.length).as("non-static annotated inner classes should NOT be considered.").isEqualTo(0);
|
||||
assertThat(configClasses).as("non-static annotated inner classes should NOT be considered.").isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -401,7 +401,7 @@ class ReflectionTestUtilsTests {
|
||||
void setFieldOnLegacyEntityWithSideEffectsInToString() {
|
||||
String testCollaborator = "test collaborator";
|
||||
setField(entity, "collaborator", testCollaborator, Object.class);
|
||||
assertThat(entity.toString().contains(testCollaborator)).isTrue();
|
||||
assertThat(entity.toString()).contains(testCollaborator);
|
||||
}
|
||||
|
||||
@Test // SPR-14363
|
||||
@@ -421,7 +421,7 @@ class ReflectionTestUtilsTests {
|
||||
void invokeSetterMethodOnLegacyEntityWithSideEffectsInToString() {
|
||||
String testCollaborator = "test collaborator";
|
||||
invokeSetterMethod(entity, "collaborator", testCollaborator);
|
||||
assertThat(entity.toString().contains(testCollaborator)).isTrue();
|
||||
assertThat(entity.toString()).contains(testCollaborator);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -180,7 +180,6 @@ class DefaultResponseCreatorTests {
|
||||
HttpHeaders responseHeaders = createResponse(creator).getHeaders();
|
||||
|
||||
assertThat(responseHeaders.get(HttpHeaders.SET_COOKIE))
|
||||
.isNotNull()
|
||||
.containsExactly(
|
||||
firstCookie.toString(),
|
||||
secondCookie.toString(),
|
||||
@@ -210,7 +209,6 @@ class DefaultResponseCreatorTests {
|
||||
HttpHeaders responseHeaders = createResponse(creator).getHeaders();
|
||||
|
||||
assertThat(responseHeaders.get(HttpHeaders.SET_COOKIE))
|
||||
.isNotNull()
|
||||
.containsExactly(
|
||||
firstCookie.toString(),
|
||||
secondCookie.toString(),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -178,7 +178,7 @@ public class SampleTests {
|
||||
this.mockServer.verify();
|
||||
}
|
||||
catch (AssertionError error) {
|
||||
assertThat(error.getMessage().contains("2 unsatisfied expectation(s)")).as(error.getMessage()).isTrue();
|
||||
assertThat(error.getMessage()).as(error.getMessage()).contains("2 unsatisfied expectation(s)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -175,7 +175,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
webRequest.setUrl(new URL("https://example.com/"));
|
||||
String contextPath = requestBuilder.buildRequest(servletContext).getContextPath();
|
||||
|
||||
assertThat(contextPath).isEqualTo("");
|
||||
assertThat(contextPath).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -404,7 +404,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getParameterMap()).hasSize(1);
|
||||
assertThat(actualRequest.getParameter("name")).isEqualTo("");
|
||||
assertThat(actualRequest.getParameter("name")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -414,7 +414,7 @@ public class HtmlUnitRequestBuilderTests {
|
||||
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
|
||||
|
||||
assertThat(actualRequest.getParameterMap()).hasSize(1);
|
||||
assertThat(actualRequest.getParameter("name")).isEqualTo("");
|
||||
assertThat(actualRequest.getParameter("name")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -115,7 +115,7 @@ public class MockMvcConnectionBuilderSupportTests {
|
||||
@Test
|
||||
public void defaultContextPathEmpty() throws Exception {
|
||||
WebConnection conn = this.builder.createConnection(this.client);
|
||||
assertThat(getResponse(conn, "http://localhost/abc").getContentAsString()).isEqualTo("");
|
||||
assertThat(getResponse(conn, "http://localhost/abc").getContentAsString()).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -100,7 +100,7 @@ class MockMvcHtmlUnitDriverBuilderTests {
|
||||
this.mockMvc = MockMvcBuilders.standaloneSetup(new CookieController()).build();
|
||||
this.driver = MockMvcHtmlUnitDriverBuilder.mockMvcSetup(this.mockMvc).withDelegate(otherDriver).build();
|
||||
|
||||
assertThat(get("http://localhost/")).isEqualTo("");
|
||||
assertThat(get("http://localhost/")).isEmpty();
|
||||
Cookie cookie = new Cookie("localhost", "cookie", "cookieManagerShared");
|
||||
otherDriver.getWebClient().getCookieManager().addCookie(cookie);
|
||||
assertThat(get("http://localhost/")).isEqualTo("cookieManagerShared");
|
||||
|
||||
@@ -169,8 +169,8 @@ class PrintingResultHandlerTests {
|
||||
List<String> cookieValues = this.response.getHeaders("Set-Cookie");
|
||||
assertThat(cookieValues).hasSize(2);
|
||||
assertThat(cookieValues.get(0)).isEqualTo("cookie=cookieValue");
|
||||
assertThat(cookieValues.get(1).startsWith(
|
||||
"enigma=42; Path=/crumbs; Domain=.example.com; Max-Age=1234; Expires=")).as("Actual: " + cookieValues.get(1)).isTrue();
|
||||
assertThat(cookieValues.get(1)).as("Actual: " + cookieValues.get(1))
|
||||
.startsWith("enigma=42; Path=/crumbs; Domain=.example.com; Max-Age=1234; Expires=");
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("header", "headerValue");
|
||||
@@ -192,14 +192,14 @@ class PrintingResultHandlerTests {
|
||||
assertThat(cookies).hasSize(2);
|
||||
String cookie1 = cookies[0];
|
||||
String cookie2 = cookies[1];
|
||||
assertThat(cookie1.startsWith("[" + Cookie.class.getSimpleName())).isTrue();
|
||||
assertThat(cookie1.contains("name = 'cookie', value = 'cookieValue'")).isTrue();
|
||||
assertThat(cookie1.endsWith("]")).isTrue();
|
||||
assertThat(cookie2.startsWith("[" + Cookie.class.getSimpleName())).isTrue();
|
||||
assertThat(cookie2.contains("name = 'enigma', value = '42', " +
|
||||
assertThat(cookie1).startsWith("[" + Cookie.class.getSimpleName());
|
||||
assertThat(cookie1).contains("name = 'cookie', value = 'cookieValue'");
|
||||
assertThat(cookie1).endsWith("]");
|
||||
assertThat(cookie2).startsWith("[" + Cookie.class.getSimpleName());
|
||||
assertThat(cookie2).contains("name = 'enigma', value = '42', " +
|
||||
"comment = [null], domain = '.example.com', maxAge = 1234, " +
|
||||
"path = '/crumbs', secure = true, version = 0, httpOnly = true")).isTrue();
|
||||
assertThat(cookie2.endsWith("]")).isTrue();
|
||||
"path = '/crumbs', secure = true, version = 0, httpOnly = true");
|
||||
assertThat(cookie2).endsWith("]");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -243,9 +243,9 @@ public class HeaderAssertionTests {
|
||||
}
|
||||
|
||||
private void assertMessageContains(AssertionError error, String expected) {
|
||||
assertThat(error.getMessage().contains(expected))
|
||||
assertThat(error.getMessage())
|
||||
.as("Failure message should contain [" + expected + "], actual is [" + error.getMessage() + "]")
|
||||
.isTrue();
|
||||
.contains(expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -174,7 +174,7 @@ class AsyncTests {
|
||||
.andExpect(request().asyncStarted())
|
||||
.andReturn();
|
||||
|
||||
assertThat(writer.toString().contains("Async started = true")).isTrue();
|
||||
assertThat(writer.toString()).contains("Async started = true");
|
||||
writer = new StringWriter();
|
||||
|
||||
this.mockMvc.perform(asyncDispatch(mvcResult))
|
||||
@@ -183,7 +183,7 @@ class AsyncTests {
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(content().string("{\"name\":\"Joe\",\"someDouble\":0.0,\"someBoolean\":false}"));
|
||||
|
||||
assertThat(writer.toString().contains("Async started = false")).isTrue();
|
||||
assertThat(writer.toString()).contains("Async started = false");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -213,7 +213,8 @@ public class HeaderAssertionTests {
|
||||
}
|
||||
|
||||
private void assertMessageContains(AssertionError error, String expected) {
|
||||
assertThat(error.getMessage().contains(expected)).as("Failure message should contain [" + expected + "], actual is [" + error.getMessage() + "]").isTrue();
|
||||
assertThat(error.getMessage()).as("Failure message should contain [" + expected + "], actual is [" + error.getMessage() + "]")
|
||||
.contains(expected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user