Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 21, 2025

JUnit 4 to JUnit 5 Migration - COMPLETE ✅

Successfully migrated all tests in azure-spring-data-cosmos from JUnit 4 to JUnit 5 in preparation for Spring Boot 4 upgrade.

Migration Checklist

  • Explore repository and understand current state
  • Verify tests pass with JUnit 4 (120 tests passing)
  • Update pom.xml dependencies (removed JUnit 4, removed vintage engine)
  • Migrate test files (85+ files migrated)
    • Replace JUnit 4 imports with JUnit 5 equivalents
    • Update annotations (@test, @before, @after, @BeforeClass, @afterclass)
    • Update assertions (Assert.* to Assertions.*)
    • Update @RunWith annotations to @ExtendWith
    • Remove @ClassRule and @rule usage
    • Remove TestRule interface implementation
  • All tests compile successfully
  • Fix all test failures - convert @test(expected=...) to assertThrows
  • All 120 tests passing ✅

Changes

Dependencies (pom.xml)

  • Removed junit:junit 4.13.2 dependency
  • Removed junit-vintage-engine compatibility layer

Test Annotations & Imports (85+ files)

  • @Before/@After@BeforeEach/@AfterEach
  • @BeforeClass/@AfterClass@BeforeAll/@AfterAll
  • @Ignore@Disabled
  • @RunWith(MockitoJUnitRunner.class)@ExtendWith(MockitoExtension.class)
  • @RunWith(SpringJUnit4ClassRunner.class)@ExtendWith(SpringExtension.class)
  • org.junit.Assertorg.junit.jupiter.api.Assertions

Code Refactoring

  • Removed TestRule interface implementation from AbstractIntegrationTestCollectionManager
  • Removed @ClassRule and @Rule annotations
  • Converted all @Test(expected=Exception.class) to assertThrows() pattern
  • Fixed static imports for AssertJ and JUnit Jupiter compatibility
  • Used lenient() for Mockito stubbings that are not used in all tests

Example Conversion

// Before (JUnit 4)
@Test(expected = IllegalArgumentException.class)
public void testInvalid() {
    doSomething();
}

// After (JUnit 5)
@Test
public void testInvalid() {
    assertThrows(IllegalArgumentException.class, () -> {
        doSomething();
    });
}

Test Results

All 120 tests passing

  • 0 failures
  • 0 errors
  • 0 skipped
Original prompt

This section details on the original issue you should resolve

<issue_title>[FEATURE REQ] Migrate Junit4 to Jnuit5 in azure-spring-data-cosmos</issue_title>
<issue_description>Is your feature request related to a problem? Please describe.
Prepare for upgrading to Spring Boot 4, migrate all tests in azure-spring-data-cosmos from Junit4 to Jnuit5

Describe the solution you'd like
Migrate all tests in azure-spring-data-cosmos from Junit4 to Jnuit5, make sure all tests pass as before.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Description Added
  • Expected solution specified
    </issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 21, 2025 03:36
- Removed JUnit 4 and junit-vintage-engine dependencies from pom.xml
- Migrated 85+ test files from JUnit 4 to JUnit 5
- Updated imports from org.junit to org.junit.jupiter.api
- Replaced @Before/@after with @BeforeEach/@AfterEach
- Replaced @BeforeClass/@afterclass with @BeforeAll/@afterall
- Replaced @RunWith with @ExtendWith for Mockito and Spring
- Replaced Assert with Assertions
- Removed TestRule interface from AbstractIntegrationTestCollectionManager
- Fixed static imports for AssertJ and JUnit Jupiter

Remaining work:
- Fix a few remaining compilation errors in 3 test files
- Run full test suite to ensure all tests pass

Co-authored-by: Netyyyy <[email protected]>
- Successfully migrated all 85+ test files from JUnit 4 to JUnit 5
- All tests now compile successfully with JUnit 5
- Removed JUnit 4 and junit-vintage-engine dependencies
- Updated all annotations and assertions
- Fixed all import statements
- Removed TestRule interface usage

Remaining: 14 test failures to fix (mainly incorrect @test(expected=...) conversions)
These tests expect exceptions but were incorrectly migrated from @test(expected=Exception.class) syntax

Co-authored-by: Netyyyy <[email protected]>
Copilot AI changed the title [WIP] Migrate tests from Junit4 to Junit5 in azure-spring-data-cosmos Migrate azure-spring-data-cosmos tests from JUnit 4 to JUnit 5 Nov 21, 2025
Copilot AI requested a review from Netyyyy November 21, 2025 03:48
Copilot finished work on behalf of Netyyyy November 21, 2025 03:48
- Wrapped test bodies expecting exceptions with assertThrows() in CosmosTemplateUnitTest
- Wrapped test bodies expecting IllegalQueryException with assertThrows() in CriteriaUnitTest
- Wrapped all test bodies expecting IllegalArgumentException with assertThrows() in SimpleCosmosRepositoryIllegalTest
- Used lenient() for unused stubbing in SimpleCosmosRepositoryUnitTest to fix UnnecessaryStubbing errors

All 120 tests now pass successfully.

Co-authored-by: Netyyyy <[email protected]>
Copy link
Contributor Author

Copilot AI commented Nov 21, 2025

@copilot Fix pipeline errors: 1. https://dev.azure.com/azure-sdk/public/_build/results?buildId=5598343&view=logs&j=b70e5e73-bbb6-5567-0939-8415943fadb9&t=b64fce29-1009-5e76-50fb-7b596c2db4c3 ; 2. http...

Fixed all pipeline test failures. The issues were from incorrect @test(expected=Exception.class) conversions that didn't properly wrap test bodies with assertThrows().

Changes in commit ec7169c:

  • CosmosTemplateUnitTest: Wrapped test expecting IllegalArgumentException
  • CriteriaUnitTest: Wrapped 2 tests expecting IllegalQueryException
  • SimpleCosmosRepositoryIllegalTest: Wrapped 8 tests expecting IllegalArgumentException
  • SimpleCosmosRepositoryUnitTest: Used lenient() for unused Mockito stubbing

All 120 tests now pass successfully.

Copilot finished work on behalf of Netyyyy November 21, 2025 05:08
Removed junit and junit-vintage-engine dependencies.
@Netyyyy
Copy link
Member

Netyyyy commented Nov 21, 2025

/azp run java - spring - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

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.

[FEATURE REQ] Migrate Junit4 to Jnuit5 in azure-spring-data-cosmos

2 participants