-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
@InjectMock replaces existing mocks #15411
Comments
Hm, what's the CDI scope of the |
@famod You're right, except that there might be various CDI constructs that can change the game ;-), e.g. qualifers, |
Sorry, I didn't bother to setup a repo, as I didn't know if it is a problem at all. I will get on it and update the issue. @mkouba The scope is @ApplicationScoped. |
I have added a minimal sample. Notice if you switch the order of fields in test
instead of
there is different mock which does not get called. |
@mkouba @famod The problem probably lies with MockitoMocksTracker, as it is beanInstance to mock map. Basically what happens is that the second mock that is read gets mapped to the same bean instance. Instead of a bean instance, would it be more appropriate to map the type of field + bean instance to the mock? (I have too little experience with quarkus to actually know if there would be a problem with that approach) |
I'll take a look sometime this week. Thanks for the reproducer and the details |
#15427 fixes the issue |
Use single mock when backing bean is the same instance
Fixes: quarkusio#15411 (cherry picked from commit 1c266be)
Describe the bug
Basically what I have is class C1, which implements 2 interfaces I1 and I2. Class C2 then injects those 2 interfaces. The actual (non-test) code runs well, but in testing one of the mocks is not called.
It will probably be the simplest to understand with some pseudo code, as I have a hard time explaining the problem with words.
From what I understand what happens is that the mocks replace the actual implementation, but that does not seem correct to me, because the implementation is not what I really want to mock or worry about.
Now... Does this qualify as a bug, or is it a "feature"? Is there some workaround except just creating interfaces that are the "same" as implementations (one interface per class)?
Expected behavior
Both mock get called.
Actual behavior
One mock gets called.
** To reproduce **
git clone https://github.com/blazmrak/inject-mock-issue.git
mvn clean test
Environment (please complete the following information):
uname -a
orver
: 10.0.19042.804java -version
: 11.0.10mvnw --version
orgradlew --version
): 3.6.3The text was updated successfully, but these errors were encountered: