0

I am using below mentioned code to get the cache but it will work at server environment need to write Junit test case for the same , could some one please help me out.

I am using EasyMock for mocking.

public Object get(final Object key, final String jndiName) throws CacheException{
            DistributedMap cacheMap = null;
            try {
                  final InitialContext ic = new InitialContext();
                  cacheMap = (DistributedMap) ic.lookup(jndiName);
                  return cacheMap.get(key);
            } catch (final Exception ex) {
                  throw new Exception(ex)
            }
      }
4

1 回答 1

0

这个问题回答了您的问题:how-to-write-a-junit-testcase-for-a-void-method-that-c​​reates-a-new-object

在创建新实例的方法中使用模拟是具有挑战性的。使用建议的解决方案之一来解决这个问题:Powermock、Factory、Override

于 2013-08-09T10:41:42.510 回答