Commit Graph

2465 Commits

Author SHA1 Message Date
Sam Brannen
3002813598 Clean up warnings in spring-test 2024-04-26 15:49:09 +03:00
Stéphane Nicoll
c21090ad31 Merge branch '6.1.x' 2024-04-22 15:16:50 +02:00
Stéphane Nicoll
8a8c8fe00e Detect target of factory method with AOT
Previously, if a factory method is defined on a parent, the generated
code would blindly use the method's declaring class for both the target
of the generated code, and the signature of the method.

This commit improves the resolution by considering the factory metadata
in the BeanDefinition.

Closes gh-32609
2024-04-22 15:13:56 +02:00
Sam Brannen
8727d723f3 Polish "Bean Overriding in Tests" support 2024-04-16 17:08:15 +02:00
Sam Brannen
b13963ee81 Reject private JUnit Jupiter lifecycle methods annotated with @⁠Autowired
Closes gh-32627
2024-04-12 14:27:38 +02:00
Stéphane Nicoll
2e3a923225 Polish 2024-04-11 08:45:26 +02:00
Simon Baslé
2d33aac350 Improve Bean Overriding support, testing and documentation
This commit improves on the bean overriding feature in several ways:
the API is simplified and polished (metadata and processor contracts,
 etc...).

The commit also reworks infrastructure classes (context customizer,
test execution listener, BeanOverrideBeanFactoryPostProcessor, etc...).
Parsing of annotations is now fully stateless.

In order to avoid OverrideMetadata in bean definition and to make a
first step towards AOT support, the BeanOverrideBeanFactoryPostProcessor
now delegates to a BeanOverrideRegistrar to track classes to parse,
the metadata-related state as well as for the field injection methods
for tests.

Lastly, this commit increases the test coverage for the provided
annotations and adds integration tests and fixes a few `@TestBean`
issues.
2024-04-10 18:16:43 +02:00
Stéphane Nicoll
7a74e45946 Make use of bean definition overriding more visible
This commit makes the use of bean definition overriding more visible and
prepare for a deprecation of the feature in the next major release.

As of this commit, use of bean definition overriding logs at INFO level.
The previous log level can be restored by setting the
allowBeanDefinitionOverriding flag explicitly on the BeanFactory (or
via the related ApplicationContext).

A number of tests that are using bean overriding on purpose have been
updated to set this flag, which will make them easier to find once we
actually deprecate the feature.

Closes gh-31288
2024-04-02 14:05:12 +02:00
Sébastien Deleuze
996e66abdb Perform NullAway build-time checks in spring-test
Closes gh-32475
2024-03-26 18:14:56 +01:00
Sébastien Deleuze
96d9081190 Merge branch '6.1.x' 2024-03-26 18:10:25 +01:00
Sébastien Deleuze
88b9c0567d Refine null-safety in spring-test
See gh-32475
2024-03-26 18:09:55 +01:00
Stéphane Nicoll
bf5b22d64f Merge branch '6.1.x' 2024-03-26 17:45:25 +01:00
Stéphane Nicoll
c7c9da56da Consistent atMost period for Awaitility-based tests
Closes gh-32537
2024-03-26 17:45:14 +01:00
Sam Brannen
5698191ba0 Rename listener to CommonCachesTestExecutionListener
See gh-30954
2024-03-20 16:37:22 +01:00
Sam Brannen
7d197972e0 Polishing 2024-03-20 13:05:30 +01:00
Sam Brannen
1732844137 Polishing 2024-03-20 12:55:35 +01:00
Stéphane Nicoll
29d307e211 Clear ApplicationContext cache after a test class completes if necessary
The ApplicationContext has a resource cache that it uses while the
context is being refreshed. Once the refresh phase completes, the
cache is cleared as its content is no longer in use. If beans are
lazily initialized, there is a case where the cache might be filled
again as processing is deferred past the refresh phase.

For those cases, the cache is not cleared. This can be a problem when
running in this mode with a large set of test configurations as the TCF
caches the related contexts.

This commit includes an additional TestExecutionListener to the TCF that
clears the resource cache if necessary once a test class completes. It
is ordered so that it runs after `@DirtiesContext` support as marking
the context as dirty will remove it from the cache and make that extra
step unnecessary.

Closes gh-30954
2024-03-20 09:42:41 +01:00
Sam Brannen
3bd342ee7d Polish bean override support in the TestContext framework 2024-03-19 12:41:06 +01:00
Juergen Hoeller
e58ea0d945 Merge branch '6.1.x'
# Conflicts:
#	spring-core/src/main/java/org/springframework/core/CoroutinesUtils.java
2024-03-19 10:06:48 +01:00
Juergen Hoeller
c531a8a705 Nullability refinements and related polishing
See gh-32475
2024-03-19 09:58:44 +01:00
Sam Brannen
8f56b4a8ae Fix logic error hidden by auto-boxing 2024-03-18 18:19:34 +01:00
Sam Brannen
2ca10e20ca Simplify implementation of BeanOverrideParser
See gh-29917
2024-03-18 18:13:36 +01:00
Sam Brannen
0ef5a4090b Support non-public BeanOverrideProcessors in the TestContext framework
Closes gh-32485
2024-03-18 18:02:51 +01:00
Stéphane Nicoll
73a1c2d509 Polish 2024-03-18 08:59:22 +01:00
Juergen Hoeller
89d563097f Merge branch '6.1.x'
# Conflicts:
#	spring-core/src/main/java/org/springframework/core/convert/TypeDescriptor.java
2024-03-16 23:24:51 +01:00
Juergen Hoeller
eb8b7c4331 Remove superfluous @NonNull declarations 2024-03-16 14:22:17 +01:00
Sam Brannen
cf31d088e2 Polish AssertJ support for MockMvc
See gh-21178
2024-03-15 17:15:32 +01:00
Stéphane Nicoll
e7d7cb8641 Add AssertJ support for MockMvc
This commit adds a new way to use MockMvc by returning a MvcResult that
is AssertJ compatible. Compared to the existing MockMvc infrastructure,
this new model has the following advantages:

