mercredi 28 octobre 2015

gemfire cacheclosedexception the cache has not yet been created

I am trying to write unit test for a method which uses an instance of cache as below

public void method(String abc){ .... .... Cache cache = CacheFactory.getAnyInstance(); .... .... } I know mocking is the way to resolve this dependency on cache. I am new to mocking and using mockito and not sure on how to pass the mocked cache to the method.

@Mock Cache cache;

@Test public void testMethod(){

doReturn(cache).when(CacheFactory.getAnyInstance()); method("abc");

}

The above is what I've tried and got the error.

Aucun commentaire:

Enregistrer un commentaire