This is an automated email from the ASF dual-hosted git repository.
upthewaterspout pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-examples.git
The following commit(s) were added to refs/heads/develop by this push:
new bea5215 GEODE-3893: Replace mocks utility class for all examples with
per-example mocks (#31)
bea5215 is described below
commit bea52153a127b4654032169f4f3093b2756269d7
Author: Michael "Sarge" Dodge <[email protected]>
AuthorDate: Mon Oct 23 14:15:17 2017 -0700
GEODE-3893: Replace mocks utility class for all examples with per-example
mocks (#31)
---
.../async/ExampleAsyncEventListenerTest.java | 57 ++++++++++++++-
.../apache/geode/examples/async/ExampleTest.java | 6 +-
.../geode/examples/functions/ExampleTest.java | 11 ++-
.../geode/examples/listener/ExampleTest.java | 2 -
.../apache/geode/examples/loader/ExampleTest.java | 3 +-
src/test/java/org/geode/examples/util/Mocks.java | 80 ----------------------
.../org/geode/examples/util/TestAsyncEvent.java | 73 --------------------
.../apache/geode/examples/writer/ExampleTest.java | 4 +-
8 files changed, 70 insertions(+), 166 deletions(-)
diff --git
a/async/src/test/java/org/apache/geode/examples/async/ExampleAsyncEventListenerTest.java
b/async/src/test/java/org/apache/geode/examples/async/ExampleAsyncEventListenerTest.java
index 49b12ea..2a2ca15 100644
---
a/async/src/test/java/org/apache/geode/examples/async/ExampleAsyncEventListenerTest.java
+++
b/async/src/test/java/org/apache/geode/examples/async/ExampleAsyncEventListenerTest.java
@@ -19,11 +19,12 @@ import static org.junit.Assert.assertEquals;
import java.util.LinkedList;
import java.util.List;
-import org.geode.examples.util.TestAsyncEvent;
import org.junit.Test;
import org.apache.geode.cache.Operation;
+import org.apache.geode.cache.Region;
import org.apache.geode.cache.asyncqueue.AsyncEvent;
+import org.apache.geode.cache.wan.EventSequenceID;
public class ExampleAsyncEventListenerTest {
@Test
@@ -44,4 +45,58 @@ public class ExampleAsyncEventListenerTest {
assertEquals("will", listener.spellCheck("wil"));
assertEquals("I", listener.spellCheck("i"));
}
+
+ public class TestAsyncEvent<K, V> implements AsyncEvent<K, V> {
+ private final Region region;
+ private final Operation operation;
+ private final K key;
+ private final V value;
+
+ public TestAsyncEvent(Region region, Operation operation, K key, V value) {
+ this.region = region;
+ this.operation = operation;
+ this.key = key;
+ this.value = value;
+ }
+
+ @Override
+ public boolean getPossibleDuplicate() {
+ return false;
+ }
+
+ @Override
+ public EventSequenceID getEventSequenceID() {
+ return null;
+ }
+
+ @Override
+ public Region<K, V> getRegion() {
+ return region;
+ }
+
+ @Override
+ public Operation getOperation() {
+ return operation;
+ }
+
+ @Override
+ public Object getCallbackArgument() {
+ return null;
+ }
+
+ @Override
+ public K getKey() {
+ return key;
+ }
+
+ @Override
+ public V getDeserializedValue() {
+ return value;
+ }
+
+ @Override
+ public byte[] getSerializedValue() {
+ return new byte[0];
+ }
+ }
}
diff --git
a/async/src/test/java/org/apache/geode/examples/async/ExampleTest.java
b/async/src/test/java/org/apache/geode/examples/async/ExampleTest.java
index 834c318..3b0117d 100644
--- a/async/src/test/java/org/apache/geode/examples/async/ExampleTest.java
+++ b/async/src/test/java/org/apache/geode/examples/async/ExampleTest.java
@@ -15,6 +15,7 @@
package org.apache.geode.examples.async;
import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -23,7 +24,6 @@ import java.util.List;
import org.apache.geode.cache.Region;
-import org.geode.examples.util.Mocks;
import org.junit.Test;
public class ExampleTest {
@@ -31,8 +31,8 @@ public class ExampleTest {
public void testExample() throws Exception {
Example example = new Example();
- Region<String, String> outgoingRegion =
Mocks.region(Example.OUTGOING_REGION_NAME);
- Region<Integer, String> incomingRegion =
Mocks.region(Example.INCOMING_REGION_NAME);
+ Region<String, String> outgoingRegion = mock(Region.class);
+ Region<Integer, String> incomingRegion = mock(Region.class);
final List<String> words = Arrays.asList(new String[] {"that", "teh"});
when(outgoingRegion.sizeOnServer()).thenReturn(words.size());
diff --git
a/functions/src/test/java/org/apache/geode/examples/functions/ExampleTest.java
b/functions/src/test/java/org/apache/geode/examples/functions/ExampleTest.java
index cfb3ad5..0748b5b 100644
---
a/functions/src/test/java/org/apache/geode/examples/functions/ExampleTest.java
+++
b/functions/src/test/java/org/apache/geode/examples/functions/ExampleTest.java
@@ -15,6 +15,8 @@
package org.apache.geode.examples.functions;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.HashSet;
@@ -22,8 +24,8 @@ import java.util.List;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.execute.Execution;
+import org.apache.geode.cache.execute.ResultCollector;
-import org.geode.examples.util.Mocks;
import org.junit.Test;
public class ExampleTest {
@@ -31,9 +33,12 @@ public class ExampleTest {
public void testExample() throws Exception {
Example example = new Example(10);
- Region<Integer, String> region = Mocks.region("example-region");
+ Region<Integer, String> region = mock(Region.class);
List<Integer> primes = Arrays.asList(1, 2, 3, 5, 7);
- Execution execution = Mocks.execution(PrimeNumber.ID, primes);
+ ResultCollector resultCollector = mock(ResultCollector.class);
+ when(resultCollector.getResult()).thenReturn(primes);
+ Execution execution = mock(Execution.class);
+ when(execution.execute(PrimeNumber.ID)).thenReturn(resultCollector);
assertEquals(new HashSet(primes), example.getPrimes(region, execution));
}
diff --git
a/listener/src/test/java/org/apache/geode/examples/listener/ExampleTest.java
b/listener/src/test/java/org/apache/geode/examples/listener/ExampleTest.java
index fccda67..14db282 100644
--- a/listener/src/test/java/org/apache/geode/examples/listener/ExampleTest.java
+++ b/listener/src/test/java/org/apache/geode/examples/listener/ExampleTest.java
@@ -19,8 +19,6 @@ import static org.junit.Assert.assertEquals;
import java.util.HashMap;
import java.util.Map;
-import org.apache.geode.cache.Region;
-import org.geode.examples.util.Mocks;
import org.junit.Test;
public class ExampleTest {
diff --git
a/loader/src/test/java/org/apache/geode/examples/loader/ExampleTest.java
b/loader/src/test/java/org/apache/geode/examples/loader/ExampleTest.java
index 2a1f38a..40609de 100644
--- a/loader/src/test/java/org/apache/geode/examples/loader/ExampleTest.java
+++ b/loader/src/test/java/org/apache/geode/examples/loader/ExampleTest.java
@@ -24,8 +24,7 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.geode.cache.LoaderHelper;
-import org.apache.geode.cache.Region;
-import org.geode.examples.util.Mocks;
+
import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemOutRule;
diff --git a/src/test/java/org/geode/examples/util/Mocks.java
b/src/test/java/org/geode/examples/util/Mocks.java
deleted file mode 100644
index b1e0d8f..0000000
--- a/src/test/java/org/geode/examples/util/Mocks.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
- * agreements. See the NOTICE file distributed with this work for additional
information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache
License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
- * or implied. See the License for the specific language governing permissions
and limitations under
- * the License.
- */
-package org.geode.examples.util;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.doAnswer;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.execute.Execution;
-import org.apache.geode.cache.execute.ResultCollector;
-
-import org.mockito.invocation.InvocationOnMock;
-
-import org.apache.geode.cache.Region;
-
-public class Mocks {
- private Mocks() {
- }
-
- @SuppressWarnings("unchecked")
- public static <K, V> Region<K, V> region(String name) throws Exception {
- Map<K, V> data = new HashMap<>();
- Region<K, V> region = mock(Region.class);
-
- when(region.getName()).thenReturn(name);
- when(region.put(any(), any())).then(inv -> data.put(getKey(inv),
getValue(inv)));
- when(region.get(any())).then(inv -> data.get(getKey(inv)));
- when(region.keySet()).thenReturn(data.keySet());
- when(region.values()).thenReturn(data.values());
- when(region.size()).then(inv -> { return data.size(); });
- when(region.keySetOnServer()).thenReturn(data.keySet());
- when(region.containsKey(any())).then(inv -> data.containsKey(getKey(inv)));
- when(region.containsKeyOnServer(any())).then(inv ->
data.containsKey(getKey(inv)));
-
- doAnswer(inv -> {
- data.putAll((Map<? extends K, ? extends V>) inv.getArguments()[0]);
- return inv.getArguments();
- }).when(region).putAll(any());
-
- return region;
- }
-
- @SuppressWarnings("unchecked")
- public static Execution execution(String functionId, Object result) throws
Exception {
- ResultCollector resultCollector = mock(ResultCollector.class);
- when(resultCollector.getResult()).thenReturn(result);
-
- Execution execution = mock(Execution.class);
- when(execution.execute(functionId)).thenReturn(resultCollector);
-
- return execution;
- }
-
- @SuppressWarnings("unchecked")
- private static <K> K getKey(InvocationOnMock inv) {
- return (K) inv.getArguments()[0];
- }
-
- @SuppressWarnings("unchecked")
- private static <V> V getValue(InvocationOnMock inv) {
- return (V) inv.getArguments()[1];
- }
-}
diff --git a/src/test/java/org/geode/examples/util/TestAsyncEvent.java
b/src/test/java/org/geode/examples/util/TestAsyncEvent.java
deleted file mode 100644
index 1efe693..0000000
--- a/src/test/java/org/geode/examples/util/TestAsyncEvent.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
- * agreements. See the NOTICE file distributed with this work for additional
information regarding
- * copyright ownership. The ASF licenses this file to You under the Apache
License, Version 2.0 (the
- * "License"); you may not use this file except in compliance with the
License. You may obtain a
- * copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
- * or implied. See the License for the specific language governing permissions
and limitations under
- * the License.
- */
-package org.geode.examples.util;
-
-import org.apache.geode.cache.Operation;
-import org.apache.geode.cache.Region;
-import org.apache.geode.cache.asyncqueue.AsyncEvent;
-import org.apache.geode.cache.wan.EventSequenceID;
-
-public class TestAsyncEvent<K, V> implements AsyncEvent<K, V> {
- private final Region region;
- private final Operation operation;
- private final K key;
- private final V value;
-
- public TestAsyncEvent(Region region, Operation operation, K key, V value) {
- this.region = region;
- this.operation = operation;
- this.key = key;
- this.value = value;
- }
- @Override
- public boolean getPossibleDuplicate() {
- return false;
- }
-
- @Override
- public EventSequenceID getEventSequenceID() {
- return null;
- }
-
- @Override
- public Region<K, V> getRegion() {
- return region;
- }
-
- @Override
- public Operation getOperation() {
- return operation;
- }
-
- @Override
- public Object getCallbackArgument() {
- return null;
- }
-
- @Override
- public K getKey() {
- return key;
- }
-
- @Override
- public V getDeserializedValue() {
- return value;
- }
-
- @Override
- public byte[] getSerializedValue() {
- return new byte[0];
- }
-}
diff --git
a/writer/src/test/java/org/apache/geode/examples/writer/ExampleTest.java
b/writer/src/test/java/org/apache/geode/examples/writer/ExampleTest.java
index bfa252b..27cc719 100644
--- a/writer/src/test/java/org/apache/geode/examples/writer/ExampleTest.java
+++ b/writer/src/test/java/org/apache/geode/examples/writer/ExampleTest.java
@@ -17,6 +17,7 @@ package org.apache.geode.examples.writer;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
@@ -24,7 +25,6 @@ import java.util.Arrays;
import org.apache.geode.cache.CacheWriterException;
import org.apache.geode.cache.Region;
-import org.geode.examples.util.Mocks;
import org.junit.Test;
public class ExampleTest {
@@ -32,7 +32,7 @@ public class ExampleTest {
public void testExample() throws Exception {
Example example = new Example();
- Region<String, String> region = Mocks.region("example-region");
+ Region<String, String> region = mock(Region.class);
when(region.put(eq("666-66-6666"), any())).thenThrow(new
CacheWriterException());
when(region.put(eq("8675309"), any())).thenThrow(new
CacheWriterException());
when(region.put(eq("999-000-0000"), any())).thenThrow(new
CacheWriterException());
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].