I am making a list of exercises and I am in doubt about the following:
Exercise 3 - The verify method, from the org.mockito.Mockito.verify package, is used to check the amount of times a method is invoked. Add in the ATest class a test to check if invoking method area (2) the pi () method is invoked exactly once.
The class to be tested is as follows:
package aula;
public abstract class A {
public long fatorial(long n) {
if (n <= 1) {
return 1;
}
return n * fatorial(n - 1);
}
public abstract Object calc(Object x, Object y) throws
NullPointerException, Exception;
public void msg(String txt) {
}
public double area(double r) {
return 2 * pi() * r;
}
public double pi() {
return Math.PI;
}
public double pow() {
return pi() * pi();
}
public abstract int inc();
}
The test I created using JUnit 4 to solve exercise three is as follows:
@Test
public void test7() throws Exception {
when(a.area(2)).thenReturn(2.0);
//when(a.area(2.0)).thenCallRealMethod();
verify(a, times(0)).pi();
//assertSame(2.0, a.area(2));
verify(a, times(1)).pi();
}
As we can see, I'm very confused with this question, I researched many things and could not heal my doubt. When I try to run this test, the result is blue not green as expected. The following error appears:
Wanted but not invoked: Actually, there were zero interactions with this mock.
If someone can help me, explaining with the class that I put up there, I thank you! I really can not do it):