I have an abstract class, say AbstractClass
where I've got a public void method myMethod
without an implementation. While I'm testing this class, I've created an anonymous subclass, where I can implement myMethod
as I see fit.
In AbstractClass
There's another method, say myImplementedMethod
which calls myMethod
. Is there a trick to what I can put in myMethod
in the anonymous subclass, so as to be able to verify that it has been called?
Edit: I'm using Mockito for mocking, and it is not my place to use another framework.
public abstract class AbstractClass {
public abstract void myMethod();
public void myImplementedMethod() {
myMethod();
}
public class AbstractClassTest {
@Before
public void setUp() {
AbstractClass myClass = new AbstractClass() {
@Override
public void myMethod(){
//What could I put here?
}
}
}
@Test
public void testMyImplementedMethod() {
myClass.myImplementedMethod();
//check that myMethod is called.
}
}