mercredi 1 novembre 2017

Mockito. How to make sure if the method called first time and didn`t call more

  @Spy
    UniqueCharacterCounterService spy = spy(new UniqueCharacterCounterService());

@Test
public void testCache() throws IncorrectInputDataException {
    spy.countCharacters("Hello");
    verify(spy).count("Hello");
    spy.countCharacters("world");
    verify(spy).count("world");
    spy.countCharacters("Hello");
    spy.countCharacters("world");
    verify(spy, atLeastOnce()).count("Hello");
}

I have this test.And i need to be sure that method called at once(at the first situation).And at other calls just retuns cached values , so the method doesn`t call.

Aucun commentaire:

Enregistrer un commentaire