Polishing
This commit is contained in:
@@ -33,7 +33,6 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public abstract class BeanOverrideContextCustomizerTestUtils {
|
||||
|
||||
|
||||
private static final BeanOverrideContextCustomizerFactory factory = new BeanOverrideContextCustomizerFactory();
|
||||
|
||||
/**
|
||||
@@ -49,12 +48,12 @@ public abstract class BeanOverrideContextCustomizerTestUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the given {@linkplain ConfigurableApplicationContext application
|
||||
* Customize the given {@linkplain ConfigurableApplicationContext application
|
||||
* context} for the given {@code testClass}.
|
||||
* @param testClass the test to process
|
||||
* @param context the context to configure
|
||||
* @param context the context to customize
|
||||
*/
|
||||
public static void configureApplicationContext(Class<?> testClass, ConfigurableApplicationContext context) {
|
||||
public static void customizeApplicationContext(Class<?> testClass, ConfigurableApplicationContext context) {
|
||||
ContextCustomizer contextCustomizer = createContextCustomizer(testClass);
|
||||
if (contextCustomizer != null) {
|
||||
contextCustomizer.customizeContext(context, mock(MergedContextConfiguration.class));
|
||||
|
||||
@@ -128,7 +128,6 @@ class TestBeanForInheritanceIntegrationTests {
|
||||
@DisplayName("Nested, concrete inherited tests with correct @TestBean setup")
|
||||
class NestedConcreteTestBeanIntegrationTests extends AbstractTestBeanIntegrationTestCase {
|
||||
|
||||
|
||||
@Autowired
|
||||
ApplicationContext ctx;
|
||||
|
||||
@@ -141,6 +140,7 @@ class TestBeanForInheritanceIntegrationTests {
|
||||
static Pojo someBean() {
|
||||
return new FakePojo("someBeanOverride");
|
||||
}
|
||||
|
||||
// Hides otherBean() defined in AbstractTestBeanIntegrationTestCase.
|
||||
static Pojo otherBean() {
|
||||
return new FakePojo("otherBean in subclass");
|
||||
@@ -169,4 +169,5 @@ class TestBeanForInheritanceIntegrationTests {
|
||||
assertThat(this.pojo2.getValue()).as("injection point").isEqualTo("in enclosing test class");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link TestBean} that use a bean factory methods
|
||||
* defined in implemented interfaces.
|
||||
* Integration tests for {@link TestBean} that use bean factory methods defined
|
||||
* in implemented interfaces.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 6.2
|
||||
|
||||
@@ -124,8 +124,8 @@ class TestBeanOverrideProcessorTests {
|
||||
TestBean overrideAnnotation = field.getAnnotation(TestBean.class);
|
||||
assertThat(overrideAnnotation).isNotNull();
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(() -> this.processor.createMetadata(
|
||||
overrideAnnotation, clazz, field))
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.processor.createMetadata(overrideAnnotation, clazz, field))
|
||||
.withMessage("No static method found named field() or someField() in %s with return type %s",
|
||||
clazz.getName(), returnType.getName());
|
||||
}
|
||||
@@ -136,7 +136,8 @@ class TestBeanOverrideProcessorTests {
|
||||
Field field = clazz.getField("field");
|
||||
NonNull badAnnotation = AnnotationUtils.synthesizeAnnotation(NonNull.class);
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(() -> this.processor.createMetadata(badAnnotation, clazz, field))
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.processor.createMetadata(badAnnotation, clazz, field))
|
||||
.withMessage("Invalid annotation passed to TestBeanOverrideProcessor: expected @TestBean" +
|
||||
" on field %s.%s", field.getDeclaringClass().getName(), field.getName());
|
||||
}
|
||||
|
||||
@@ -18,12 +18,13 @@ package org.springframework.test.context.bean.override.convention;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.test.context.bean.override.BeanOverrideContextCustomizerTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* Tests for {@link TestBean}.
|
||||
*
|
||||
@@ -35,8 +36,9 @@ public class TestBeanTests {
|
||||
void contextCustomizerCannotBeCreatedWithNoSuchBeanName() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBean("anotherBean", String.class, () -> "example");
|
||||
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(FailureByNameLookup.class, context);
|
||||
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
|
||||
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByNameLookup.class, context);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to override bean 'beanToOverride': there is no bean definition \
|
||||
to replace with that name of type java.lang.String""");
|
||||
@@ -45,8 +47,9 @@ public class TestBeanTests {
|
||||
@Test
|
||||
void contextCustomizerCannotBeCreatedWithNoSuchBeanType() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(FailureByTypeLookup.class, context);
|
||||
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
|
||||
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByTypeLookup.class, context);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to override bean: no bean definitions of \
|
||||
type %s (as required by annotated field '%s.example')""".formatted(
|
||||
@@ -58,8 +61,9 @@ public class TestBeanTests {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBean("bean1", String.class, () -> "example1");
|
||||
context.registerBean("bean2", String.class, () -> "example2");
|
||||
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(FailureByTypeLookup.class, context);
|
||||
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
|
||||
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByTypeLookup.class, context);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to select a bean definition to override: found 2 bean definitions \
|
||||
of type %s (as required by annotated field '%s.example'): %s""".formatted(
|
||||
@@ -70,8 +74,9 @@ public class TestBeanTests {
|
||||
void contextCustomizerCannotBeCreatedWithBeanOfWrongType() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBean("beanToOverride", Integer.class, () -> 42);
|
||||
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(FailureByNameLookup.class, context);
|
||||
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
|
||||
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(FailureByNameLookup.class, context);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to override bean 'beanToOverride': there is no bean definition \
|
||||
to replace with that name of type %s""".formatted(
|
||||
@@ -81,8 +86,8 @@ public class TestBeanTests {
|
||||
@Test
|
||||
void contextCustomizerCannotBeCreatedWithMissingOverrideMethod() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
Assertions.assertThatIllegalStateException()
|
||||
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.configureApplicationContext(
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(
|
||||
FailureMissingDefaultOverrideMethod.class, context))
|
||||
.withMessage("No static method found named example() or beanToOverride() in %s with return type %s"
|
||||
.formatted(FailureMissingDefaultOverrideMethod.class.getName(), String.class.getName()));
|
||||
@@ -91,8 +96,8 @@ public class TestBeanTests {
|
||||
@Test
|
||||
void contextCustomizerCannotBeCreatedWithMissingExplicitOverrideMethod() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
Assertions.assertThatIllegalStateException()
|
||||
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.configureApplicationContext(
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(
|
||||
FailureMissingExplicitOverrideMethod.class, context))
|
||||
.withMessage("No static method found named createExample() in %s with return type %s"
|
||||
.formatted(FailureMissingExplicitOverrideMethod.class.getName(), String.class.getName()));
|
||||
@@ -102,8 +107,8 @@ public class TestBeanTests {
|
||||
void contextCustomizerCannotBeCreatedWithFieldInParentAndMissingOverrideMethod() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBean("beanToOverride", String.class, () -> "example");
|
||||
Assertions.assertThatIllegalStateException()
|
||||
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.configureApplicationContext(
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(
|
||||
FailureOverrideInParentWithoutFactoryMethod.class, context))
|
||||
.withMessage("No static method found named beanToOverride() in %s with return type %s"
|
||||
.formatted(FailureOverrideInParentWithoutFactoryMethod.class.getName(), String.class.getName()));
|
||||
@@ -113,8 +118,8 @@ public class TestBeanTests {
|
||||
void contextCustomizerCannotBeCreatedWitCompetingOverrideMethods() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBean("bean", String.class, () -> "example");
|
||||
Assertions.assertThatIllegalStateException()
|
||||
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.configureApplicationContext(
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(
|
||||
FailureCompetingOverrideMethods.class, context))
|
||||
.withMessage("Found 2 competing static methods named example() or beanToOverride() in %s with return type %s"
|
||||
.formatted(FailureCompetingOverrideMethods.class.getName(), String.class.getName()));
|
||||
|
||||
@@ -32,7 +32,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
class MockitoBeanContextCustomizerEqualityTests {
|
||||
|
||||
|
||||
@Test
|
||||
void contextCustomizerWithSameMockByNameInDifferentClassIsEqual() {
|
||||
assertThat(createContextCustomizer(Case1ByName.class)).isEqualTo(createContextCustomizer(Case2ByName.class));
|
||||
|
||||
@@ -17,14 +17,13 @@
|
||||
package org.springframework.test.context.bean.override.mockito;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
@@ -35,11 +34,9 @@ import static org.mockito.Mockito.mock;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringJUnitConfig
|
||||
class MockitoBeanForBeanFactoryIntegrationTests {
|
||||
|
||||
// spring-boot/gh-7439
|
||||
|
||||
@MockitoBean
|
||||
private TestFactoryBean testFactoryBean;
|
||||
|
||||
|
||||
@@ -122,6 +122,7 @@ public class MockitoBeanForByTypeLookupIntegrationTests {
|
||||
verifyNoMoreInteractions(this.ambiguousMeta);
|
||||
}
|
||||
|
||||
|
||||
interface AnotherService {
|
||||
|
||||
String hello();
|
||||
|
||||
@@ -62,7 +62,8 @@ public class MockitoBeanOverrideProcessorTests {
|
||||
Field field = clazz.getField("a");
|
||||
Annotation annotation = field.getAnnotation(Nullable.class);
|
||||
|
||||
assertThatIllegalStateException().isThrownBy(() -> this.processor.createMetadata(annotation, clazz, field))
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> this.processor.createMetadata(annotation, clazz, field))
|
||||
.withMessage("Invalid annotation passed to MockitoBeanOverrideProcessor: expected " +
|
||||
"@MockitoBean/@MockitoSpyBean on field %s.%s", field.getDeclaringClass().getName(),
|
||||
field.getName());
|
||||
|
||||
@@ -18,12 +18,13 @@ package org.springframework.test.context.bean.override.mockito;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.test.context.bean.override.BeanOverrideContextCustomizerTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* Tests for {@link MockitoBean}.
|
||||
*
|
||||
@@ -36,8 +37,9 @@ class MockitoMockBeanTests {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBean("bean1", String.class, () -> "example1");
|
||||
context.registerBean("bean2", String.class, () -> "example2");
|
||||
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(ByTypeSingleLookup.class, context);
|
||||
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
|
||||
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(ByTypeSingleLookup.class, context);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to select a bean definition to override: found 2 bean definitions \
|
||||
of type %s (as required by annotated field '%s.example'): %s""".formatted(
|
||||
@@ -51,4 +53,5 @@ class MockitoMockBeanTests {
|
||||
String example;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,12 +18,13 @@ package org.springframework.test.context.bean.override.mockito;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.test.context.bean.override.BeanOverrideContextCustomizerTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* Tests for {@link MockitoSpyBean}.
|
||||
*
|
||||
@@ -35,8 +36,9 @@ class MockitoSpyBeanTests {
|
||||
void contextCustomizerCannotBeCreatedWithNoSuchBeanName() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBean("present", String.class, () -> "example");
|
||||
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(ByNameSingleLookup.class, context);
|
||||
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
|
||||
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(ByNameSingleLookup.class, context);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to override bean 'beanToSpy' by wrapping: \
|
||||
there is no existing bean instance with that name of type %s""".formatted(
|
||||
@@ -46,8 +48,9 @@ class MockitoSpyBeanTests {
|
||||
@Test
|
||||
void contextCustomizerCannotBeCreatedWithNoSuchBeanType() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(ByTypeSingleLookup.class, context);
|
||||
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
|
||||
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(ByTypeSingleLookup.class, context);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to select a bean to override by wrapping: found 0 bean instances of \
|
||||
type %s (as required by annotated field '%s.example')""".formatted(
|
||||
@@ -59,8 +62,9 @@ class MockitoSpyBeanTests {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBean("bean1", String.class, () -> "example1");
|
||||
context.registerBean("bean2", String.class, () -> "example2");
|
||||
BeanOverrideContextCustomizerTestUtils.configureApplicationContext(ByTypeSingleLookup.class, context);
|
||||
Assertions.assertThatIllegalStateException().isThrownBy(context::refresh)
|
||||
BeanOverrideContextCustomizerTestUtils.customizeApplicationContext(ByTypeSingleLookup.class, context);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(context::refresh)
|
||||
.withMessage("""
|
||||
Unable to select a bean to override by wrapping: found 2 bean instances \
|
||||
of type %s (as required by annotated field '%s.example'): %s""".formatted(
|
||||
|
||||
@@ -20,13 +20,14 @@ import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* Tests for {@link HttpHeadersAssert}.
|
||||
*
|
||||
@@ -42,7 +43,7 @@ class HttpHeadersAssertTests {
|
||||
@Test
|
||||
void containsHeaderWithNameNotPresent() {
|
||||
Map<String, String> map = Map.of("first", "1");
|
||||
Assertions.assertThatExceptionOfType(AssertionError.class)
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(map).containsHeader("wrong-name"))
|
||||
.withMessageContainingAll("HTTP headers", "first", "wrong-name");
|
||||
}
|
||||
@@ -56,7 +57,7 @@ class HttpHeadersAssertTests {
|
||||
@Test
|
||||
void containsHeadersWithSeveralNamesNotPresent() {
|
||||
Map<String, String> map = Map.of("first", "1", "second", "2", "third", "3");
|
||||
Assertions.assertThatExceptionOfType(AssertionError.class)
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(map).containsHeaders("first", "wrong-name", "another-wrong-name", "third"))
|
||||
.withMessageContainingAll("HTTP headers", "first", "wrong-name", "another-wrong-name");
|
||||
}
|
||||
@@ -69,7 +70,7 @@ class HttpHeadersAssertTests {
|
||||
@Test
|
||||
void doesNotContainHeaderWithNamePresent() {
|
||||
Map<String, String> map = Map.of("first", "1");
|
||||
Assertions.assertThatExceptionOfType(AssertionError.class)
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(map).doesNotContainKey("first"))
|
||||
.withMessageContainingAll("HTTP headers", "first");
|
||||
}
|
||||
@@ -83,7 +84,7 @@ class HttpHeadersAssertTests {
|
||||
@Test
|
||||
void doesNotContainHeadersWithSeveralNamesPresent() {
|
||||
Map<String, String> map = Map.of("first", "1", "second", "2", "third", "3");
|
||||
Assertions.assertThatExceptionOfType(AssertionError.class)
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(map).doesNotContainsHeaders("first", "another-wrong-name", "second"))
|
||||
.withMessageContainingAll("HTTP headers", "first", "second");
|
||||
}
|
||||
@@ -100,7 +101,7 @@ class HttpHeadersAssertTests {
|
||||
void hasValueWithStringMatchOnSecondaryValue() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.addAll("header", List.of("first", "second", "third"));
|
||||
Assertions.assertThatExceptionOfType(AssertionError.class)
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(headers).hasValue("header", "second"))
|
||||
.withMessageContainingAll("check primary value for HTTP header 'header'", "first", "second");
|
||||
}
|
||||
@@ -109,7 +110,7 @@ class HttpHeadersAssertTests {
|
||||
void hasValueWithNoStringMatch() {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.addAll("header", List.of("first", "second", "third"));
|
||||
Assertions.assertThatExceptionOfType(AssertionError.class)
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(headers).hasValue("wrong-name", "second"))
|
||||
.withMessageContainingAll("HTTP headers", "header", "wrong-name");
|
||||
}
|
||||
@@ -118,7 +119,7 @@ class HttpHeadersAssertTests {
|
||||
void hasValueWithNonPresentHeader() {
|
||||
HttpHeaders map = new HttpHeaders();
|
||||
map.add("test-header", "a");
|
||||
Assertions.assertThatExceptionOfType(AssertionError.class)
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(map).hasValue("wrong-name", "a"))
|
||||
.withMessageContainingAll("HTTP headers", "test-header", "wrong-name");
|
||||
}
|
||||
@@ -134,7 +135,7 @@ class HttpHeadersAssertTests {
|
||||
void hasValueWithLongMatchOnSecondaryValue() {
|
||||
HttpHeaders map = new HttpHeaders();
|
||||
map.addAll("header", List.of("123", "456", "789"));
|
||||
Assertions.assertThatExceptionOfType(AssertionError.class)
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(map).hasValue("header", 456))
|
||||
.withMessageContainingAll("check primary long value for HTTP header 'header'", "123", "456");
|
||||
}
|
||||
@@ -143,7 +144,7 @@ class HttpHeadersAssertTests {
|
||||
void hasValueWithNoLongMatch() {
|
||||
HttpHeaders map = new HttpHeaders();
|
||||
map.addAll("header", List.of("123", "456", "789"));
|
||||
Assertions.assertThatExceptionOfType(AssertionError.class)
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(map).hasValue("wrong-name", 456))
|
||||
.withMessageContainingAll("HTTP headers", "header", "wrong-name");
|
||||
}
|
||||
@@ -161,7 +162,7 @@ class HttpHeadersAssertTests {
|
||||
Instant instant = Instant.now();
|
||||
HttpHeaders map = new HttpHeaders();
|
||||
map.setInstant("header", instant);
|
||||
Assertions.assertThatExceptionOfType(AssertionError.class)
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(map).hasValue("wrong-name", instant.minusSeconds(30)))
|
||||
.withMessageContainingAll("HTTP headers", "header", "wrong-name");
|
||||
}
|
||||
@@ -171,7 +172,7 @@ class HttpHeadersAssertTests {
|
||||
Instant instant = Instant.now();
|
||||
HttpHeaders map = new HttpHeaders();
|
||||
map.setInstant("header", instant);
|
||||
Assertions.assertThatExceptionOfType(AssertionError.class)
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(map).hasValue("wrong-name", instant.minusSeconds(1)))
|
||||
.withMessageContainingAll("HTTP headers", "header", "wrong-name");
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.util.Map;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpSession;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Nested;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -37,7 +36,6 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*/
|
||||
public class AbstractHttpServletRequestAssertTests {
|
||||
|
||||
|
||||
@Nested
|
||||
class AttributesTests {
|
||||
|
||||
@@ -90,7 +88,6 @@ public class AbstractHttpServletRequestAssertTests {
|
||||
private HttpServletRequest createRequest(Map<String, Object> attributes) {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
HttpSession session = request.getSession();
|
||||
Assertions.assertThat(session).isNotNull();
|
||||
attributes.forEach(session::setAttribute);
|
||||
return request;
|
||||
}
|
||||
@@ -127,19 +124,18 @@ public class AbstractHttpServletRequestAssertTests {
|
||||
assertThatExceptionOfType(AssertionError.class)
|
||||
.isThrownBy(() -> assertThat(request).hasAsyncStarted(false))
|
||||
.withMessage("Async expected not to have started");
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static ResponseAssert assertThat(HttpServletRequest response) {
|
||||
return new ResponseAssert(response);
|
||||
private static RequestAssert assertThat(HttpServletRequest request) {
|
||||
return new RequestAssert(request);
|
||||
}
|
||||
|
||||
|
||||
private static final class ResponseAssert extends AbstractHttpServletRequestAssert<ResponseAssert, HttpServletRequest> {
|
||||
private static final class RequestAssert extends AbstractHttpServletRequestAssert<RequestAssert, HttpServletRequest> {
|
||||
|
||||
ResponseAssert(HttpServletRequest actual) {
|
||||
super(actual, ResponseAssert.class);
|
||||
RequestAssert(HttpServletRequest actual) {
|
||||
super(actual, RequestAssert.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.test.web.servlet.assertj;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.assertj.core.api.AssertProvider;
|
||||
import org.assertj.core.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -120,7 +119,7 @@ class HandlerResultAssertTests {
|
||||
|
||||
private static Method method(Class<?> target, String name, Class<?>... parameterTypes) {
|
||||
Method method = ReflectionUtils.findMethod(target, name, parameterTypes);
|
||||
Assertions.assertThat(method).isNotNull();
|
||||
assertThat(method).isNotNull();
|
||||
return method;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user