You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by zh...@apache.org on 2018/12/12 01:37:14 UTC

[geode] 01/01: GEODE-6143: remove PowerMock from DataTypeJUnitTest

This is an automated email from the ASF dual-hosted git repository.

zhouxj pushed a commit to branch feature/GEODE-6143-5
in repository https://gitbox.apache.org/repos/asf/geode.git

commit caa0458f3ec70479a6f6b5871234585fa762f66c
Author: zhouxh <gz...@pivotal.io>
AuthorDate: Tue Dec 11 17:35:50 2018 -0800

    GEODE-6143: remove PowerMock from DataTypeJUnitTest
---
 .../geode/internal/offheap/DataTypeJUnitTest.java  | 83 ++++++++--------------
 1 file changed, 30 insertions(+), 53 deletions(-)

diff --git a/geode-core/src/test/java/org/apache/geode/internal/offheap/DataTypeJUnitTest.java b/geode-core/src/test/java/org/apache/geode/internal/offheap/DataTypeJUnitTest.java
index 90b5532..ffa1685 100755
--- a/geode-core/src/test/java/org/apache/geode/internal/offheap/DataTypeJUnitTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/offheap/DataTypeJUnitTest.java
@@ -16,13 +16,8 @@ package org.apache.geode.internal.offheap;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.any;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.eq;
-import static org.mockito.Mockito.when;
 
 import java.io.ByteArrayOutputStream;
-import java.io.DataInput;
 import java.io.DataOutputStream;
 import java.io.File;
 import java.io.IOException;
@@ -50,32 +45,30 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.TimeUnit;
 
 import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
 
+import org.apache.geode.DataSerializable;
 import org.apache.geode.DataSerializer;
 import org.apache.geode.Instantiator;
 import org.apache.geode.distributed.internal.ReplyMessage;
 import org.apache.geode.internal.DSCODE;
-import org.apache.geode.internal.DSFIDFactory;
 import org.apache.geode.internal.DataSerializableFixedID;
 import org.apache.geode.internal.DataSerializableJUnitTest.DataSerializableImpl;
 import org.apache.geode.internal.InternalDataSerializer;
-import org.apache.geode.internal.InternalInstantiator;
 import org.apache.geode.internal.admin.remote.ShutdownAllResponse;
 import org.apache.geode.internal.cache.execute.data.CustId;
+import org.apache.geode.internal.cache.persistence.DiskStoreID;
 
 /**
  * Tests the DataType support for off-heap MemoryInspector.
  */
