Can anyone correct my mistake.
Provided code:
public void testSetBaseSalaryNegative() {
final double altBaseSalary = -999.99;
try {
emp.setBaseSalary(altBaseSalary); // Expecting an IllegalArgumentException
fail ("Negative base-salary values should be rejected by setBaseSalary and result in an IllegalArgumentException");
} catch (IllegalArgumentException ex) {
// This is the nominal case
} catch (RuntimeException ex) {
assertThrowableTestFailure(ex);
Junit4 is showing this fail.It highlightedfail ("Negative base-salary values should be rejected by setBaseSalary and result in an IllegalArgumentException");
Here is the code i wrote:
public void setBaseSalary( double salary ) {
// TODO: implement this method
baseSalary = ( salary < 0.0 ) ? 0.0 : salary;
if (baseSalary < 0.0){
throw new IllegalArgumentException("Negative base-salary values should be rejected by setBaseSalary and result in an IllegalArgumentException");
}
}
public double getBaseSalary() {
// TODO: implement this method
return baseSalary;