mureinik opened a new pull request, #4475: URL: https://github.com/apache/eventmesh/pull/4475
### Motivation In its current form, the project has some JUnit 4 and some JUnit 5 (Jupiter) tests. This PR aims to align all the tests to a single modern framework, JUnit Jupiter, in order to make future development easier. ### Modifications As this PR is already pretty large as-is, it attempts to be non-opinionated and simply replace JUnit 4 calls with the closed JUnit Jupiter equivalents. Subsequent work may want to change some tests to take further advantage of JUnit Jupiter's features. This PR includes the following changes: 1. Gradle dependencies: 1. All the dependencies under `org.junit.jupiter` were consolidated to use the single artifact `org.junit.jupiter:junit-jupiter`. 1. The `junit:junit` dependency was removed in favor of `org.junit.jupiter:junit-jupiter` mentioned in 1.i. 1. The Mockito dependencies `org.mockito:mockito-core` and `org.mockito:mockito-inline` duplications were cleaned up, and each module was left only with the relevant dependency. 1. The `org.mockito:mockito-junit-jupiter` dependency was added to provide the integration with Mockito. 2. The `org.powermock:powermock-module-junit4` dependency was removed. 3. The `org.powermock:powermock-api-mockito2` dependency was removed. 1. Annotations 1. `org.junit.jupiter.api.BeforeEach` was used as a drop-in replacement for `org.junit.Before`. 1. `org.junit.jupiter.api.BeforeAll` was used as a drop-in replacement for `org.junit.BeforeClass`. 1. `org.junit.jupiter.api.AfterEach` was used as a drop-in replacement for `org.junit.After`. 1. `org.junit.jupiter.api.AfterAll` was used as a drop-in replacement for `org.junit.AfterClass`. 1. `org.junit.jupiter.api.AfterEach` was used as a drop-in replacement for `org.junit.After`. 1. `org.junit.jupiter.api.Disabled` was used as a drop-in replacement for `org.junit.Ignore`. 1. `org.junit.jupiter.api.Test` was used as a replacement for `org.junit.Test`, although with some caveats: 1. For the simple case with no arguments, `org.junit.jupiter.api.Test` was used as a drop-in replacement for `org.junit.Test`. 1. For the case where `org.junit.Test` was used with a `timeout` argument, a combination of `org.junit.jupiter.api.Test` and `org.junit.jupiter.api.Timeout` was used. 1. For the case where `org.junit.Test` was used with an `expected` argument, `org.junit.jupiter.api.Test` was used, but the assertion on the exception begin thrown is done explicitly in the test's code, see 3.i. below. 1. `org.junit.jupiter.api.extension.ExtendWith` was used as a replacement for `org.junit.runner.RunWith` with an extension corresponding to the runner being replaced. 1. `org.mockito.junit.jupiter.MockitoExtension` was used to provide the same functionality as `org.mockito.junit.MockitoJUnitRunner`. Since the extension is stricter than the runner, in some cases `org.mockito.junit.jupiter.MockitoSettings` was used to explicitly make the mocking more lenient. 4. `org.mockito.junit.jupiter.MockitoExtension` was used to replace usages of `org.powermock.modules.junit4.PowerMockRunner` and its associated annotations. 1. Assertions 1. `org.junit.jupiter.api.Assertions` was used as a drop-in replacement for `org.junit.Assert` for the case where the assertion was performed without a message. 1. `org.junit.jupiter.api.Assertions` was used instead of `org.junit.Assert` in the cases where an assertion method was used with a message, but the argument were permuted to fit the new method's signature. 1. `org.junit.jupiter.api.Assertions` does not have an equivalent of `org.junit.Asser`t's `assertThat` method, but luckily it was only used in a few places, and always used the `org.hamcrest.CoreMatchers.is` matcher. These assertions were rewritten as straight-forward `assertEquals` assertions. 1. `org.junit.jupiter.api.Assertions` does not have an equivalent of `org.hamcrest.MatcherAssert`'s `assertThat` method, but luckily it was only used in a few places, and always used the `org.hamcrest.CoreMatchers.is` matcher. These assertions were rewritten as straight-forward `assertEquals` assertions. 1. `org.junit.jupiter.api.Assertions`' `assertThrows` was used to assert an expected exception is thrown instead of using `org.junit.Test` with the `expected` annotation. 1. Mocking 1. Usages of `org.powermock.api.mockito.PowerMockito` were deemed to be unnescary, and replaced with straight-forward usages of `org.mockito.Mockito`. 5. Usages of `org.powermock.reflect.Whitebox` were cleaned, and the `org.mockito.InjectMocks` was used instead in order to inject mocks to the object under test. 6. ### Documentation - Does this pull request introduce a new feature? no - If yes, how is the feature documented? not applicable - If a feature is not applicable for documentation, explain why? It's not an external facing feature, it's an internal re-working of the testing framework - If a feature is not documented yet in this PR, please create a followup issue for adding the documentation -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@eventmesh.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@eventmesh.apache.org For additional commands, e-mail: dev-h...@eventmesh.apache.org