-@RunWith(PowerMockRunner.class)
-@PowerMockIgnore("*.UnitTest")
-@PrepareForTest({InternalInstantiator.class, Instantiator.class, DataSerializer.class,
-    DSFIDFactory.class})
 public class DataTypeJUnitTest {
+  static {
+    Instantiator.register(new Instantiator(CustId.class, (short) 1) {
+      public DataSerializable newInstance() {
+        return new CustId();
+      }
+    });
+  }
 
   @Test
   public void testDataSerializableFixedIDByte() throws IOException {
@@ -104,19 +97,16 @@ public class DataTypeJUnitTest {
 
   @Test
   public void testDataSerializableFixedIDInt() throws IOException, ClassNotFoundException {
-    Integer someDSFIDInt = new Integer(1);
-
-    PowerMockito.mockStatic(DSFIDFactory.class);
-    when(DSFIDFactory.create(eq(someDSFIDInt), any())).thenReturn(someDSFIDInt);
-    DSFIDFactory.create(someDSFIDInt, null);
+    // DiskStoreID is a DataSerializableFixedID
+    DiskStoreID dsId = new DiskStoreID(0x1L, 0x2L);
 
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     DataOutputStream out = new DataOutputStream(baos);
-    DataSerializer.writeByte(DSCODE.DS_FIXED_ID_INT.toByte(), out);
-    DataSerializer.writeInteger(someDSFIDInt, out);
+    DataSerializer.writeObject(dsId, out);
     byte[] bytes = baos.toByteArray();
+
     String type = DataType.getDataType(bytes);
-    assertEquals("org.apache.geode.internal.DataSerializableFixedID:" + Integer.class.getName(),
+    assertEquals("org.apache.geode.internal.DataSerializableFixedID:" + DiskStoreID.class.getName(),
         type);
   }
 
@@ -712,16 +702,8 @@ public class DataTypeJUnitTest {
 
   @Test
   public void getDataTypeShouldReturnUserDataSeriazliable() throws IOException {
-    Instantiator mockInstantiator = PowerMockito.mock(Instantiator.class);
-    doReturn(CustId.class).when(mockInstantiator).getInstantiatedClass();
-    mockInstantiator.getInstantiatedClass();
-
     int someClassId = 1;
 
-    PowerMockito.mockStatic(InternalInstantiator.class);
-    when(InternalInstantiator.getClassId(mockInstantiator.getClass())).thenReturn(someClassId);
-    when(InternalInstantiator.getInstantiator(someClassId)).thenReturn(mockInstantiator);
-
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     DataOutputStream out = new DataOutputStream(baos);
     out.writeByte(DSCODE.USER_DATA_SERIALIZABLE.toByte());
@@ -736,15 +718,7 @@ public class DataTypeJUnitTest {
 
   @Test
   public void getDataTypeShouldReturnUserDataSeriazliable2() throws IOException {
-    Instantiator mockInstantiator = PowerMockito.mock(Instantiator.class);
-    doReturn(CustId.class).when(mockInstantiator).getInstantiatedClass();
-    mockInstantiator.getInstantiatedClass();
-
-    int someClassId = 1;
-
-    PowerMockito.mockStatic(InternalInstantiator.class);
-    when(InternalInstantiator.getClassId(mockInstantiator.getClass())).thenReturn(someClassId);
-    when(InternalInstantiator.getInstantiator(someClassId)).thenReturn(mockInstantiator);
+    short someClassId = 1;
 
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     DataOutputStream out = new DataOutputStream(baos);
@@ -760,16 +734,8 @@ public class DataTypeJUnitTest {
 
   @Test
   public void getDataTypeShouldReturnUserDataSeriazliable4() throws IOException {
-    Instantiator mockInstantiator = PowerMockito.mock(Instantiator.class);
-    doReturn(CustId.class).when(mockInstantiator).getInstantiatedClass();
-    mockInstantiator.getInstantiatedClass();
-
     int someClassId = 1;
 
-    PowerMockito.mockStatic(InternalInstantiator.class);
-    when(InternalInstantiator.getClassId(mockInstantiator.getClass())).thenReturn(someClassId);
-    when(InternalInstantiator.getInstantiator(someClassId)).thenReturn(mockInstantiator);
-
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     DataOutputStream out = new DataOutputStream(baos);
     out.writeByte(DSCODE.USER_DATA_SERIALIZABLE_4.toByte());
@@ -835,19 +801,30 @@ public class DataTypeJUnitTest {
 
   @Test
   public void getDataTypeShouldReturnGemfireEnum() throws IOException {
-    PowerMockito.mockStatic(DataSerializer.class);
-    when(DataSerializer.readString(any(DataInput.class))).thenReturn("GEMFIRE_ENUM");
-
     ByteArrayOutputStream baos = new ByteArrayOutputStream();
     DataOutputStream out = new DataOutputStream(baos);
     out.writeByte(DSCODE.GEMFIRE_ENUM.toByte());
+    DataSerializer.writeString(DSCODE.GEMFIRE_ENUM.name(), out);
+
     byte[] bytes = baos.toByteArray();
     String type = DataType.getDataType(bytes);
 
     assertThat(type).isEqualTo("java.lang.Enum:GEMFIRE_ENUM");
   }
 
-  // TODO:PDX_INLINE_ENUM
+  @Test
+  public void getDataTypeShouldReturnPdxInlineEnum() throws IOException {
+    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+    DataOutputStream out = new DataOutputStream(baos);
+    out.writeByte(DSCODE.PDX_INLINE_ENUM.toByte());
+    DataSerializer.writeString(DSCODE.PDX_INLINE_ENUM.name(), out);
+
+    byte[] bytes = baos.toByteArray();
+    String type = DataType.getDataType(bytes);
+
+    assertThat(type).isEqualTo("java.lang.Enum:PDX_INLINE_ENUM");
+  }
+
   @Test
   public void testBigInteger() throws IOException {
     BigInteger value = BigInteger.ZERO;