Comments (5)
can i try contribute?
from mockito.
@dev-jonghoonpark feel free to submit a pull request!
from mockito.
I think it's correct that I'm getting an UnnecessaryStubbingException because I didn't enter the expected input. (Passed "hello", not any(MyPojo.class))
However, something feels like the result is not clear.
I think this is normal, I didn’t write the MRE such that the mock would actually be used, but you could simply add a second call with a parameter that matches the mock, e.g.
myService.doSomething(new MyPojo());
from mockito.
Yes this appears to be a legitimate bug, good catch! Feel free to submit a pull request with a fix and a regression test for it!
from mockito.
hello. @TimvdLippe
I found a problem and fixed the code.
I think the problem was that we used stack inside ArgumentMatcherStorageImpl.java, so the order was reversed during the push/pop process.
so I changed code like this (I modified it to assign the result of the popMatcher to m2 first)
public void reportAnd() {
assertStateFor("And(?)", TWO_SUB_MATCHERS);
ArgumentMatcher<?> m2 = popMatcher();
ArgumentMatcher<?> m1 = popMatcher();
reportMatcher(new And(m1, m2));
}
@Override
public void reportOr() {
assertStateFor("Or(?)", TWO_SUB_MATCHERS);
ArgumentMatcher<?> m2 = popMatcher();
ArgumentMatcher<?> m1 = popMatcher();
reportMatcher(new Or(m1, m2));
}
Before the fix, m1 and m2 were reversed, as follows
After the fix, m1 and m2 were assigned as expected, as follows
I was happy to think I had fixed the bug.
But sadly, the error changed to the following
(I used the example code provided by the author)
org.mockito.exceptions.misusing.UnnecessaryStubbingException:
Unnecessary stubbings detected.
Clean & maintainable test code requires zero unnecessary code.
Following stubbings are unnecessary (click to navigate to relevant line of code):
1. -> at com.example.demo.MockitoTest.test(MockitoTest.java:22)
Please remove unnecessary stubbings or use 'lenient' strictness. More info: javadoc for UnnecessaryStubbingException class.
at org.mockito.junit.jupiter.MockitoExtension.afterEach(MockitoExtension.java:192)
...
I think it's correct that I'm getting an UnnecessaryStubbingException because I didn't enter the expected input. (Passed "hello", not any(MyPojo.class))
However, something feels like the result is not clear.
What are your thoughts?
I'm wondering if this is a good fix.
If this is the right fix, I'll raise a PR with the addition of test code for this.
(Note that the ./gradlew check
passed without fail.)
Have a nice day
from mockito.
Related Issues (20)
- application HOT 1
- In TypeBasedCandidateFilter.isCompatibleTypes -> ClassCastException: class TypeVariableImpl cannot be cast to class Class HOT 9
- Spy does not see method called in feedback call HOT 3
- Mockito.mock(...) does not work inside an Arquillian integration test anymore HOT 1
- Feature Request: MockedConstruction needs a setInitializer method
- ArgumentMatcher like assertArg() for multiple different calls? HOT 3
- Mockito does not work on Java 21 HOT 3
- Mockito.mock() not mocking the Class in Java 17 HOT 1
- ArgumentMatcher for one property
- Tests failures after adding mockito-inline on Java 21
- springjpa+junit5+mockito+querydsl
- ungraceful failure from instrumented code
- Failing while building mockito-inline version 4.6.1 using ./gradlew build (org.mockito:mockito-inline:4.6.1) HOT 1
- Mockito does not work with OTEL extension api in classpath
- verify can't differ/handle logging methods with "Object... arguments" in signature
- Not possible to mock Thread.sleep
- WIthMockito feature request
- potential editorconfig enhancement HOT 2
- Mockito 5.12.0 and Java 22 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mockito.