From: Tim M. <tim...@po...> - 2003-06-03 07:27:06
|
There is a subtle difference when testing - sometimes you want to be able to pass in an object (a mock version - where if there was no interface it should still act as equal). This implies that it is preferable to write equals as equals(obj o) { return o.equals(this); } I don't think we have this issue in the dynamic version and as nat points out the constraints are written to handle this - but the older version did have this issue sometimes... Ignore this if its confusing - its just something that I remember from years ago. Tim > -----Original Message----- > From: moc...@li... > [mailto:moc...@li...]On Behalf Of > Nat Pryce > Sent: 02 June 2003 23:09 > To: Vincent Tence; 'Mockobjects-Java-Dev' > Subject: Re: [MO-java-dev] Is IsEqual testing for equality in the right > order? > > > > According to the Java equals protocol, the expressions > arg.equals(_object) > > and _object.equals(arg) must act the same, so it makes no > difference. If > > the two expressions act differently, then that is a bug in the > > implementation of the class of arg or _object. > > I should have also said: if you want different behaviour, you can always > write a new constraint by implementing the Constraint interface. This is > exactly the situation that the Constraint interface was designed for. > > Cheers, > Nat. > > _______________________ > Dr. Nathaniel Pryce > B13media Ltd. > http://www.b13media.com > +44 (0)7712 526 661 > > > ----- Original Message ----- > From: "Nat Pryce" <nat...@b1...> > To: "Vincent Tence" <Vin...@ge...>; "'Mockobjects-Java-Dev'" > <moc...@li...> > Sent: Monday, June 02, 2003 11:07 PM > Subject: Re: [MO-java-dev] Is IsEqual testing for equality in the right > order? > > > > > > Cheers, > > Nat. > > _______________________ > > Dr. Nathaniel Pryce > > B13media Ltd. > > http://www.b13media.com > > +44 (0)7712 526 661 > > > > ----- Original Message ----- > > From: "Vincent Tence" <Vin...@ge...> > > To: "'Mockobjects-Java-Dev'" > <moc...@li...> > > Sent: Monday, June 02, 2003 10:57 PM > > Subject: [MO-java-dev] Is IsEqual testing for equality in the > right order? > > > > > > > Hi, > > > > > > I noticed that the IsEqual constraint tests for equality by comparing > the > > > expected value against the actual value. IIRC it used to be the other > way > > > around with "static" mocks - i.e. expected.equals(actual) - > so you could > > > deal with legacy code not implementing equals correctly. It has helped > me > > in > > > a number of situtations. Any reason why this has changed? > > > > > > Extract from IsEqual : > > > > > > public boolean eval( Object arg ) { > > > if(arg instanceof Object[]) { > > > arg = Arrays.asList((Object[])arg); > > > } > > > return arg.equals(_object); > > > } > > > > > > It could be _object.equals(arg) or am I missing something? > > > > > > Thanks, > > > Vincent > > > > > > > > > > > > ------------------------------------------------------- > > > This SF.net email is sponsored by: eBay > > > Get office equipment for less on eBay! > > > http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5 > > > _______________________________________________ > > > Mockobjects-java-dev mailing list > > > Moc...@li... > > > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > > > > > ------------------------------------------------------- > This SF.net email is sponsored by: eBay > Get office equipment for less on eBay! > http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5 > _______________________________________________ > Mockobjects-java-dev mailing list > Moc...@li... > https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev > > --- > Incoming mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.487 / Virus Database: 286 - Release Date: 01/06/2003 > --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.487 / Virus Database: 286 - Release Date: 01/06/2003 |