Skip to content

[AMORO-4203][optimizer-common] Migrate tests from JUnit 4 to JUnit 5#4204

Merged
xxubai merged 1 commit into
apache:masterfrom
lintingbin:feat/junit5-amoro-optimizer-common
May 7, 2026
Merged

[AMORO-4203][optimizer-common] Migrate tests from JUnit 4 to JUnit 5#4204
xxubai merged 1 commit into
apache:masterfrom
lintingbin:feat/junit5-amoro-optimizer-common

Conversation

@lintingbin
Copy link
Copy Markdown
Contributor

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-common to JUnit Jupiter:

  • OptimizerTestBase
  • TestOptimizer
  • TestOptimizerToucher
  • TestOptimizerExecutor
  • TestOptimizerConfig

How TestAms is consumed without migrating it yet

OptimizerTestBase previously held @ClassRule public static TestAms TEST_AMS = new TestAms();. TestAms extends org.junit.rules.ExternalResource and 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 @BeforeAll and TEST_AMS.after() from @AfterAll. Both methods are already public on TestAms, so no reflection or wrapper is needed and the lifecycle is identical to what @ClassRule produced. Once #4203 reaches Step 9, TestAms will move to a JUnit 5 Extension and these direct calls can be replaced with @RegisterExtension for free.

Other mechanical changes

  • org.junit.*org.junit.jupiter.api.*
  • @Before / @After@BeforeEach / @AfterEach; @BeforeClass@BeforeAll
  • Assert.assertX(...)Assertions.assertX(...)
  • TestOptimizerConfig: three @Test(expected = CmdLineException.class) rewritten as Assertions.assertThrows(CmdLineException.class, () -> ...)
  • TestOptimizer: dropped its duplicate @BeforeClass reduceCallAmsInterval() because the parent already calls OptimizerTestHelpers.setCallAmsIntervalForTest() from @BeforeAll

Type of change

  • Improvement (test infrastructure)

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:check clean.

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).
@github-actions github-actions Bot added the module:ams-optimizer AMS optimizer module label May 7, 2026
@lintingbin
Copy link
Copy Markdown
Contributor Author

@czy006 @xxubai CI is green. This is the smallest leaf in #4203 (5 files in amoro-optimizer-common) and serves as the pattern validator before fanning out — would appreciate a review when you have a chance.

@xxubai xxubai merged commit cf8ff05 into apache:master May 7, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

module:ams-optimizer AMS optimizer module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants