Code Monkey home page Code Monkey logo

Comments (5)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
Thanks for detailed report, I'll take a look at it.

Original comment by [email protected] on 13 Mar 2008 at 10:33

from mockito.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024

Original comment by [email protected] on 16 Mar 2008 at 2:50

from mockito.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
Again, thank you very much for very detailed report and for suggesting the fix.

InvocationMatcher.isSimilarTo() method have no effect on verification. This 
method is
only used to decide what kind of verification message to print. E.g. at the 
point
when isSimilarTo() is called the verification has already failed.

I created a test case according to your description and everything works fine 
(can
you paste it to your IDE and tell me if this is it?):

{{{
    interface View {
        void addProperty(String property);
        void addProperty(DomainObject property);
    }

    class DomainObject {}

    class CustomDomainMatcher extends ArgumentMatcher<DomainObject> {
        @Override public boolean matches(Object argument) {
            return true;
        }
    }

    @Test
    public void testBug() throws Exception {
        View view = mock(View.class);

        view.addProperty(new DomainObject());
        view.addProperty("test");

        verify(view, atLeastOnce()).addProperty(argThat(new CustomDomainMatcher()));
        verify(view, times(1)).addProperty(argThat(new CustomDomainMatcher()));

        verify(view, atLeastOnce()).addProperty("test");
        verify(view, times(1)).addProperty("test");
    }
}}}

Misbehaviour in your code may be related to following:

Look at this line:

verify(view, atLeastOnce()).addProperty( argThat(new CustomDomainMatcher()) ); 

Given that addProperty() method is overloaded in your code, it is very 
important what
kind of generic type your customDomainMatcher is defined with:

class CustomDomainMatcher extends ArgumentMatcher<DomainObject> {

or 

class CustomDomainMatcher extends ArgumentMatcher<String> {

Compiler uses this generic type to determine which overloaded version of the 
method
to use.

If your matcher is not generic, you have to cast the argument to make compiler 
happy:
verify(view, atLeastOnce()).addProperty((DomainObject) argThat(new
customDomainMatcher()) ); 

Closing the bug - please reopen if it still doesn't work for you.

Original comment by [email protected] on 16 Mar 2008 at 3:09

  • Changed state: Invalid

from mockito.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024
It will be a few days, but I will give that a try in my environment. 
K

Original comment by [email protected] on 24 Mar 2008 at 9:02

from mockito.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 27, 2024

Original comment by [email protected] on 19 Apr 2009 at 7:40

  • Added labels: Milestone-Pre1.7

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.