I have this Java program, but my test gives me this message:
testEmployeeTostring: failed testEmployeeTostring expected <[id[=
1013, name= Jubal Early, job = ]procurement]> but was: <[id[= 1013,
name= Jubal Early, job = ] procurement]>
I had to use @Override and I think that’s the problem. I hope someone can figure out the problem with this:
public class Employee {
int id;
String name;
JobType job;
public Employee(int id, String name, JobType job)
{
this.id = id;
this.name = name;
this.job = job;
}
@Override public String toString()
{
return ("["+ "id =" + id + ", name = " + name + ", job = " + job + "]");
}
}
Are you sure you have
equals()method overriden? JUnit usesequals()to compare objects. OverridinghashCode()is always a good idea as well:The code above assumes all fields are non-nullable and that
JobTypeis anenum. And BTWtoString()might have nothing to do here, as long as you are comparing objects, nottoString()of objects (bad practice).