You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2018/01/07 06:15:42 UTC

[GitHub] sijie closed pull request #937: Issue 935: Issue 915: Part 3 - Make circe-checksum module work for both java 8 and java 9

sijie closed pull request #937: Issue 935: Issue 915: Part 3 - Make circe-checksum module work for both java 8 and java 9
URL: https://github.com/apache/bookkeeper/pull/937
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/bookkeeper-server/pom.xml b/bookkeeper-server/pom.xml
index 5b8206616..7b62fb73a 100644
--- a/bookkeeper-server/pom.xml
+++ b/bookkeeper-server/pom.xml
@@ -33,6 +33,13 @@
       <groupId>org.apache.bookkeeper</groupId>
       <artifactId>bookkeeper-common</artifactId>
       <version>${project.parent.version}</version>
+      <exclusions>
+        <!-- exclude "netty-common" since "netty-all" already introduces it -->
+        <exclusion>
+          <groupId>io.netty</groupId>
+          <artifactId>netty-common</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
     <dependency>
       <groupId>org.apache.bookkeeper</groupId>
@@ -70,7 +77,7 @@
         <exclusion>
           <groupId>log4j</groupId>
           <artifactId>log4j</artifactId>
-	</exclusion>
+	    </exclusion>
         <exclusion>
           <groupId>io.netty</groupId>
           <artifactId>netty</artifactId>
@@ -78,27 +85,29 @@
       </exclusions>
     </dependency>
     <dependency>
