Code Monkey home page Code Monkey logo

Comments (5)

dev-jonghoonpark avatar dev-jonghoonpark commented on May 27, 2024 1

can i try contribute?

from mockito.

TimvdLippe avatar TimvdLippe commented on May 27, 2024 1

@dev-jonghoonpark feel free to submit a pull request!

from mockito.

DidierLoiseau avatar DidierLoiseau commented on May 27, 2024 1

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.

TimvdLippe avatar TimvdLippe commented on May 27, 2024

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.

dev-jonghoonpark avatar dev-jonghoonpark commented on May 27, 2024

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

before change

After the fix, m1 and m2 were assigned as expected, as follows

after change

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.