-
Notifications
You must be signed in to change notification settings - Fork 40.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SpyDefinition.SpringAopBypassingVerificationStartedListener seems to handle the event parameter incorrectly. #23708
Comments
@RobertZenz, unfortunately it's hard to say as I'm not sure that I have understood exactly what you're trying to do. Could you please provide a complete yet minimal sample that reproduces the problem? You could share it with us by zipping it up and attaching it to this issue or pushing it to a separate repository on GitHub. |
It's exactly as simple as I wrote to reproduce: @SpringBootTest
public class Testcase {
@SpyBean
private MyCrudRepository myCrudRepistory;
@Test
public void test() {
Mockito.verify(myCrudRepistory, Mockito.times(1)).save(Mockito.any());
}
} public interface MyCrudRepository extends CrudRepository<MyModelClass, BigDecimal> {
} |
Thanks, but that isn't sufficient for us to be certain that we're looking at the same problem as you are seeing. For example, you haven't told us which version of Spring Boot you're using or of any other dependencies. If you would like us to spend some more time investigating, please spend some time providing a complete yet minimal sample that reproduces the problem. As I said above, you can share it with us by zipping it up and attaching it to this issue or pushing it to a separate repository on GitHub. |
Given that I've pointed you at the exact line that is the problem in HEAD, I'd say "the latest". But I'll throw something together... |
This is a simple example project which shows this exception. |
Thanks for the sample. It's revealed that you're using Mockito's inline mock maker, making this a duplicate of #22416. |
@wilkinsona I just ran into the same issue with spring 2.4. It seems that this issue was not a duplicate of #22416 but still exists. It seems that it's not possible to use a spring-data repository as a Will you reopen this issue or shall I create a new one? |
Interesting, thanks. I'll reopen it and we can take another look. There may also be some overlap with #7033. Unfortunately, |
Thanks for getting into this issue again. BTW: We're using spring-data-mongo and see exactly the same issue. |
Another thing: In our case it worked with Spring Boot 2.3 and mockito 3.2.0 with:
With Spring 2.4 it then fails with the following error:
|
I have a possible fix for #7033 which appears to fix https://github.com/ractive/spring-boot-gh-23708. The spy is successfully created (with or without
However, this is to be expected as nothing is interacting with the repository. The test passes with a modification to the app such that As a result of the above, I'm going to close this one as a duplicate of #7033 |
I'm seeing the following exception when using
@SpyBean
for aCrudRepository
in my Integration-Tests:What I'm trying to do is instrument the repository to fail at a certain call to test the error handling behavior. So the definition of the field in question is as simple as it gets:
I can use the Spy correctly for everything, with the exception of verifying whether the function was actually called, which gives me the above exception. I'm using
verify
like this:As far as I can see, that is because in SpyDefinition.SpringAopBypassingVerificationStartedListener:114 the actual object is being presented to the
VerificationStartedEvent
, which actually expects a mock.Or is that an unsupported use-case or am I spying on the repository in a wrong way?
The text was updated successfully, but these errors were encountered: