Commit Graph

2628 Commits

Author SHA1 Message Date
Sam Brannen
40ca83dfd4 Revise Bean Override internals and Javadoc 2024-09-28 17:13:24 +02:00
Sam Brannen
bed3025274 Restructure BeanOverrideBeanFactoryPostProcessor and improve documentation 2024-09-27 17:08:08 +02:00
Sam Brannen
ea8b8ae910 Polishing 2024-09-27 17:03:49 +02:00
Sam Brannen
9c746905bc Test status quo for Bean Override singleton semantics
The tests introduced in this commit reveal the following issues in our
Bean Override support.

- If a FactoryBean signals it does not manage a singleton, the Bean
  Override support silently replaces it with a singleton.

- An attempt to override a prototype-scoped bean or a bean configured
  with a custom scope results in one of the following.

  - If the bean type of the original bean definition is a concrete
    class, an attempt will be made to invoke the default constructor
    which will either succeed with undesirable results or fail with an
    exception if the bean type does not have a default constructor.

  - If the bean type of the original bean definition is an interface or
    a FactoryBean that claims to create a bean of a certain interface
    type, an attempt will be made to instantiate the interface which
    will always fail with a BeanCreationException.
2024-09-27 15:42:12 +02:00
Sam Brannen
c3ff6cf319 Reverse engineer documentation for Bean Override internals 2024-09-27 15:39:35 +02:00
Sam Brannen
ded5c13e19 Reinstate BeanOverrideTestSuite 2024-09-27 13:48:56 +02:00
Yanming Zhou
8941e2876e Replace 'e.g.' with 'for example' in documentation and comments
Closes gh-33515
2024-09-26 14:11:17 +02:00
Sam Brannen
e55fe9077f Make DynamicPropertyRegistrarBeanInitializer public
In order to allow third parties (for example, Spring Boot) to ensure
that a DynamicPropertyRegistrarBeanInitializer has been registered in
an ApplicationContext which has not been customized by the
DynamicPropertiesContextCustomizer, this commit converts
DynamicPropertyRegistrarBeanInitializer to a public API for use in such
special use cases.

Closes gh-33593
2024-09-26 13:01:57 +02:00
Sam Brannen
b943bdeec2 Polishing 2024-09-25 17:28:47 +02:00
Sam Brannen
aef5143642 Merge branch '6.1.x' 2024-09-24 16:50:12 +02:00
Sam Brannen
5cc4d0a2ca Do not invoke AotTestExecutionListener for @⁠DisabledInAotMode tests
Closes gh-33589
2024-09-24 16:47:48 +02:00
Sam Brannen
6a9b5d21f4 Document that TestContextAnnotationUtils is required for @⁠Nested support
Closes gh-33586
2024-09-24 11:55:44 +02:00
Sam Brannen
59eaed0b28 Ensure integration tests are suitable for AOT processing 2024-09-23 16:45:56 +02:00
Sam Brannen
7d99790c34 Polishing 2024-09-23 16:45:56 +02:00
Sam Brannen
8931b75b95 Polishing 2024-09-20 10:58:37 +02:00
Johnny Lim
3ba9d35e22 Polish
Closes gh-33566
2024-09-20 10:58:37 +02:00
Sam Brannen
e587753b1d Introduce @⁠EasyMockBean bean override example
This commit introduces example support for a custom @⁠EasyMockBean
annotation that allows tests to use EasyMock as the mocking framework
for bean overrides in a test's ApplicationContext.

The point of this exercise is to ensure that it is possible for third
parties to introduce bean override support for mocking frameworks other
than Mockito, and that they can do so with the APIs currently in place.

Closes gh-33562
2024-09-18 17:10:06 +02:00
Sam Brannen
6c2cba5d8a Polish bean override internals 2024-09-18 14:22:15 +02:00
Sam Brannen
13e175ab46 Avoid use of static import in production code 2024-09-16 15:50:05 +02:00
Sam Brannen
b60bb44256 Polish test @⁠Configuration classes 2024-09-16 15:45:32 +02:00
Sam Brannen
31a6e98eaf Introduce @⁠Disabled AOT tests for @⁠TestBean support
See gh-32933
2024-09-16 15:43:54 +02:00
Sam Brannen
d097eea3a8 Polish DynamicPropertyRegistrar documentation 2024-09-12 13:20:59 +02:00
Sam Brannen
e7b52cf8b2 Introduce DynamicPropertyRegistrar to replace DynamicPropertyRegistry bean
Spring Boot's testing support registers a DynamicPropertyRegistry as a
bean in the ApplicationContext, which conflicts with the
DynamicPropertyRegistry registered as a bean by the Spring TestContext
Framework (TCF) since Spring Framework 6.2 M2.

To avoid that conflict and to improve the user experience for Spring's
testing support, this commit introduces a DynamicPropertyRegistrar API
to replace the DynamicPropertyRegistry bean support.

Specifically, the TCF no longer registers a DynamicPropertyRegistry as
a bean in the ApplicationContext.

Instead, users can now register custom implementations of
DynamicPropertyRegistrar as beans in the ApplicationContext, and the
DynamicPropertiesContextCustomizer now registers a
DynamicPropertyRegistrarBeanInitializer which eagerly initializes
DynamicPropertyRegistrar beans and invokes their accept() methods with
an appropriate DynamicPropertyRegistry.

In addition, a singleton DynamicValuesPropertySource is created and
registered with the Environment for use in
DynamicPropertiesContextCustomizer and
DynamicPropertyRegistrarBeanInitializer, which allows
@⁠DynamicPropertySource methods and DynamicPropertyRegistrar beans to
transparently populate the same DynamicValuesPropertySource.

