geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From u..@apache.org
Subject geode git commit: GEODE-2995: Using Powermock to mock enums in CodecRegistryJUnitTest.java
Date Wed, 14 Jun 2017 22:29:32 GMT
Repository: geode
Updated Branches:
  refs/heads/feature/GEODE-2995 a460ee7c2 -> d790ed5d8


GEODE-2995: Using Powermock to mock enums in CodecRegistryJUnitTest.java


Project: http://git-wip-us.apache.org/repos/asf/geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/d790ed5d
Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/d790ed5d
Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/d790ed5d

Branch: refs/heads/feature/GEODE-2995
Commit: d790ed5d8f6efc2fcf0be13d388e0053f5695d56
Parents: a460ee7
Author: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Authored: Wed Jun 14 15:29:27 2017 -0700
Committer: Udo Kohlmeyer <ukohlmeyer@pivotal.io>
Committed: Wed Jun 14 15:29:27 2017 -0700

----------------------------------------------------------------------
 geode-protobuf/build.gradle                     |  4 +++
 .../geode/client/protocol/OpsProcessorTest.java |  2 ++
 .../registry/CodecRegistryJUnitTest.java        | 33 +++++++++++++-------
 3 files changed, 27 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/geode/blob/d790ed5d/geode-protobuf/build.gradle
----------------------------------------------------------------------
diff --git a/geode-protobuf/build.gradle b/geode-protobuf/build.gradle
index 7a5cbfb..2102f6a 100644
--- a/geode-protobuf/build.gradle
+++ b/geode-protobuf/build.gradle
@@ -32,6 +32,10 @@ dependencies {
     testCompile project(':geode-junit')
     testCompile files(project(':geode-core').sourceSets.test.output)
 
+    testCompile 'org.powermock:powermock-core:' + project.'powermock.version'
+    testCompile 'org.powermock:powermock-module-junit4:' + project.'powermock.version'
+    testCompile 'org.powermock:powermock-api-mockito:' + project.'powermock.version'
+
     compile 'com.google.protobuf:protobuf-java:3.3.1'
 }
 

http://git-wip-us.apache.org/repos/asf/geode/blob/d790ed5d/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java
b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java
index 271b934..7f3a86c 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/client/protocol/OpsProcessorTest.java
@@ -72,6 +72,8 @@ public class OpsProcessorTest {
 //        ProtobufRequestOperationParser.getRequestForOperationTypeID(messageRequest)))
 //            .thenReturn(expectedResponse);
 
+
+
     OpsProcessor processor = new OpsProcessor(opsHandlerRegistry, serializationCodecRegistry);
     ClientProtocol.Response response = processor.process(messageRequest);
     Assert.assertEquals(expectedResponse, response.getGetResponse());

http://git-wip-us.apache.org/repos/asf/geode/blob/d790ed5d/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java
b/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java
index a6c3e78..5811e08 100644
--- a/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java
+++ b/geode-protobuf/src/test/java/org/apache/geode/serialization/registry/CodecRegistryJUnitTest.java
@@ -24,36 +24,44 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
-import org.mockito.Mockito;
+import org.junit.runner.RunWith;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
 
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({SerializationType.class})
 @Category(UnitTest.class)
 public class CodecRegistryJUnitTest {
   private SerializationCodecRegistry codecRegistry;
+
   @Before
   public void startup() throws CodecAlreadyRegisteredForTypeException {
     codecRegistry = new SerializationCodecRegistry();
   }
 
   @After
-  public void tearDown(){
+  public void tearDown() {
     codecRegistry.shutdown();
   }
 
   @Test
   public void testRegisterCodec() throws CodecAlreadyRegisteredForTypeException {
-    Assert.assertEquals(0, codecRegistry.getRegisteredCodecCount());
-    codecRegistry.register(SerializationType.INT, new DummyTypeCodec());
-    Assert.assertEquals(1, codecRegistry.getRegisteredCodecCount());
+    Assert.assertEquals(10, codecRegistry.getRegisteredCodecCount());
+    SerializationType mockSerializationType = PowerMockito.mock(SerializationType.class);
+    codecRegistry.register(mockSerializationType, new DummyTypeCodec());
+    Assert.assertEquals(11, codecRegistry.getRegisteredCodecCount());
   }
 
   @Test
   public void testRegisteringCodecForRegisteredType_throwsException()
       throws CodecAlreadyRegisteredForTypeException {
-    codecRegistry.register(SerializationType.INT, new DummyTypeCodec());
+    SerializationType mockSerializationType = PowerMockito.mock(SerializationType.class);
+    codecRegistry.register(mockSerializationType, new DummyTypeCodec());
 
     boolean caughtException = false;
     try {
-      codecRegistry.register(SerializationType.INT, new DummyTypeCodec());
+      codecRegistry.register(mockSerializationType, new DummyTypeCodec());
     } catch (CodecAlreadyRegisteredForTypeException e) {
       caughtException = true;
     }
@@ -65,9 +73,9 @@ public class CodecRegistryJUnitTest {
   public void testGetRegisteredCodec()
       throws CodecAlreadyRegisteredForTypeException, CodecNotRegisteredForTypeException {
     TypeCodec expectedCodec = new DummyTypeCodec();
-    codecRegistry.register(SerializationType.INT, expectedCodec);
-    Assert.assertEquals(1, codecRegistry.getRegisteredCodecCount());
-    TypeCodec codec = codecRegistry.getCodecForType(SerializationType.INT);
+    SerializationType mockSerializationType = PowerMockito.mock(SerializationType.class);
+    codecRegistry.register(mockSerializationType, expectedCodec);
+    TypeCodec codec = codecRegistry.getCodecForType(mockSerializationType);
     Assert.assertSame(expectedCodec, codec);
   }
 
@@ -75,7 +83,8 @@ public class CodecRegistryJUnitTest {
   public void testGetCodecForUnregisteredType_throwsException() {
     boolean caughtException = false;
     try {
-      codecRegistry.getCodecForType(SerializationType.INT);
+      SerializationType mockSerializationType = PowerMockito.mock(SerializationType.class);
+      codecRegistry.getCodecForType(mockSerializationType);
     } catch (CodecNotRegisteredForTypeException e) {
       caughtException = true;
     }
@@ -96,7 +105,7 @@ public class CodecRegistryJUnitTest {
 
     @Override
     public SerializationType getSerializationType() {
-      return Mockito.mock(SerializationType.class);
+      return PowerMockito.mock(SerializationType.class);
     }
   }
 }


Mime
View raw message