I prepared short Java class. Could anyone show me how write voids: testEquals, testHashCode, testToString for this code in junit? I have a little problem with it;)
public class JW {
private String name;
private int quantityVoters;
private int voted;
public JW( String nam, int quantityV ) {
if( nam == null || nam.length() == 0 || quantityV < 10 )
throw new IllegalArgumentException( "JW: Wrong" );
name= nam;
quantityVoters= quantityV;
voted= 0;
}
public void voting( int n ) {
if( n < 0 || n > quantityVoters - voted )
throw new IllegalArgumentException( "JW: soething wrong with voting!" );
else
voted += n;
}
public int novote() {
return quantityVoters - voted;
}
public boolean equals( Object o ) {
return o != null && o instanceof JW && ((JW)o).name.equals( name );
}
public int hashCode() {
return name.hashCode();
}
public String toString() {
return "JW " + name + ": quantity Voters: " + quantityVoters + ", voted: " + voted;
}
}
See Question&Answers more detail:os