[AMORO-4203][optimizer-common] Migrate tests from JUnit 4 to JUnit 5#4204
Merged
xxubai merged 1 commit intoMay 7, 2026
Merged
Conversation
Migrate the 5 test files in amoro-optimizer-common to JUnit Jupiter: OptimizerTestBase, TestOptimizer, TestOptimizerToucher, TestOptimizerExecutor, TestOptimizerConfig. OptimizerTestBase no longer uses @ClassRule on TestAms (which still extends ExternalResource until the closing PR of apache#4203). Its public before()/after() are invoked from @BeforeAll/@afterall instead, which preserves the original lifecycle without forcing TestAms itself to migrate yet. The duplicated @BeforeClass reduceCallAmsInterval() in TestOptimizer is dropped because the parent already runs it. Mechanical changes elsewhere: org.junit.* -> org.junit.jupiter.api.*; @Before/@after -> @BeforeEach/@AfterEach; Assert.assertX -> Assertions.assertX; @test(expected=CmdLineException.class) in TestOptimizerConfig -> three Assertions.assertThrows(...) calls. mvn -pl amoro-optimizer/amoro-optimizer-common -am test passes (10/10).
Contributor
Author
12 tasks
xxubai
approved these changes
May 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this PR for?
Closes part of #4203 (Step 2 —
amoro-optimizer-common, the smallest leaf module).Migrates the 5 test files in
amoro-optimizer-commonto JUnit Jupiter:OptimizerTestBaseTestOptimizerTestOptimizerToucherTestOptimizerExecutorTestOptimizerConfigHow TestAms is consumed without migrating it yet
OptimizerTestBasepreviously held@ClassRule public static TestAms TEST_AMS = new TestAms();.TestAmsextendsorg.junit.rules.ExternalResourceand is shared across many modules, so per the staged plan in #4203 it stays on JUnit 4 until the very last (Step 9) PR.To unblock this step, the base class now invokes
TEST_AMS.before()from@BeforeAllandTEST_AMS.after()from@AfterAll. Both methods are alreadypubliconTestAms, so no reflection or wrapper is needed and the lifecycle is identical to what@ClassRuleproduced. Once #4203 reaches Step 9,TestAmswill move to a JUnit 5Extensionand these direct calls can be replaced with@RegisterExtensionfor free.Other mechanical changes
org.junit.*→org.junit.jupiter.api.*@Before/@After→@BeforeEach/@AfterEach;@BeforeClass→@BeforeAllAssert.assertX(...)→Assertions.assertX(...)TestOptimizerConfig: three@Test(expected = CmdLineException.class)rewritten asAssertions.assertThrows(CmdLineException.class, () -> ...)TestOptimizer: dropped its duplicate@BeforeClass reduceCallAmsInterval()because the parent already callsOptimizerTestHelpers.setCallAmsIntervalForTest()from@BeforeAllType of change
How was this patch tested?
mvn -pl amoro-optimizer/amoro-optimizer-common -am test→ 10/10 tests pass under the JUnit Platform provider,mvn spotless:checkclean.