lundi 14 novembre 2016

Re-implementation of method which returns primitive type

I need to re-implement an method of a mock, which returns a primitive value.

The standard andAnswer approach is not a solution, because it uses an generics object and primitive type is not allowed. The template from user guide:

  expect(l.remove(10)).andAnswer(new IAnswer<String>() {
    public String answer() throws Throwable {
      return getCurrentArguments()[0].toString();
    }
  });

I need to use andAnswer approach, not andDelegateTo, because:

  • I mock a class, not an interface
  • when andDelegateTo is used, I have to create anonymous class of mocked type, which will calls some of its constructors, which is not an option for my case.

Aucun commentaire:

Enregistrer un commentaire