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 changed the title Jdk17/springboot3 trpc-registry: migrate tests from JUnit 4 + PowerMock to JUnit 5 + Mockito Jan 27, 2026
@drow931 drow931 marked this pull request as ready for review January 27, 2026 07:18
@wardseptember wardseptember merged commit ad88b38 into trpc-group:JDK17/Springboot3 Jan 27, 2026
13 of 15 checks passed
@drow931 drow931 deleted the JDK17/Springboot3 branch January 27, 2026 08:49
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.

2 participants