GigaSpaceProxy implements InvocationHandler { public static GigaSpace create(GigaSpace gigaSpace) { return ReflectionUtil.newProxy(GigaSpace.class, new GigaSpaceProxy(gigaSpace)); } GigaSpaceProxy(GigaSpace gigaSpace); static GigaSpace create(GigaSpace gigaSpace); @Override Object invoke(Object proxy, final Method method, final Object[] args);  }
@Test public void proxiesInvocations() throws Exception { GigaSpace gigaSpace = Mockito.mock(GigaSpace.class); GigaSpace proxied = GigaSpaceProxy.create(gigaSpace); Mockito.stub(gigaSpace.count(null)).toReturn(21); assertEquals(21, proxied.count(null)); }
@Test public void wrappsSpaceCacheExceptionsInServiceUnavailableException() throws Exception { GigaSpace gigaSpace = Mockito.mock(GigaSpace.class); Mockito.stub(gigaSpace.count(null)).toThrow(new SpaceCacheException("")); GigaSpace proxied = GigaSpaceProxy.create(gigaSpace); try { proxied.count(null); fail("Expected ServiceUnavailableException or subclass to be thrown"); } catch (ServiceUnavailableException e) { } }