-      <groupId>org.apache.zookeeper</groupId>
-      <artifactId>zookeeper</artifactId>
-      <version>${zookeeper.version}</version>
-      <type>test-jar</type>
-      <scope>test</scope>
+      <groupId>io.netty</groupId>
+      <artifactId>netty-all</artifactId>
+      <version>${netty.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>io.netty</groupId>
+      <artifactId>netty-tcnative-boringssl-static</artifactId>
+      <version>${netty-boringssl.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.bookkeeper.http</groupId>
+      <artifactId>http-server</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.bookkeeper</groupId>
+      <artifactId>circe-checksum</artifactId>
+      <version>${project.version}</version>
       <exclusions>
-        <exclusion>
-          <groupId>org.slf4j</groupId>
-          <artifactId>slf4j-log4j12</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>org.slf4j</groupId>
-          <artifactId>slf4j-api</artifactId>
-        </exclusion>
-        <exclusion>
-          <groupId>log4j</groupId>
-          <artifactId>log4j</artifactId>
-        </exclusion>
+        <!-- exclude "netty-buffer" since "netty-all" already introduces it -->
         <exclusion>
           <groupId>io.netty</groupId>
-          <artifactId>netty</artifactId>
+          <artifactId>netty-buffer</artifactId>
         </exclusion>
       </exclusions>
     </dependency>
@@ -161,11 +170,7 @@
         </exclusion>
       </exclusions>
     </dependency>
-    <dependency>
-      <groupId>io.netty</groupId>
-      <artifactId>netty-all</artifactId>
-      <version>${netty.version}</version>
-    </dependency>
+    <!-- testing dependencies -->
     <dependency>
       <groupId>org.apache.hadoop</groupId>
       <artifactId>hadoop-minikdc</artifactId>
@@ -173,19 +178,29 @@
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>io.netty</groupId>
-      <artifactId>netty-tcnative-boringssl-static</artifactId>
-      <version>${netty-boringssl.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.bookkeeper.http</groupId>
-      <artifactId>http-server</artifactId>
-      <version>${project.version}</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.pulsar</groupId>
-      <artifactId>pulsar-checksum</artifactId>
-      <version>1.20.0-incubating</version>
+      <groupId>org.apache.zookeeper</groupId>
+      <artifactId>zookeeper</artifactId>
+      <version>${zookeeper.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+      <exclusions>
+        <exclusion>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-log4j12</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>org.slf4j</groupId>
+          <artifactId>slf4j-api</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>log4j</groupId>
+          <artifactId>log4j</artifactId>
+        </exclusion>
+        <exclusion>
+          <groupId>io.netty</groupId>
+          <artifactId>netty</artifactId>
+        </exclusion>
+      </exclusions>
     </dependency>
   </dependencies>
   <build>
@@ -224,6 +239,7 @@
                   <include>com.google.protobuf:protobuf-java</include>
                   <include>org.apache.bookkeeper:bookkeeper-common</include>
                   <include>org.apache.bookkeeper:bookkeeper-proto</include>
+                  <include>org.apache.bookkeeper:circe-checksum</include>
                   <include>org.apache.bookkeeper.stats:bookkeeper-stats-api</include>
                 </includes>
               </artifactSet>
diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/CRC32CDigestManager.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/CRC32CDigestManager.java
index 1923220d7..86394ccf3 100644
--- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/CRC32CDigestManager.java
+++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/client/CRC32CDigestManager.java
@@ -18,11 +18,11 @@
 * limitations under the License.
 */
 
+import com.scurrilous.circe.checksum.Crc32cIntChecksum;
 import com.scurrilous.circe.crc.Sse42Crc32C;
 import io.netty.buffer.ByteBuf;
 import org.apache.commons.lang3.mutable.MutableBoolean;
 import org.apache.commons.lang3.mutable.MutableInt;
-import org.apache.pulsar.checksum.utils.Crc32cChecksum;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -56,10 +56,10 @@ void populateValueAndReset(ByteBuf buf) {
     void update(ByteBuf data) {
         if (isNewCrc.get().isTrue()) {
             isNewCrc.get().setFalse();
-            currentCrc.get().setValue(Crc32cChecksum.computeChecksum(data));
+            currentCrc.get().setValue(Crc32cIntChecksum.computeChecksum(data));
         } else {
             final int lastCrc = currentCrc.get().intValue();
-            currentCrc.get().setValue(Crc32cChecksum.resumeChecksum(lastCrc, data));
+            currentCrc.get().setValue(Crc32cIntChecksum.resumeChecksum(lastCrc, data));
         }
     }
 }
diff --git a/circe-checksum/pom.xml b/circe-checksum/pom.xml
index ddcd0f2e6..9b4f08408 100644
--- a/circe-checksum/pom.xml
+++ b/circe-checksum/pom.xml
@@ -54,19 +54,6 @@
       <version>${netty.version}</version>
     </dependency>
 
-    <dependency>
-      <groupId>org.testng</groupId>
-      <artifactId>testng</artifactId>
-      <version>6.8.5</version>
-    </dependency>
-    
-    <dependency>
-      <groupId>com.googlecode.jmockit</groupId>
-      <artifactId>jmockit</artifactId>
-      <version>1.7</version>
-      <scope>test</scope>
-    </dependency>
-
   </dependencies>
 
   <build>
@@ -105,7 +92,22 @@
           </execution>
         </executions>
       </plugin>
-
+      <plugin>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <version>${maven-compiler-plugin.version}</version>
+        <configuration>
+          <source>1.8</source>
+          <target>1.8</target>
+          <compilerArgs>
+            <!-- Object.finalize() is deprecated at java 9 -->
+            <!-- <compilerArg>-Werror</compilerArg> -->
+            <compilerArg>-Xlint:deprecation</compilerArg>
+            <compilerArg>-Xlint:unchecked</compilerArg>
+            <!-- https://issues.apache.org/jira/browse/MCOMPILER-205 -->
+            <compilerArg>-Xpkginfo:always</compilerArg>
+	  </compilerArgs>
+        </configuration>
+      </plugin>
       <plugin>
         <groupId>com.github.maven-nar</groupId>
         <artifactId>nar-maven-plugin</artifactId>
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/CommonHashesTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/CommonHashesTest.java
index a42de857c..f69e59916 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/CommonHashesTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/CommonHashesTest.java
@@ -15,11 +15,10 @@
  ******************************************************************************/
 package com.scurrilous.circe;
 
-import static org.testng.Assert.assertEquals;
+import static org.junit.Assert.assertEquals;
 
 import java.nio.charset.Charset;
-
-import org.testng.annotations.Test;
+import org.junit.Test;
 
 @SuppressWarnings("javadoc")
 public class CommonHashesTest {
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/checksum/ChecksumTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/checksum/ChecksumTest.java
index f6b0b9b75..67fee3ce3 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/checksum/ChecksumTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/checksum/ChecksumTest.java
@@ -19,14 +19,14 @@
 package com.scurrilous.circe.checksum;
 
 import static com.scurrilous.circe.params.CrcParameters.CRC32C;
-import static org.testng.Assert.assertEquals;
+import static org.junit.Assert.assertEquals;
 
 import com.scurrilous.circe.IncrementalIntHash;
 import com.scurrilous.circe.IncrementalLongHash;
 import com.scurrilous.circe.crc.StandardCrcProvider;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
-import org.testng.annotations.Test;
+import org.junit.Test;
 
 /**
  * Verify circe checksum.
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCProvidersTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCProvidersTest.java
index b3ac059c6..81ff710f6 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCProvidersTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCProvidersTest.java
@@ -24,21 +24,20 @@
 import static com.scurrilous.circe.HashSupport.STATELESS_INCREMENTAL;
 import static com.scurrilous.circe.params.CrcParameters.CRC32;
 import static com.scurrilous.circe.params.CrcParameters.CRC64;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
 import java.util.EnumSet;
 import java.util.Iterator;
 import java.util.Map.Entry;
 import java.util.SortedMap;
 
-import org.testng.annotations.Test;
-
 import com.scurrilous.circe.HashProvider;
 import com.scurrilous.circe.HashProviders;
 import com.scurrilous.circe.HashSupport;
 import com.scurrilous.circe.IncrementalLongHash;
+import org.junit.Test;
 
 @SuppressWarnings("javadoc")
 public class CRCProvidersTest {
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCTest.java
index e5eb77d6a..287026c8f 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/crc/CRCTest.java
@@ -24,16 +24,14 @@
 import static com.scurrilous.circe.params.CrcParameters.CRC32_POSIX;
 import static com.scurrilous.circe.params.CrcParameters.CRC64;
 import static com.scurrilous.circe.params.CrcParameters.CRC64_XZ;
-import static org.testng.Assert.assertEquals;
+import static org.junit.Assert.assertEquals;
 
 import com.scurrilous.circe.IncrementalLongHash;
-import java.nio.charset.Charset;
-
-import org.testng.annotations.Test;
-
 import com.scurrilous.circe.HashProvider;
 import com.scurrilous.circe.IncrementalIntHash;
 import com.scurrilous.circe.params.CrcParameters;
+import java.nio.charset.Charset;
+import org.junit.Test;
 
 /**
  * Tests the {@link StandardCrcProvider} with various CRC algorithms. See the <a
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalIntHashTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalIntHashTest.java
index 0f947c907..7b75a03df 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalIntHashTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalIntHashTest.java
@@ -15,101 +15,106 @@
  ******************************************************************************/
 package com.scurrilous.circe.impl;
 
-import static org.testng.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import com.scurrilous.circe.StatefulHash;
 import java.nio.ByteBuffer;
-import mockit.Expectations;
-import mockit.Mocked;
-import org.testng.annotations.Test;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
 
 @SuppressWarnings("javadoc")
 public class AbstractIncrementalIntHashTest {
 
-    @Mocked
     private AbstractIncrementalIntHash hash;
 
+    @Before
+    public void setup() {
+        this.hash = mock(AbstractIncrementalIntHash.class, Mockito.CALLS_REAL_METHODS);
+    }
+
     @Test
     public void testAsStateful() {
         final byte[] input = new byte[10];
-        new Expectations(hash) {
-            {
-                hash.algorithm();
-                hash.length();
-                hash.initial();
-                result = 42;
-                hash.resumeUnchecked(42, input, 2, 4);
-                result = 99;
-            }
-        };
+
+        when(hash.initial()).thenReturn(42);
+        when(hash.resumeUnchecked(eq(42), eq(input), eq(2), eq(4))).thenReturn(99);
+
         StatefulHash stateful = hash.createStateful();
         stateful.algorithm();
         stateful.length();
-        assertNotEquals(stateful, stateful.createNew());
+        assertNotSame(stateful, stateful.createNew());
         stateful.reset();
         stateful.update(input, 2, 4);
         assertEquals(99, stateful.getInt());
+
+        // verification
+        verify(hash, times(1)).algorithm();
+        verify(hash, times(1)).length();
+        verify(hash, times(1)).initial();
+        verify(hash, times(1)).resumeUnchecked(
+            eq(42), eq(input), eq(2), eq(4));
     }
 
     @Test
     public void testCalculateByteArray() {
         final byte[] input = new byte[10];
-        new Expectations(hash) {
-            {
-                hash.initial();
-                result = 42;
-                hash.resume(42, input);
-            }
-        };
+
+        when(hash.initial()).thenReturn(42);
+
         hash.calculate(input);
+
+        verify(hash, times(1)).initial();
+        verify(hash, times(1)).resume(eq(42), eq(input));
     }
 
     @Test
     public void testCalculateByteArrayIntInt() {
         final byte[] input = new byte[10];
-        new Expectations(hash) {
-            {
-                hash.initial();
-                result = 42;
-                hash.resume(42, input, 2, 4);
-            }
-        };
+
+        when(hash.initial()).thenReturn(42);
+
         hash.calculate(input, 2, 4);
+
+        verify(hash, times(1)).initial();
+        verify(hash, times(1)).resume(eq(42), eq(input), eq(2), eq(4));
     }
 
     @Test
     public void testCalculateByteBuffer() {
         final ByteBuffer input = ByteBuffer.allocate(10);
-        new Expectations(hash) {
-            {
-                hash.initial();
-                result = 42;
-                hash.resume(42, input);
-            }
-        };
+
+        when(hash.initial()).thenReturn(42);
+
         hash.calculate(input);
+
+        verify(hash, times(1)).initial();
+        verify(hash, times(1)).resume(eq(42), eq(input));
     }
 
     @Test
     public void testResumeIntByteArray() {
         final byte[] input = new byte[10];
-        new Expectations(hash) {
-            {
-                hash.resumeUnchecked(42, input, 0, input.length);
-            }
-        };
+
         hash.resume(42, input);
+
+        verify(hash, times(1)).resumeUnchecked(eq(42), eq(input), eq(0), eq(input.length));
     }
 
     @Test
     public void testResumeIntByteArrayIntInt() {
         final byte[] input = new byte[10];
-        new Expectations(hash) {
-            {
-                hash.resumeUnchecked(42, input, 2, 4);
-            }
-        };
+
         hash.resume(42, input, 2, 4);
+
+        verify(hash, times(1)).resumeUnchecked(eq(42), eq(input), eq(2), eq(4));
     }
 
     @Test
@@ -117,13 +122,12 @@ public void testResumeIntByteBuffer() {
         final ByteBuffer input = ByteBuffer.allocate(20);
         input.position(5);
         input.limit(15);
-        new Expectations(hash) {
-            {
-                hash.resumeUnchecked(42, input.array(), input.arrayOffset() + 5, 10);
-            }
-        };
+
         hash.resume(42, input);
         assertEquals(input.limit(), input.position());
+
+        verify(hash, times(1))
+            .resumeUnchecked(eq(42), eq(input.array()), eq(input.arrayOffset() + 5), eq(10));
     }
 
     @Test
@@ -131,12 +135,11 @@ public void testResumeIntReadOnlyByteBuffer() {
         final ByteBuffer input = ByteBuffer.allocate(20).asReadOnlyBuffer();
         input.position(5);
         input.limit(15);
-        new Expectations(hash) {
-            {
-                hash.resumeUnchecked(42, withInstanceOf(byte[].class), 0, 10);
-            }
-        };
+
         hash.resume(42, input);
         assertEquals(input.limit(), input.position());
+
+        verify(hash, times(1))
+            .resumeUnchecked(eq(42), any(byte[].class), eq(0), eq(10));
     }
 }
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalLongHashTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalLongHashTest.java
index 0468da8b0..81f8f72eb 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalLongHashTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractIncrementalLongHashTest.java
@@ -15,37 +15,39 @@
  ******************************************************************************/
 package com.scurrilous.circe.impl;
 
-import static org.testng.Assert.*;
-
-import java.nio.ByteBuffer;
-
-import mockit.Expectations;
-import mockit.Mocked;
-
-import org.testng.annotations.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import com.scurrilous.circe.StatefulHash;
-import com.scurrilous.circe.impl.AbstractIncrementalLongHash;
+import java.nio.ByteBuffer;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
 
 @SuppressWarnings("javadoc")
 public class AbstractIncrementalLongHashTest {
 
-    @Mocked
     private AbstractIncrementalLongHash hash;
 
+    @Before
+    public void setup() {
+        this.hash = mock(AbstractIncrementalLongHash.class, Mockito.CALLS_REAL_METHODS);
+    }
+
     @Test
     public void testAsStateful() {
         final byte[] input = new byte[10];
-        new Expectations(hash) {
-            {
-                hash.algorithm();
-                hash.length();
-                hash.initial();
-                result = 0x4200000000L;
-                hash.resumeUnchecked(0x4200000000L, input, 2, 4);
-                result = 0x990000000000L;
-            }
-        };
+
+        when(hash.initial()).thenReturn(0x4200000000L);
+        when(hash.resumeUnchecked(eq(0x4200000000L), eq(input), eq(2), eq(4)))
+            .thenReturn(0x990000000000L);
+
         StatefulHash stateful = hash.createStateful();
         stateful.algorithm();
         stateful.length();
@@ -54,67 +56,65 @@ public void testAsStateful() {
         stateful.update(input, 2, 4);
         assertEquals(0, stateful.getInt());
         assertEquals(0x990000000000L, stateful.getLong());
+
+        verify(hash, times(1)).algorithm();
+        verify(hash, times(1)).length();
+        verify(hash, times(1)).initial();
+        verify(hash, times(1)).resumeUnchecked(
+            eq(0x4200000000L), eq(input), eq(2), eq(4));
     }
 
     @Test
     public void testCalculateByteArray() {
         final byte[] input = new byte[10];
-        new Expectations(hash) {
-            {
-                hash.initial();
-                result = 0x4200000000L;
-                hash.resume(0x4200000000L, input);
-            }
-        };
+
+        when(hash.initial()).thenReturn(0x4200000000L);
+
         hash.calculate(input);
+
+        verify(hash, times(1)).resume(eq(0x4200000000L), eq(input));
     }
 
     @Test
     public void testCalculateByteArrayIntInt() {
         final byte[] input = new byte[10];
-        new Expectations(hash) {
-            {
-                hash.initial();
-                result = 0x4200000000L;
-                hash.resume(0x4200000000L, input, 2, 4);
-            }
-        };
+
+        when(hash.initial()).thenReturn(0x4200000000L);
+
         hash.calculate(input, 2, 4);
+
+        verify(hash, times(1)).resume(eq(0x4200000000L), eq(input), eq(2), eq(4));
     }
 
     @Test
     public void testCalculateByteBuffer() {
         final ByteBuffer input = ByteBuffer.allocate(10);
-        new Expectations(hash) {
-            {
-                hash.initial();
-                result = 0x4200000000L;
-                hash.resume(0x4200000000L, input);
-            }
-        };
+
+        when(hash.initial()).thenReturn(0x4200000000L);
+
         hash.calculate(input);
+
+        verify(hash, times(1)).resume(eq(0x4200000000L), eq(input));
     }
 
     @Test
     public void testResumeLongByteArray() {
         final byte[] input = new byte[10];
-        new Expectations(hash) {
-            {
-                hash.resumeUnchecked(0x4200000000L, input, 0, input.length);
-            }
-        };
+
         hash.resume(0x4200000000L, input);
+
+        verify(hash, times(1))
+            .resumeUnchecked(eq(0x4200000000L), eq(input), eq(0), eq(input.length));
     }
 
     @Test
     public void testResumeLongByteArrayIntInt() {
         final byte[] input = new byte[10];
-        new Expectations(hash) {
-            {
-                hash.resumeUnchecked(0x4200000000L, input, 2, 4);
-            }
-        };
+
         hash.resume(0x4200000000L, input, 2, 4);
+
+        verify(hash, times(1))
+            .resumeUnchecked(eq(0x4200000000L), eq(input), eq(2), eq(4));
     }
 
     @Test
@@ -122,13 +122,12 @@ public void testResumeLongByteBuffer() {
         final ByteBuffer input = ByteBuffer.allocate(20);
         input.position(5);
         input.limit(15);
-        new Expectations(hash) {
-            {
-                hash.resumeUnchecked(0x4200000000L, input.array(), input.arrayOffset() + 5, 10);
-            }
-        };
+
         hash.resume(0x4200000000L, input);
         assertEquals(input.limit(), input.position());
+
+        verify(hash, times(1))
+            .resumeUnchecked(eq(0x4200000000L), eq(input.array()), eq(input.arrayOffset() + 5), eq(10));
     }
 
     @Test
@@ -136,12 +135,11 @@ public void testResumeLongReadOnlyByteBuffer() {
         final ByteBuffer input = ByteBuffer.allocate(20).asReadOnlyBuffer();
         input.position(5);
         input.limit(15);
-        new Expectations(hash) {
-            {
-                hash.resumeUnchecked(0x4200000000L, withInstanceOf(byte[].class), 0, 10);
-            }
-        };
+
         hash.resume(0x4200000000L, input);
         assertEquals(input.limit(), input.position());
+
+        verify(hash, times(1))
+            .resumeUnchecked(eq(0x4200000000L), any(byte[].class), eq(0), eq(10));
     }
 }
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatefulHashTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatefulHashTest.java
index 8cad8b1b1..968e18b55 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatefulHashTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatefulHashTest.java
@@ -15,67 +15,71 @@
  ******************************************************************************/
 package com.scurrilous.circe.impl;
 
-import static org.testng.Assert.assertEquals;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.atLeast;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
 
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.List;
 
-import mockit.Expectations;
-import mockit.Mocked;
-import mockit.NonStrictExpectations;
-
-import org.testng.annotations.Test;
+import org.junit.Test;
+import org.mockito.Mockito;
 
 @SuppressWarnings("javadoc")
 public class AbstractStatefulHashTest {
 
-    @Mocked
     private AbstractStatefulHash hash;
 
+    public AbstractStatefulHashTest() {
+        this.hash = mock(AbstractStatefulHash.class, Mockito.CALLS_REAL_METHODS);
+    }
+
     @Test
     public void testUpdateByteArray() {
         final byte[] input = new byte[42];
-        new Expectations(hash) {
-            {
-                hash.updateUnchecked(input, 0, input.length);
-            }
-        };
+
         hash.update(input);
+
+        verify(hash, times(1))
+            .updateUnchecked(eq(input), eq(0), eq(input.length));
     }
 
     @Test
     public void testUpdateByteArrayIntInt() {
         final byte[] input = new byte[42];
-        new Expectations(hash) {
-            {
-                hash.updateUnchecked(input, 5, 10);
-            }
-        };
+
         hash.update(input, 5, 10);
+
+        verify(hash, times(1))
+            .updateUnchecked(eq(input), eq(5), eq(10));
     }
 
-    @Test(expectedExceptions = IllegalArgumentException.class)
+    @Test(expected = IllegalArgumentException.class)
     public void testUpdateByteArrayIntNegInt() {
         final byte[] input = new byte[42];
-        new Expectations(hash) {
-        };
+
         hash.update(input, 1, -1);
     }
 
-    @Test(expectedExceptions = IndexOutOfBoundsException.class)
+    @Test(expected = IndexOutOfBoundsException.class)
     public void testUpdateByteArrayNegIntInt() {
         final byte[] input = new byte[42];
-        new Expectations(hash) {
-        };
+
         hash.update(input, -1, 10);
     }
 
-    @Test(expectedExceptions = IndexOutOfBoundsException.class)
+    @Test(expected = IndexOutOfBoundsException.class)
     public void testUpdateByteArrayIntIntOverflow() {
         final byte[] input = new byte[42];
-        new Expectations(hash) {
-        };
+
         hash.update(input, 40, 3);
     }
 
@@ -84,13 +88,12 @@ public void testUpdateByteBuffer() {
         final ByteBuffer input = ByteBuffer.allocate(20);
         input.position(5);
         input.limit(15);
-        new Expectations(hash) {
-            {
-                hash.updateUnchecked(input.array(), input.arrayOffset() + 5, 10);
-            }
-        };
+
         hash.update(input);
         assertEquals(input.limit(), input.position());
+
+        verify(hash, times(1))
+            .updateUnchecked(eq(input.array()), eq(input.arrayOffset() + 5), eq(10));
     }
 
     @Test
@@ -98,25 +101,25 @@ public void testUpdateReadOnlyByteBuffer() {
         final ByteBuffer input = ByteBuffer.allocate(20).asReadOnlyBuffer();
         input.position(5);
         input.limit(15);
-        new Expectations(hash) {
-            {
-                hash.updateUnchecked(withInstanceOf(byte[].class), 0, 10);
-            }
-        };
+
         hash.update(input);
         assertEquals(input.limit(), input.position());
+
+        verify(hash, times(1))
+            .updateUnchecked(any(byte[].class), eq(0), eq(10));
     }
 
     @Test
     public void testGetBytes() {
         final List<byte[]> captures = new ArrayList<>();
-        new Expectations(hash) {
-            {
-                hash.length();
-                result = 5;
-                hash.writeBytes(withCapture(captures), 0, 5);
-            }
-        };
+
+        when(hash.length()).thenReturn(5);
+
+        doAnswer(invocationOnMock -> {
+            captures.add(invocationOnMock.getArgument(0));
+            return invocationOnMock.callRealMethod();
+        }).when(hash).writeBytes(any(byte[].class), eq(0), eq(5));
+
         hash.getBytes();
         assertEquals(5, captures.get(0).length);
     }
@@ -124,70 +127,54 @@ public void testGetBytes() {
     @Test
     public void testGetBytesByteArrayInt() {
         final byte[] output = new byte[5];
-        new Expectations(hash) {
-            {
-                hash.length();
-                result = output.length;
-                hash.getLong();
-                result = 0x1234567890L;
-            }
-        };
+
+        when(hash.length()).thenReturn(output.length);
+        when(hash.getLong()).thenReturn(0x1234567890L);
+
         hash.getBytes(output, 0, output.length);
-        assertEquals(new byte[] { (byte) 0x90, 0x78, 0x56, 0x34, 0x12 }, output);
+        assertArrayEquals(new byte[] { (byte) 0x90, 0x78, 0x56, 0x34, 0x12 }, output);
     }
 
-    @Test(expectedExceptions = IndexOutOfBoundsException.class)
+    @Test(expected = IndexOutOfBoundsException.class)
     public void testGetBytesByteArrayNegInt() {
         final byte[] output = new byte[5];
-        new NonStrictExpectations(hash) {
-            {
-                hash.length();
-                result = output.length;
-            }
-        };
+
+        when(hash.length()).thenReturn(output.length);
+
         hash.getBytes(output, -1, output.length);
+
+        verify(hash, atLeast(0)).length();
     }
 
-    @Test(expectedExceptions = IndexOutOfBoundsException.class)
+    @Test(expected = IndexOutOfBoundsException.class)
     public void testGetBytesByteArrayIntOverflow() {
         final byte[] output = new byte[5];
-        new Expectations(hash) {
-        };
+
         hash.getBytes(output, 0, output.length + 1);
     }
 
     @Test
     public void testGetBytesByteArrayIntPartial() {
         final byte[] output = new byte[5];
-        new Expectations(hash) {
-            {
-                hash.length();
-                result = output.length + 1;
-                hash.writeBytes(output, 0, output.length);
-            }
-        };
+
+        when(hash.length()).thenReturn(output.length + 1);
+
         hash.getBytes(output, 0, output.length);
+
+        verify(hash, times(1)).writeBytes(eq(output), eq(0), eq(output.length));
     }
 
     @Test
     public void testGetByte() {
-        new Expectations(hash) {
-            {
-                hash.getInt();
-                result = 0x12345678;
-            }
-        };
+        when(hash.getInt()).thenReturn(0x12345678);
+
         assertEquals(0x78, hash.getByte());
     }
 
     @Test
     public void testGetShort() {
-        new Expectations(hash) {
-            {
-                hash.getInt();
-                result = 0x12345678;
-            }
-        };
+        when(hash.getInt()).thenReturn(0x12345678);
+
         assertEquals(0x5678, hash.getShort());
     }
 }
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessIntHashTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessIntHashTest.java
index 184b54640..1aa3d5517 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessIntHashTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessIntHashTest.java
@@ -15,43 +15,45 @@
  ******************************************************************************/
 package com.scurrilous.circe.impl;
 
-import static org.testng.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 
 import java.nio.ByteBuffer;
 
-import mockit.Expectations;
-import mockit.Mocked;
-
-import org.testng.annotations.Test;
-
-import com.scurrilous.circe.impl.AbstractStatelessIntHash;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
 
 @SuppressWarnings("javadoc")
 public class AbstractStatelessIntHashTest {
 
-    @Mocked
     private AbstractStatelessIntHash hash;
 
+    @Before
+    public void setup() {
+        hash = mock(AbstractStatelessIntHash.class, Mockito.CALLS_REAL_METHODS);
+    }
+
     @Test
     public void testCalculateByteArray() {
         final byte[] input = new byte[10];
-        new Expectations(hash) {
-            {
-                hash.calculateUnchecked(input, 0, input.length);
-            }
-        };
+
         hash.calculate(input);
+
+        verify(hash, times(1)).calculateUnchecked(eq(input), eq(0), eq(input.length));
     }
 
     @Test
     public void testCalculateByteArrayIntInt() {
         final byte[] input = new byte[10];
-        new Expectations(hash) {
-            {
-                hash.calculateUnchecked(input, 2, 4);
-            }
-        };
+
         hash.calculate(input, 2, 4);
+
+        verify(hash, times(1)).calculateUnchecked(eq(input), eq(2), eq(4));
     }
 
     @Test
@@ -59,13 +61,12 @@ public void testCalculateByteBuffer() {
         final ByteBuffer input = ByteBuffer.allocate(20);
         input.position(5);
         input.limit(15);
-        new Expectations(hash) {
-            {
-                hash.calculateUnchecked(input.array(), input.arrayOffset() + 5, 10);
-            }
-        };
+
         hash.calculate(input);
         assertEquals(input.limit(), input.position());
+
+        verify(hash, times(1))
+            .calculateUnchecked(eq(input.array()), eq(input.arrayOffset() + 5), eq(10));
     }
 
     @Test
@@ -73,12 +74,11 @@ public void testCalculateReadOnlyByteBuffer() {
         final ByteBuffer input = ByteBuffer.allocate(20).asReadOnlyBuffer();
         input.position(5);
         input.limit(15);
-        new Expectations(hash) {
-            {
-                hash.calculateUnchecked(withInstanceOf(byte[].class), 0, 10);
-            }
-        };
+
         hash.calculate(input);
         assertEquals(input.limit(), input.position());
+
+        verify(hash, times(1))
+            .calculateUnchecked(any(byte[].class), eq(0), eq(10));
     }
 }
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessLongHashTest.java b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessLongHashTest.java
index a4a607f3c..d0aabd59e 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessLongHashTest.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/impl/AbstractStatelessLongHashTest.java
@@ -15,43 +15,47 @@
  ******************************************************************************/
 package com.scurrilous.circe.impl;
 
-import static org.testng.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
 
 import java.nio.ByteBuffer;
 
-import mockit.Expectations;
-import mockit.Mocked;
-
-import org.testng.annotations.Test;
-
-import com.scurrilous.circe.impl.AbstractStatelessLongHash;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
 
 @SuppressWarnings("javadoc")
 public class AbstractStatelessLongHashTest {
 
-    @Mocked
     private AbstractStatelessLongHash hash;
 
+    @Before
+    public void setup() {
+        this.hash = mock(AbstractStatelessLongHash.class, Mockito.CALLS_REAL_METHODS);
+    }
+
     @Test
     public void testCalculateByteArray() {
         final byte[] input = new byte[10];
-        new Expectations(hash) {
-            {
-                hash.calculateUnchecked(input, 0, input.length);
-            }
-        };
+
         hash.calculate(input);
+
+        verify(hash, times(1))
+            .calculateUnchecked(eq(input), eq(0), eq(input.length));
     }
 
     @Test
     public void testCalculateByteArrayIntInt() {
         final byte[] input = new byte[10];
-        new Expectations(hash) {
-            {
-                hash.calculateUnchecked(input, 2, 4);
-            }
-        };
+
         hash.calculate(input, 2, 4);
+
+        verify(hash, times(1))
+            .calculateUnchecked(eq(input), eq(2), eq(4));
     }
 
     @Test
@@ -59,13 +63,12 @@ public void testCalculateByteBuffer() {
         final ByteBuffer input = ByteBuffer.allocate(20);
         input.position(5);
         input.limit(15);
-        new Expectations(hash) {
-            {
-                hash.calculateUnchecked(input.array(), input.arrayOffset() + 5, 10);
-            }
-        };
+
         hash.calculate(input);
         assertEquals(input.limit(), input.position());
+
+        verify(hash, times(1))
+            .calculateUnchecked(eq(input.array()), eq(input.arrayOffset() + 5), eq(10));
     }
 
     @Test
@@ -73,12 +76,11 @@ public void testCalculateReadOnlyByteBuffer() {
         final ByteBuffer input = ByteBuffer.allocate(20).asReadOnlyBuffer();
         input.position(5);
         input.limit(15);
-        new Expectations(hash) {
-            {
-                hash.calculateUnchecked(withInstanceOf(byte[].class), 0, 10);
-            }
-        };
+
         hash.calculate(input);
         assertEquals(input.limit(), input.position());
+
+        verify(hash, times(1))
+            .calculateUnchecked(any(byte[].class), eq(0), eq(10));
     }
 }
diff --git a/circe-checksum/src/test/java/com/scurrilous/circe/utils/NativeUtilsTests.java b/circe-checksum/src/test/java/com/scurrilous/circe/utils/NativeUtilsTests.java
index f1d49288e..adaf7715d 100644
--- a/circe-checksum/src/test/java/com/scurrilous/circe/utils/NativeUtilsTests.java
+++ b/circe-checksum/src/test/java/com/scurrilous/circe/utils/NativeUtilsTests.java
@@ -19,8 +19,8 @@
 package com.scurrilous.circe.utils;
 
 import java.io.FileNotFoundException;
-import org.testng.Assert;
-import org.testng.annotations.Test;
+import org.junit.Assert;
+import org.junit.Test;
 
 /**
  * Unit test of {@link NativeUtils}.
diff --git a/shaded/bookkeeper-server-shaded/pom.xml b/shaded/bookkeeper-server-shaded/pom.xml
index d09b274d5..c2be72149 100644
--- a/shaded/bookkeeper-server-shaded/pom.xml
+++ b/shaded/bookkeeper-server-shaded/pom.xml
@@ -69,6 +69,7 @@
                   <include>org.apache.bookkeeper:bookkeeper-common</include>
                   <include>org.apache.bookkeeper:bookkeeper-proto</include>
                   <include>org.apache.bookkeeper:bookkeeper-server</include>
+                  <include>org.apache.bookkeeper:circe-checksum</include>
                   <include>org.apache.bookkeeper.stats:bookkeeper-stats-api</include>
                 </includes>
               </artifactSet>
diff --git a/tests/bookkeeper-server-shaded-artifact-test/pom.xml b/tests/bookkeeper-server-shaded-artifact-test/pom.xml
index 58328543e..aa40a121c 100644
--- a/tests/bookkeeper-server-shaded-artifact-test/pom.xml
+++ b/tests/bookkeeper-server-shaded-artifact-test/pom.xml
@@ -42,6 +42,10 @@
           <groupId>org.apache.bookkeeper</groupId>
           <artifactId>bookkeeper-proto</artifactId>
         </exclusion>
+        <exclusion>
+          <groupId>org.apache.bookkeeper</groupId>
+          <artifactId>circe-checksum</artifactId>
+        </exclusion>
       </exclusions>
     </dependency>
   </dependencies>
diff --git a/tests/bookkeeper-server-shaded-artifact-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedArtifactTest.java b/tests/bookkeeper-server-shaded-artifact-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedArtifactTest.java
index 9b97cc64d..80e2d0c67 100644
--- a/tests/bookkeeper-server-shaded-artifact-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedArtifactTest.java
+++ b/tests/bookkeeper-server-shaded-artifact-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedArtifactTest.java
@@ -59,4 +59,10 @@ public void testBookKeeperProto() throws Exception {
         Class.forName("org.apache.bookkeeper.proto.BookkeeperProtocol");
         assertTrue(true);
     }
+
+    @Test
+    public void testCirceChecksum() throws Exception {
+        Class.forName("com.scurrilous.circe.checksum.Crc32cIntChecksum");
+        assertTrue(true);
+    }
 }
diff --git a/tests/bookkeeper-server-shaded-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedJarTest.java b/tests/bookkeeper-server-shaded-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedJarTest.java
index 083935f57..e462d33d6 100644
--- a/tests/bookkeeper-server-shaded-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedJarTest.java
+++ b/tests/bookkeeper-server-shaded-test/src/test/java/org/apache/bookkeeper/tests/shaded/BookKeeperServerShadedJarTest.java
@@ -59,4 +59,10 @@ public void testBookKeeperProto() throws Exception {
         Class.forName("org.apache.bookkeeper.proto.BookkeeperProtocol");
         assertTrue(true);
     }
+
+    @Test
+    public void testCirceChecksum() throws Exception {
+        Class.forName("com.scurrilous.circe.checksum.Crc32cIntChecksum");
+        assertTrue(true);
+    }
 }


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services