ijuma commented on a change in pull request #9520:
URL: https://github.com/apache/kafka/pull/9520#discussion_r549419585



##########
File path: 
clients/src/test/java/org/apache/kafka/common/memory/GarbageCollectedMemoryPoolTest.java
##########
@@ -23,68 +23,74 @@
 import org.junit.Assert;
 import org.junit.Test;
 
+import static org.junit.Assert.assertThrows;
+
 
 public class GarbageCollectedMemoryPoolTest {
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testZeroSize() throws Exception {
-        new GarbageCollectedMemoryPool(0, 7, true, null);
+    @Test
+    public void testZeroSize() {
+        assertThrows(IllegalArgumentException.class,
+            () -> new GarbageCollectedMemoryPool(0, 7, true, null));
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testNegativeSize() throws Exception {
-        new GarbageCollectedMemoryPool(-1, 7, false, null);
+    @Test
+    public void testNegativeSize() {
+        assertThrows(IllegalArgumentException.class,
+            () -> new GarbageCollectedMemoryPool(-1, 7, false, null));
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testZeroMaxAllocation() throws Exception {
-        new GarbageCollectedMemoryPool(100, 0, true, null);
+    @Test
+    public void testZeroMaxAllocation() {
+        assertThrows(IllegalArgumentException.class,
+            () -> new GarbageCollectedMemoryPool(100, 0, true, null));
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testNegativeMaxAllocation() throws Exception {
-        new GarbageCollectedMemoryPool(100, -1, false, null);
+    @Test
+    public void testNegativeMaxAllocation() {
+        assertThrows(IllegalArgumentException.class,
+            () -> new GarbageCollectedMemoryPool(100, -1, false, null));
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testMaxAllocationLargerThanSize() throws Exception {
-        new GarbageCollectedMemoryPool(100, 101, true, null);
+    @Test
+    public void testMaxAllocationLargerThanSize() {
+        assertThrows(IllegalArgumentException.class,
+            () -> new GarbageCollectedMemoryPool(100, 101, true, null));
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testAllocationOverMaxAllocation() throws Exception {
+    @Test
+    public void testAllocationOverMaxAllocation() {
         GarbageCollectedMemoryPool pool = new GarbageCollectedMemoryPool(1000, 
10, false, null);
-        pool.tryAllocate(11);
+        assertThrows(IllegalArgumentException.class, () -> 
pool.tryAllocate(11));
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testAllocationZero() throws Exception {
+    @Test
+    public void testAllocationZero() {
         GarbageCollectedMemoryPool pool = new GarbageCollectedMemoryPool(1000, 
10, true, null);
-        pool.tryAllocate(0);
+        assertThrows(IllegalArgumentException.class, () -> 
pool.tryAllocate(0));
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testAllocationNegative() throws Exception {
+    @Test
+    public void testAllocationNegative() {
         GarbageCollectedMemoryPool pool = new GarbageCollectedMemoryPool(1000, 
10, false, null);
-        pool.tryAllocate(-1);
+        assertThrows(IllegalArgumentException.class, () -> 
pool.tryAllocate(-1));
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testReleaseNull() throws Exception {
+    @Test
+    public void testReleaseNull() {
         GarbageCollectedMemoryPool pool = new GarbageCollectedMemoryPool(1000, 
10, true, null);
-        pool.release(null);
+        assertThrows(IllegalArgumentException.class, () -> pool.release(null));
     }
 
-    @Test(expected = IllegalArgumentException.class)
-    public void testReleaseForeignBuffer() throws Exception {
+    @Test
+    public void testReleaseForeignBuffer() {
         GarbageCollectedMemoryPool pool = new GarbageCollectedMemoryPool(1000, 
10, true, null);
         ByteBuffer fellOffATruck = ByteBuffer.allocate(1);
-        pool.release(fellOffATruck);
-        pool.close();

Review comment:
       Do we still need to call `close` to avoid a leak?

##########
File path: 
clients/src/test/java/org/apache/kafka/common/record/MemoryRecordsBuilderTest.java
##########
@@ -504,20 +510,21 @@ public void writePastLimit() {
         }
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testAppendAtInvalidOffset() {
         ByteBuffer buffer = ByteBuffer.allocate(1024);
         buffer.position(bufferOffset);
 
         long logAppendTime = System.currentTimeMillis();
-        MemoryRecordsBuilder builder = new MemoryRecordsBuilder(buffer, 
RecordBatch.MAGIC_VALUE_V1, compressionType,
+        MemoryRecordsBuilder builder = new MemoryRecordsBuilder(buffer, 
RecordBatch.MAGIC_VALUE_V2, compressionType,

Review comment:
       Why did we change the magic value version here?

##########
File path: 
clients/src/test/java/org/apache/kafka/common/security/authenticator/SaslServerAuthenticatorTest.java
##########
@@ -67,8 +68,7 @@ public void testOversizeRequest() throws IOException {
             
invocation.<ByteBuffer>getArgument(0).putInt(SaslServerAuthenticator.MAX_RECEIVE_SIZE
 + 1);
             return 4;
         });
-        authenticator.authenticate();
-        verify(transportLayer).read(any(ByteBuffer.class));

Review comment:
       Why don't we need the `verify` call?

##########
File path: 
connect/api/src/test/java/org/apache/kafka/connect/data/SchemaBuilderTest.java
##########
@@ -293,16 +295,13 @@ public void testEmptyStruct() {
         new Struct(emptyStructSchema);
     }
 
-    @Test(expected = SchemaBuilderException.class)
+    @Test
     public void testDuplicateFields() {
-        final Schema schema = SchemaBuilder.struct()
-                .name("testing")
-                .field("id", SchemaBuilder.string().doc("").build())
-                .field("id", SchemaBuilder.string().doc("").build())
-                .build();
-        final Struct struct = new Struct(schema)
-                .put("id", "testing");
-        struct.validate();
+        assertThrows(SchemaBuilderException.class, () -> SchemaBuilder.struct()
+            .name("testing")
+            .field("id", SchemaBuilder.string().doc("").build())
+            .field("id", SchemaBuilder.string().doc("").build())
+            .build());

Review comment:
       It seems that we are not testing the `validate` method anymore.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to