From 4de6a90801e3a9d51beb22821893a85cea76ac3a Mon Sep 17 00:00:00 2001 From: Ken Huang Date: Wed, 19 Jun 2024 15:39:16 +0900 Subject: [PATCH] KAFKA-16921 [6/N] Remove junit 4 dependency from connect:runtime module (#16383) Reviewers: Chia-Ping Tsai --- build.gradle | 4 - .../TransformationIntegrationTest.java | 10 +-- .../kafka/connect/util/ParameterizedTest.java | 83 ------------------- 3 files changed, 5 insertions(+), 92 deletions(-) delete mode 100644 connect/runtime/src/test/java/org/apache/kafka/connect/util/ParameterizedTest.java diff --git a/build.gradle b/build.gradle index 3bdb243ec2b..67f105c282c 100644 --- a/build.gradle +++ b/build.gradle @@ -523,7 +523,6 @@ subprojects { } else { useJUnitPlatform { includeTags "integration" - includeTags 'org.apache.kafka.test.IntegrationTest' } } @@ -561,7 +560,6 @@ subprojects { } else { useJUnitPlatform { excludeTags "integration" - excludeTags 'org.apache.kafka.test.IntegrationTest' } } @@ -3193,8 +3191,6 @@ project(':connect:runtime') { testImplementation project(':group-coordinator') testImplementation libs.junitJupiter - testImplementation libs.junitVintageEngine - testImplementation libs.mockitoJunitJupiter testImplementation libs.mockitoCore testImplementation libs.hamcrest testImplementation libs.mockitoJunitJupiter diff --git a/connect/runtime/src/test/java/org/apache/kafka/connect/integration/TransformationIntegrationTest.java b/connect/runtime/src/test/java/org/apache/kafka/connect/integration/TransformationIntegrationTest.java index 17d2e7da57a..c3a71841921 100644 --- a/connect/runtime/src/test/java/org/apache/kafka/connect/integration/TransformationIntegrationTest.java +++ b/connect/runtime/src/test/java/org/apache/kafka/connect/integration/TransformationIntegrationTest.java @@ -23,10 +23,10 @@ import org.apache.kafka.connect.transforms.predicates.HasHeaderKey; import org.apache.kafka.connect.transforms.predicates.RecordIsTombstone; import org.apache.kafka.connect.transforms.predicates.TopicNameMatches; import org.apache.kafka.connect.util.clusters.EmbeddedConnectCluster; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -72,7 +72,7 @@ public class TransformationIntegrationTest { private EmbeddedConnectCluster connect; private ConnectorHandle connectorHandle; - @Before + @BeforeEach public void setup() { // setup Connect worker properties Map workerProps = new HashMap<>(); @@ -99,7 +99,7 @@ public class TransformationIntegrationTest { connectorHandle = RuntimeHandles.get().connectorHandle(CONNECTOR_NAME); } - @After + @AfterEach public void close() { // delete connector handle RuntimeHandles.get().deleteConnector(CONNECTOR_NAME); diff --git a/connect/runtime/src/test/java/org/apache/kafka/connect/util/ParameterizedTest.java b/connect/runtime/src/test/java/org/apache/kafka/connect/util/ParameterizedTest.java deleted file mode 100644 index 5f168913542..00000000000 --- a/connect/runtime/src/test/java/org/apache/kafka/connect/util/ParameterizedTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.kafka.connect.util; - -import java.lang.annotation.Annotation; -import org.junit.runner.Description; -import org.junit.runner.manipulation.Filter; -import org.junit.runner.manipulation.NoTestsRemainException; -import org.junit.runners.Parameterized; - -/** - * Running a single parameterized test causes issue as explained in - * http://youtrack.jetbrains.com/issue/IDEA-65966 and - * https://stackoverflow.com/questions/12798079/initializationerror-with-eclipse-and-junit4-when-executing-a-single-test/18438718#18438718 - * - * As a workaround, the original filter needs to be wrapped and then pass it a deparameterized - * description which removes the parameter part (See deparametrizeName) - */ -public class ParameterizedTest extends Parameterized { - - public ParameterizedTest(Class klass) throws Throwable { - super(klass); - } - - @Override - public void filter(Filter filter) throws NoTestsRemainException { - super.filter(new FilterDecorator(filter)); - } - - private static String deparametrizeName(String name) { - //Each parameter is named as [0], [1] etc - if (name.startsWith("[")) { - return name; - } - - //Convert methodName[index](className) to methodName(className) - int indexOfOpenBracket = name.indexOf('['); - int indexOfCloseBracket = name.indexOf(']') + 1; - return name.substring(0, indexOfOpenBracket).concat(name.substring(indexOfCloseBracket)); - } - - private static Description wrap(Description description) { - String fixedName = deparametrizeName(description.getDisplayName()); - Description clonedDescription = Description.createSuiteDescription( - fixedName, - description.getAnnotations().toArray(new Annotation[0]) - ); - description.getChildren().forEach(child -> clonedDescription.addChild(wrap(child))); - return clonedDescription; - } - - private static class FilterDecorator extends Filter { - private final Filter delegate; - - private FilterDecorator(Filter delegate) { - this.delegate = delegate; - } - - @Override - public boolean shouldRun(Description description) { - return delegate.shouldRun(wrap(description)); - } - - @Override - public String describe() { - return delegate.describe(); - } - } -} \ No newline at end of file