mercredi 23 décembre 2015

Mocked instance fires events

I have a class which I want to unit test and it has a dependency Foo, which I want to mock. This class Foo sometimes fires events when a certain method is called. But don't know how to mock the class Foo to get this behaviour.

So, how could I mock the class Foo, that it act like the following code? I used so far Mockito but open for new frameworks if mockito don't offer the needed functionalities.

//This is how the class Foo should act when it is mocked
public class Foo()
{
    private Listener listener;
    public void addListener(Listener listener)
    {
        this.listener = listener;
    }

    public void callMethodWhichMayFireAnEvent()
    {
        listener.event();
    }
}

Aucun commentaire:

Enregistrer un commentaire