Closes gh-33501
2024-09-11 17:42:04 +02:00
Stéphane Nicoll
e311d9848a Expose the uriTemplate used to build a MockHttpServletRequest
This commit exposes the unexpanded URI template used to build a
MockHttpServletRequest. This allows MockMvc users to retrieve that
information, in consistency with ExchangeResult in WebTestClient.

Closes gh-33509
2024-09-09 14:46:05 +02:00
Brian Clozel
52c4ffa4d2 Merge branch '6.1.x' 2024-08-30 21:23:29 +02:00
Brian Clozel
fab889009a Support multiple async starts in MockHttpServletRequest
Closes gh-33457
2024-08-30 20:08:36 +02:00
rstoyanchev
7aa25e083a Merge branch '6.1.x' 2024-08-28 18:59:47 +03:00
rstoyanchev
186deb777f Update deprecation notices on rawStatusCode
Mark for removal where not marked, and set to 7.0
consistently as the target for removal.

See gh-33440
2024-08-28 18:49:49 +03:00
rstoyanchev
57cb8c7abf Restore rawStatusCode methods
Revert methods removed in 7df2e2a8d2.

See gh-33440
2024-08-28 18:12:26 +03:00
Sam Brannen
5bcfcdd0be Polishing 2024-08-28 14:46:12 +02:00
Sam Brannen
38a56b3fda Unwrap CGLIB proxy when invoking non-proxied methods in ReflectionTestUtils
Prior to this commit, when ReflectionTestUtils was used to invoke a
method on a CGLIB proxy, the invocation was always performed directly
on the proxy. Consequently, if the method was not proxied/intercepted
by the CGLIB proxy -- for example, if the method was final or
effectively private -- the invoked method could not operate on the
state of the target object or interact with other private methods in
the target object.

With this commit, if the supplied target object is a CGLIB proxy which
does not intercept the method, the proxy will be unwrapped allowing the
method to be invoked directly on the ultimate target of the proxy.

Closes gh-33429
2024-08-28 14:31:24 +02:00
Sam Brannen
4a099d213e Add missing @⁠TestMethodOrder declarations 2024-08-19 14:46:21 +02:00
Simon Baslé
107ae6159b Add tests for MockitoBean reset of mocks/spies from a FactoryBean
Closes gh-33405
2024-08-19 11:10:19 +02:00
Sébastien Deleuze
94d8fc7af8 Merge branch '6.1.x' 2024-08-19 10:46:54 +02:00
Sébastien Deleuze
0101945708 Prevent a leak in WebTestClient
This commit applies the same kind of processing for
Void.class element type in the ParameterizedTypeReference
variant of WebTestClient.ResponseSpec#returnResult than
in the Class variant.

Closes gh-33389
2024-08-19 10:46:47 +02:00
Sam Brannen
59c779d8fe Enforce order of Javadoc tags for records introduced in 6.2
See gh-33403
2024-08-18 13:12:47 +02:00
Sam Brannen
d749d2949d Use new features from JUnit Jupiter 5.11
This commit primarily migrates to the new argumentSet() feature but also
applies additional polishing to our use of parameterized tests.

See gh-33395
2024-08-16 13:48:19 +02:00
Sam Brannen
f6110dda06 Polishing 2024-08-08 17:48:57 +03:00
Simon Baslé
70e5af7d16 Polishing: remove unnecessary code 2024-08-07 16:57:52 +02:00
Simon Baslé
52bc3cf5aa Polishing 2024-08-07 16:43:09 +02:00
Stéphane Nicoll
313b063aef Polish 2024-08-07 15:28:52 +02:00
Simon Baslé
7052af97a6 Polish test to focus on the FactoryBean results being mocked 2024-08-07 14:57:15 +02:00
Simon Baslé
1c893e6354 Add @MockitoBeanSettings, use MockitoSession with strict stubs default
This commit changes the way the `MockitoTestExecutionListener` sets up
mockito, now using the `MockitoSession` feature. Additionally, stubbing
now defaults to a STRICT mode which can be overruled with a newly
introduced annotation: `@MockitoBeanSettings`.

Closes gh-33318
2024-08-07 14:57:15 +02:00
Sanghyuk Jung
ca377e4854 Remove duplicated "the" in Javadoc
See gh-33308
2024-08-03 09:52:23 +02:00
rstoyanchev
31a3119784 Add FilterRegistration's defensively
Follow-up to d2225c, which broke Boot tests because the ServletContext can
be the one of the embedded Servlet container if initializing a live server
and as well as MockMvc (e.g. via `@AutoConfigureMockMvc`).

See gh-33252
2024-07-31 14:50:08 +03:00
rstoyanchev
5ac7e74bf2 Replace test FilterRegistration with the one in testFixtures
See gh-33252
2024-07-30 11:33:47 +03:00
rstoyanchev
d2225c2140 MockMvc supports FilterRegistration filter init
Closes gh-33252
2024-07-30 11:33:47 +03:00
Stéphane Nicoll
70f3b0eb91 Only register DynamicPropertySourceBeanInitializer if necessary
This commit makes sure to check first if
DynamicPropertySourceBeanInitializer has been registered before trying
to register it.

When running with AOT optimizations, the bean definition has been
contributed so there is no need to register it again when the context
customizer runs.

Closes gh-33272
2024-07-29 09:30:27 +02:00
Stéphane Nicoll
89453905cb Copy tests for multipart request builder
See gh-33229
2024-07-18 12:11:59 +02:00
Stéphane Nicoll
6590ab6bf9 Consistently set content type of the request with multipart
Closes gh-33232
2024-07-18 12:01:47 +02:00