In Java Objects are comared via equals() method, not toString(). I usually
use Jakarta Lang libarary to automate it. For example:

import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

public abstract class AbstractParent<T extends AbstractParent> implements
Serializable {

    private static final long serialVersionUID = 1L;

    @Override public boolean equals(Object obj) {
        return EqualsBuilder.reflectionEquals(this, obj);
    }

    @Override public int hashCode() {
        return HashCodeBuilder.reflectionHashCode(this);
    }

    @Override public String toString() {
        return ToStringBuilder.reflectionToString(this,
ToStringStyle.MULTI_LINE_STYLE);
    }
}

On Wed, Oct 21, 2009 at 11:12 AM, Charles Moulliard <cmoulli...@gmail.com>wrote:

> I have customized the toString method of each Class. What is strange
> is that in another the test generating the same objects, it works.
>
> I will adapt the test to compare object differently.
>
> Charles Moulliard
> Senior Enterprise Architect
> Apache Camel Committer
>
> *****************************
> blog : http://cmoulliard.blogspot.com
> twitter : http://twitter.com/cmoulliard
>
>
>
> On Tue, Oct 20, 2009 at 7:48 PM, Claus Ibsen <claus.ib...@gmail.com>
> wrote:
> > Hi
> >
> > If you are comparing objects it will use equals and it may not be able
> > to detect that they are identical.
> >
> > If they have a nice toString you can convert them to String and do a
> > string equals.
> >
> > At least their to string output in this mail looks as if they are
> identical.
> >
> > On Tue, Oct 20, 2009 at 4:48 PM, Charles Moulliard <cmoulli...@gmail.com>
> wrote:
> >> Unit test return the following error :
> >>
> >> java.lang.AssertionError: mock://result Body of message: 0.
> >>
> >> Expected:
> >>
> >> <[{org.apache.camel.dataformat.bindy.model.fix.simple.Header=Model :
> >> org.apache.camel.dataformat.bindy.model.fix.simple.Header, FIX 4.1,
> >> 20, 10, INVMGR, BRKR,
> >> org.apache.camel.dataformat.bindy.model.fix.simple.Order=Model :
> >> org.apache.camel.dataformat.bindy.model.fix.simple.Order, BE.CHM.001,
> >> CHM0001-01, 4, BE0001245678, 1, this is a camel - bindy test,
> >> org.apache.camel.dataformat.bindy.model.fix.simple.Trailer=Model :
> >> org.apache.camel.dataformat.bindy.model.fix.simple.Trailer, 220}]>
> >>
> >>  but was:
> >>
> >> <[{org.apache.camel.dataformat.bindy.model.fix.simple.Header=Model :
> >> org.apache.camel.dataformat.bindy.model.fix.simple.Header, FIX.4.1,
> >> 20, 10, INVMGR, BRKR,
> >> org.apache.camel.dataformat.bindy.model.fix.simple.Order=Model :
> >> org.apache.camel.dataformat.bindy.model.fix.simple.Order, BE.CHM.001,
> >> CHM0001-01, 4, BE0001245678, 1, this is a camel - bindy test,
> >> org.apache.camel.dataformat.bindy.model.fix.simple.Trailer=Model :
> >> org.apache.camel.dataformat.bindy.model.fix.simple.Trailer, 220}]>
> >>
> >> I don't understand why test fail because comparison of both is the same
> !!!
> >>
> >> Here is the method used to compare what I receive :
> >> result.expectedBodiesReceived()
> >>
> >> result = result endpoint
> >>
> >> Regards,
> >>
> >> Charles Moulliard
> >> Senior Enterprise Architect
> >> Apache Camel Committer
> >>
> >> *****************************
> >> blog : http://cmoulliard.blogspot.com
> >> twitter : http://twitter.com/cmoulliard
> >>
> >
> >
> >
> > --
> > Claus Ibsen
> > Apache Camel Committer
> >
> > Open Source Integration: http://fusesource.com
> > Blog: http://davsclaus.blogspot.com/
> > Twitter: http://twitter.com/davsclaus
> >
>

Reply via email to