keeganwitt / gmock

Automatically exported from code.google.com/p/gmock
6 stars 2 forks source link

Default behaviors for hashCode() and equals() on the Java side in record stage #79

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I was facing a problem when I was working on the collaborator sample. When
I called "classUnderTest.addListener(mock)" in the setup() method, it threw
an ClassCastException. I looked into the code of ClassUnderTest, and found:

    public void addListener(Collaborator listener) {
        listeners.add(listener);
    }

here listeners is a HashMap, and mock.hashCode() returned a MethodRecorder
instead of an integer, so it failed.

I think we should do the same thing for hashCode() and equals() as
toString() in JavaMethodInterceptor.

Original issue reported on code.google.com by JohnnyJianHY on 31 Mar 2009 at 7:01

GoogleCodeExporter commented 9 years ago
So we would stop mocking hashcode on the java side?

What if you had move the addListener call in the play closure?

Original comment by julien.g...@gmail.com on 9 Apr 2009 at 7:36

GoogleCodeExporter commented 9 years ago
No, we will not stop mocking hashCode on the java side.

Actually, we stop recording expectations of hashCode on the java side (actually 
we
always recording expectations on the groovy side), but we can still mocking 
hashCode
on the java side in the play closure.

Original comment by JohnnyJianHY on 9 Apr 2009 at 7:49

GoogleCodeExporter commented 9 years ago

Original comment by JohnnyJianHY on 9 Apr 2009 at 12:49