-
Notifications
You must be signed in to change notification settings - Fork 1.7k
GH-3873: Deprecate JUnit 4 utilities in the project #3878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
2da4d5d
077adbe
c8839a5
6fe5470
53a7686
7ea24ac
f48c8cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright 2002-2019 the original author or authors. | ||
| * Copyright 2002-2025 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
|
|
@@ -14,32 +14,34 @@ | |
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.springframework.kafka.test.rule; | ||
| package org.springframework.kafka.test.extensions; | ||
|
|
||
| import java.lang.reflect.Method; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import org.apache.logging.log4j.Level; | ||
| import org.junit.rules.MethodRule; | ||
| import org.junit.runners.model.FrameworkMethod; | ||
| import org.junit.runners.model.Statement; | ||
| import org.junit.jupiter.api.extension.ExtensionContext; | ||
| import org.junit.jupiter.api.extension.InvocationInterceptor; | ||
| import org.junit.jupiter.api.extension.ReflectiveInvocationContext; | ||
|
|
||
| import org.springframework.kafka.test.utils.JUnitUtils; | ||
| import org.springframework.kafka.test.utils.JUnitUtils.LevelsContainer; | ||
|
|
||
| /** | ||
| * A JUnit method @Rule that changes the logger level for a set of classes | ||
| * A JUnit extension @ that changes the logger level for a set of classes | ||
| * while a test method is running. Useful for performance or scalability tests | ||
| * where we don't want to generate a large log in a tight inner loop. | ||
| * | ||
| * @author Dave Syer | ||
| * @author Artem Bilan | ||
| * @author Gary Russell | ||
| * @author Sanghyoek An | ||
| * | ||
| */ | ||
| public class Log4j2LevelAdjuster implements MethodRule { | ||
| public class Log4j2LevelAdjuster implements InvocationInterceptor { | ||
|
||
|
|
||
| private final List<Class<?>> classes; | ||
|
|
||
|
|
@@ -60,25 +62,25 @@ public Log4j2LevelAdjuster categories(String... categoriesToAdjust) { | |
| } | ||
|
|
||
| @Override | ||
| public Statement apply(final Statement base, FrameworkMethod method, Object target) { | ||
| return new Statement() { | ||
| @Override | ||
| public void evaluate() throws Throwable { | ||
| LevelsContainer container = null; | ||
| try { | ||
| container = JUnitUtils.adjustLogLevels(method.getName(), | ||
| Log4j2LevelAdjuster.this.classes, Log4j2LevelAdjuster.this.categories, | ||
| Log4j2LevelAdjuster.this.level); | ||
| base.evaluate(); | ||
| } | ||
| finally { | ||
| if (container != null) { | ||
| JUnitUtils.revertLevels(method.getName(), container); | ||
| } | ||
| } | ||
| } | ||
| public void interceptTestMethod(Invocation<Void> invocation, | ||
| ReflectiveInvocationContext<Method> invocationContext, | ||
| ExtensionContext extensionContext) throws Throwable { | ||
| String methodName = extensionContext.getRequiredTestMethod().getName(); | ||
| LevelsContainer container = null; | ||
|
|
||
| }; | ||
| try { | ||
| container = JUnitUtils.adjustLogLevels( | ||
| methodName, | ||
| Log4j2LevelAdjuster.this.classes, | ||
| Log4j2LevelAdjuster.this.categories, | ||
| Log4j2LevelAdjuster.this.level); | ||
| invocation.proceed(); | ||
| } | ||
| finally { | ||
| if (container != null) { | ||
| JUnitUtils.revertLevels(methodName, container); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| /** | ||
| * Provides JUnit5 extensions. | ||
| */ | ||
| @org.jspecify.annotations.NullMarked | ||
| package org.springframework.kafka.test.extensions; |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ | |
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.springframework.kafka.test.rule; | ||
| package org.springframework.kafka.test.extensions; | ||
|
||
|
|
||
| import java.io.IOException; | ||
| import java.net.ServerSocket; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct.
We are talking about deprecation of the utility, but not total removal.
Therefore dependency and deprecated classes must still be here.
Again: we develop library, so whatever we do here might break target projects using our library.
Removing it temporary locally is a good way to check if we still have any JUnit 4 tests left. 😄