reswqa commented on code in PR #7906:
URL: https://github.com/apache/iceberg/pull/7906#discussion_r1250513092


##########
common/src/main/java/org/apache/iceberg/common/testutils/PerTestCallbackWrapper.java:
##########
@@ -0,0 +1,51 @@
+/*
+ * 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.apache.iceberg.common.testutils;
+
+import org.junit.jupiter.api.extension.AfterEachCallback;
+import org.junit.jupiter.api.extension.BeforeEachCallback;
+import org.junit.jupiter.api.extension.ExtensionContext;
+
+/**
+ * This class is used to wrap a specific {@link CustomExtension} to junit5 
extension with test-level
+ * callbacks {@link BeforeEachCallback} and {@link AfterEachCallback}. It can 
be used as a
+ * substitute for @Rule in junit4.
+ */
+public class PerTestCallbackWrapper<C extends CustomExtension>

Review Comment:
   I just writing an example to verify this as following: 
   
   Define the extension:
   ```
   public class TestExtension
       implements BeforeAllCallback, AfterAllCallback, BeforeEachCallback, 
AfterEachCallback {
   
     public void afterAll(ExtensionContext context) throws Exception {
       System.out.println("after all");
     }
   
     public void afterEach(ExtensionContext context) throws Exception {
       System.out.println("after each");
     }
   
     public void beforeAll(ExtensionContext context) throws Exception {
       System.out.println("before all");
     }
   
     @Override
     public void beforeEach(ExtensionContext context) throws Exception {
       System.out.println("before each");
     }
   }
   ```
   
   Test Class:
   ```
   class ExtensionTest {
     @RegisterExtension static TestExtension testExtension = new 
TestExtension();
   
     @Test
     void test1() {
       System.out.println("test1");
     }
   
     @Test
     void test2() {
       System.out.println("test2");
     }
   }
   ```
   
   The output is:
   ```
   before all
   before each
   test1
   after each
   before each
   test2
   after each
   after all
   ```
   
   And If I directly use the `ExtendWith` annotation instead of static 
`RegisterExtension`, the output is also the same.
   ```
   @ExtendWith(TestExtension.class)
   class ExtensionTest {}
   ```
   



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to