* Can be created from a MockMvc instance
* Dedicated builder methods for easier setup
* Assertions use familiar AssertJ syntax with discoverable assertions
through a DSL
* Improved exception message

See gh-21178

Co-authored-by: Brian Clozel <brian.clozel@broadcom.com>
2024-03-15 13:30:32 +01:00
Stéphane Nicoll
555d4a6004 Add AssertJ support for cookies
This commit adds AssertJ compatible assertions for cookies

See gh-21178

Co-authored-by: Brian Clozel <brian.clozel@broadcom.com>
2024-03-15 13:28:12 +01:00
Stéphane Nicoll
1cdbcc58f3 Add AssertJ support for the Model
This commit adds AssertJ compatible assertions for the Model that is
generated from an HTTP request.

See gh-21178
2024-03-15 13:28:12 +01:00
Stéphane Nicoll
b46e528922 Add AssertJ support for the HTTP handler
This commit adds AssertJ compatible assertions for the component that
produces the result from the request.

See gh-21178
2024-03-15 13:28:12 +01:00
Stéphane Nicoll
e97ae434fb Add AssertJ support for HTTP requests and responses
This commit adds AssertJ compatible assertions for HTTP request and
responses, including headers, media type, and response body. The latter
delegate to the recently included JSON assert support.

See gh-21178
2024-03-15 13:28:11 +01:00
Stéphane Nicoll
76f45c4289 Add support for JSON assertions using JSON path
This commit moves JSON path AssertJ support from Spring Boot.

See gh-21178

Co-authored-by: Brian Clozel <brian.clozel@broadcom.com>
2024-03-15 13:28:11 +01:00
Stéphane Nicoll
97ebc43ea9 Add support for JSON assertions using JSON compare
This commit moves JSON content AssertJ support from Spring Boot.

See gh-21178

Co-authored-by: Brian Clozel <brian.clozel@broadcom.com>
2024-03-15 13:28:11 +01:00
Sam Brannen
27d5213176 Polish Javadoc for @⁠TestBean support 2024-03-14 13:44:27 +01:00
Sam Brannen
986c4fd926 Revise use of Objects.requireNonNull()
Historically, we have rarely intentionally thrown a
NullPointerException in the Spring Framework. Instead, we prefer to
throw either an IllegalArgumentException or IllegalStateException
instead of a NullPointerException.

However, changes to the code in recent times have introduced the use of
Objects.requireNonNull(Object) which throws a NullPointerException
without an explicit error message.

The latter ends up providing less context than a NullPointerException
thrown by the JVM (since Java 14) due to actually de-referencing a
null-pointer. See https://openjdk.org/jeps/358.

In light of that, this commit revises our current use of
Objects.requireNonNull(Object) by removing it or replacing it with
Assert.notNull().

However, we still use Objects.requireNonNull(T, String) in a few places
where we are required to throw a NullPointerException in order to
comply with a third-party contract such as Reactive Streams.

Closes gh-32430
2024-03-13 16:00:22 +01:00
Sam Brannen
d6422d368a Revise @⁠TestBean support
See gh-29917
2024-03-13 16:00:22 +01:00
Sam Brannen
21ed8aad74 Add missing test 2024-03-13 15:59:28 +01:00
Sam Brannen
7211db9262 Polishing 2024-03-13 15:59:28 +01:00
Sébastien Deleuze
68ae1e5700 Fix a link in MockitoResetTestExecutionListener javadoc 2024-03-12 17:43:10 +01:00
rstoyanchev
8af1d8e842 Remove applyAttributes flag from contribution
See gh-29958
2024-03-12 10:43:31 +00:00
PhilKes
052b6357c8 Apply attributes to the underlying HTTP request
See gh-29958
2024-03-12 10:43:31 +00:00
rstoyanchev
282ee02419 Polishing contribution
Closes gh-31924
2024-03-12 10:43:31 +00:00
Anton Ždanov
667e30f580 Set UTF-8 as default multipart charset to ContentRequestMatchers
See gh-31924
2024-03-12 10:43:31 +00:00
Stéphane Nicoll
92d1ebefbb Upgrade to HtmUnit 3.11.0
This commit upgrades to a major new release of HtmlUnit. This is a
breaking change as HtmlUnit 3 moves to a `org.htmlunit` package and
calling code needs to be restructured.

Our use of Selenium has been adapted accordingly, moving to Selenium
3, using the new org.seleniumhq.selenium:htmlunit3-driver integration.

Closes gh-30392
2024-03-11 14:36:46 +01:00
Sam Brannen
71245f9655 Relocate bean override infrastructure to the proper package in the TCF 2024-03-11 14:21:04 +01:00
Sam Brannen
c4e0f96ef7 Polishing 2024-03-11 11:28:59 +01:00
Yanming Zhou
246e4977a2 Polishing Optional usage 2024-03-11 09:13:49 +01:00
Sam Brannen
6f5d3a4b12 Polish Bean Override support in the TestContext framework 2024-03-10 16:05:55 +01:00
Stéphane Nicoll
8172d7adfe Polish 2024-03-09 17:27:44 +01:00