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 <92105726+Netyyyy@users.noreply.github.com>
- 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 <92105726+Netyyyy@users.noreply.github.com>
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
- 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 <92105726+Netyyyy@users.noreply.github.com>
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).

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR successfully migrates all tests in azure-spring-data-cosmos from JUnit 4 to JUnit 5 in preparation for Spring Boot 4 upgrade. The migration involves 85+ test files with comprehensive updates to annotations, imports, assertions, and test patterns.

Key Changes

  • Removed JUnit 4 dependencies (junit:junit 4.13.2, junit-vintage-engine 5.12.2)
  • Updated all test annotations from JUnit 4 to JUnit 5 equivalents
  • Converted @Test(expected=...) patterns to assertThrows() lambdas
  • Removed @ClassRule and @Rule annotations along with TestRule interface implementation
  • Updated static imports for assertions and test utilities

Reviewed changes

Copilot reviewed 92 out of 92 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pom.xml Removed JUnit 4 and vintage engine dependencies
external_dependencies.txt Removed JUnit 4 dependency version references
85+ test files Migrated annotations, imports, and assertions from JUnit 4 to JUnit 5
AbstractIntegrationTestCollectionManager.java Removed TestRule interface implementation
SimpleCosmosRepositoryUnitTest.java Added lenient() for Mockito stubbing

@Netyyyy Netyyyy marked this pull request as ready for review November 26, 2025 06:15
@Netyyyy Netyyyy requested review from a team as code owners November 26, 2025 06:15
@Netyyyy
Copy link
Member

Netyyyy commented Nov 26, 2025

Hi @kushagraThapar , we already check the changes, please help review it at your earliest convenience.

@kushagraThapar
Copy link
Member

Hi @kushagraThapar , we already check the changes, please help review it at your earliest convenience.

Thanks @Netyyyy we need to run the cosmos spring tests in order to verify the changes as well.

@kushagraThapar
Copy link
Member

/azp run java - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Netyyyy
Copy link
Member

Netyyyy commented Dec 1, 2025

/azp run java - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kushagraThapar
Copy link
Member

@Netyyyy
Copy link
Member

Netyyyy commented Dec 1, 2025

/azp run java - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Netyyyy
Copy link
Member

Netyyyy commented Dec 1, 2025

/azp run java - cosmos - tests

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Netyyyy
Copy link
Member

Netyyyy commented Dec 1, 2025

@Netyyyy I see few spring data cosmos tests failing here: https://dev.azure.com/azure-sdk/internal/_build/results?buildId=5622303&view=ms.vss-test-web.build-test-results-tab&runId=58230383&resultId=100167&paneView=debug Can you please look into it, thanks!

Hi @kushagraThapar , the tests passed, please help take a review, thanks.

Copy link
Member

@kushagraThapar kushagraThapar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @Netyyyy

@Netyyyy
Copy link
Member

Netyyyy commented Dec 2, 2025

/check-enforcer override

@Netyyyy Netyyyy merged commit 7ced330 into main Dec 2, 2025
79 of 94 checks passed
@Netyyyy Netyyyy deleted the copilot/migrate-junit4-to-junit5 branch December 2, 2025 01:29
Netyyyy pushed a commit to Netyyyy/azure-sdk-for-java that referenced this pull request Dec 2, 2025
…#47346)

- Removed JUnit 4 and junit-vintage-engine dependencies from pom.xml
- 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
- Migrate @test(expected=...) to assertThrows

(cherry picked from commit 7ced330)
Netyyyy added a commit that referenced this pull request Dec 22, 2025
* fix: suppress deprecation warnings for Spring Framework 7.0 @Nullable/@nonnull annotations

* replace ListenableFutureCallback

* add spring-boot-persistence and replace

* fix ConfigurableBootstrapContext/EnvironmentPostProcessor path

* replace with spring-boot-kafka

* remove alwaysApplyingWhenNonNull()

* replace with spring-boot-data-redis

* replace with spring-boot-jms

* replace with spring-boot-jdbc

* add spring-boot-restclient

* add spring-boot-security

* add spring-boot-jackson

* add spring-boot-http-converter

* replace new OAuth2ClientAutoConfiguration

* replace containsKey with containsHeader

* add spring-boot-health

* replace spring-boot-starter-web with spring-boot-starter-webmvc

* replace org.springframework.data.util.TypeInformation with org.springframework.data.core.TypeInformation

* replace with ParametersSource.of()

* replace QueryMethodEvaluationContextProvider with ValueExpressionDelegate

* replace ClassTypeInformation.from with TypeInformation.of

* Migrate azure-spring-data-cosmos tests from JUnit 4 to JUnit 5 (#47346)

* skip monitor for not support Spring Boot 4

* replace with jackson2

* replace spring.jms.listener.concurrency with spring.jms.listener.minConcurrency

* Add jackson-databind
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

4 participants