Github user metatype commented on the issue:
https://github.com/apache/geode-examples/pull/4
Here's a possible unit test. It mocks the Geode API (lol), invokes the
Example, and checks `System.out` .
```java
package org.apache.geode.examples.replicated;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.isA;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.powermock.api.mockito.PowerMockito.whenNew;
import java.util.Collections;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.ClientCache;
import org.apache.geode.cache.client.ClientCacheFactory;
import org.apache.geode.cache.client.ClientRegionFactory;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemOutRule;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest({ Example.class })
public class ExampleTest {
@Rule
public SystemOutRule systemOutRule = new SystemOutRule().enableLog();
@Test
@SuppressWarnings("unchecked")
public void testExample() throws Exception {
ClientCacheFactory cacheFactory = mock(ClientCacheFactory.class);
whenNew(ClientCacheFactory.class).withNoArguments()
.thenReturn(cacheFactory);
when(cacheFactory.addPoolLocator(any(),
anyInt())).thenReturn(cacheFactory);
when(cacheFactory.set(any(), any())).thenReturn(cacheFactory);
ClientCache cache = mock(ClientCache.class);
when(cacheFactory.create()).thenReturn(cache);
ClientRegionFactory<Integer, String> regionFactory = mock(
ClientRegionFactory.class);
when(cache.<Integer, String> createClientRegionFactory(
isA(ClientRegionShortcut.class))).thenReturn(regionFactory);
Region<Integer, String> region = mock(Region.class);
when(regionFactory.create(any())).thenReturn(region);
when(region.getName()).thenReturn("example-region");
when(region.put(any(), any())).thenReturn(null);
when(region.get(any())).thenReturn("value");
when(region.keySetOnServer()).thenReturn(Collections.EMPTY_SET);
Example.main(null);
assertThat(systemOutRule.getLog())
.contains("Inserted 10 entries into region");
}
}
```
Thoughts?
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---