I'm using JUnit 5, and copied the code from "Software Testing" book in order to create a mock object for testing. part of the tester code is:
@Test
public void rangesOKTestWithoutDependency() {
// This is an anonymous class
SimpleDate simpleDate = new SimpleDate(1, 1, 2000) {
@Override
public boolean isLeap(int year) {
if(2000 == year) return true;
else if(2001 == year) return false;
else throw new IllegalArgumentException("No Mock for year " + year);
}
};
assertTrue(simpleDate.rangesOK(2, 29, 2000)); // Valid due to leap year
assertFalse(simpleDate.rangesOK(2, 29, 2001)); // Valid due to leap year
}
I have a compiler error, which says "Method isLeap(int) must override or implement a supertype method". This error is reported in the line that I override isLeap() method. (The line below @override)
Well, amazingly this is what I have done. So I don't know what is this complain about. Here is the isLeap() method in class simpleDate:
private boolean isLeap(int year) {
boolean isLeapYear = true;
if(year % 4 != 0)
isLeapYear = false;
else if(year % 100 != 0)
isLeapYear = true;
else if(year % 400 != 0)
isLeapYear = false;
return isLeapYear;
}
As you see the method in the tester is an overridden version of the original method but still I get an error. Any thoughts?
ps: I'm using eclipse.
public boolean isLeapvsprivate boolean isLeapprivatemethod, it has to beprotectedorpublic