Skip to content

Conversation

@drow931
Copy link

@drow931 drow931 commented Jan 27, 2026

trpc-registry: migrate tests from JUnit 4 + PowerMock to JUnit 5 + Mockito

Migrate all test classes in trpc-registry module from JUnit 4 with
PowerMock to JUnit 5 with Mockito, improving test maintainability
and compatibility with modern Java versions.

Changes across all submodules:

Common Changes:

  • Replace JUnit 4 annotations with JUnit 5 equivalents:
  • Replace Assert.* with Assertions.*
  • Replace PowerMock static mocking with Mockito.mockStatic()
  • Replace Whitebox.invokeMethod() with Java reflection API
  • Update pom.xml files to add mockito-junit-jupiter dependency

Affected Modules:

  • trpc-registry-api (8 test files)
  • trpc-registry-consul (6 test files)
  • trpc-registry-nacos (4 test files)
  • trpc-registry-open-polaris (4 test files)
  • trpc-registry-zookeeper (2 test files)

Key Technical Changes:

  1. Static mocking pattern:

    • Before: PowerMockito.mockStatic(SomeClass.class)
    • After: MockedStatic mock = Mockito.mockStatic(SomeClass.class)
      with proper cleanup in @AfterEach
  2. Private method invocation:

    • Before: Whitebox.invokeMethod(obj, "method", args)
    • After: Method m = Class.getDeclaredMethod("method", types);
      m.setAccessible(true);
      m.invoke(obj, args);
  3. Assertions:

    • Before: Assert.assertEquals(expected, actual)
    • After: Assertions.assertEquals(expected, actual)

Total: 26 files changed, 349 insertions(+), 304 deletions(-)

@drow931 drow931 closed this Jan 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant