spring-projects / spring-projects/spring-framework
When using `@MockitoBean` and `@MockitoSpyBean` make it easier to inject any underlying proxy target as well as the mock or spy
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 60.2k
- Forks
- 38.8k
- Avg merge
- 5d 2h
- Merged PRs (30d)
- 27
Description
Overview
We'd like to support something like this:
@MockitoSpyBean
ProxiedBean<Service> service;
ProxiedBean would then provide accessors for the bean both with and without all of its Spring proxies. This should make it easier to bypass any caching or advice when, for example, setting expectations, while having them in place when exercising the service.
Hopefully this will address spring-projects/spring-boot#22281 by providing a nicer API that can be used in place of AopTestUtils.getTargetObject(service).
Related Issues
- spring-projects/spring-boot#22281
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing @MockitoBean and @MockitoSpyBean support and the AopTestUtils.getTargetObject(service) usage described in the issue. Define how a ProxiedBean would expose the bean with and without Spring proxies, then add tests showing that expectations can bypass advice while service calls retain it. Done means the proposed API works for both mocks and spies and addresses the related Spring Boot issue.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100