Chore: migrate tests from jmockit to mockito to include test coverage in sonar report#229
Chore: migrate tests from jmockit to mockito to include test coverage in sonar report#229mcook42 wants to merge 55 commits into
Conversation
Removed @mocked on the J2735Bsm field — this was a misuse of jmockit for a plain getter/setter test. Replaced with a real instance and migrated imports from JUnit 4 Assert to JUnit 5 Assertions.
Migrated 22 of 28 tests. Patterns used: - @tested + @Injectable + @capturing -> @Injectmocks + @mock + MockedConstruction - new Expectations() { session.set(...); result = ...; } -> mockConstruction(SnmpSession.class, (mock, ctx) -> when(mock.set(...)).thenReturn/thenThrow(...)) - Extracted helper methods (mockSnmpSession, stubSessionReturning, assertBadRequestForErrorCode) to consolidate 9 near-duplicate tests The remaining 6 tests (deleteShouldCatchSessionIOException* and deleteShouldCatchSessionNullPointerException*) are @disabled with a TODO because pure Mockito cannot simulate a constructor throwing a checked exception: MockedConstruction wraps any throwable raised from the initializer in MockitoException, which the controller's catch(IOException) and catch(NullPointerException) blocks do not match. Unblocking options: inject a SnmpSession factory into TimDeleteController or adopt PowerMockito.whenNew.
The file had no live jmockit usage — only a commented-out @RunWith(JMockit.class) and a stale org.junit.runner.RunWith import. Removed dead imports and switched org.junit.Assert.assertEquals to org.junit.jupiter.api.Assertions.assertEquals. All 3 tests pass.
Removed dead jmockit imports and JUnit 4 residue; the file had only commented-out JMockit annotations and was already using JUnit 5 semantics. Aligned assertEquals argument order to JUnit 5 (expected, actual, message).
…mockit to Mockito
Replaced the 5 @capturing field mocks with per-test MockedStatic instances managed in @BeforeEach/@AfterEach. The tests do not stub or verify on the mocked builders, so Mockito's default null-returning stubs are equivalent to jmockit's @capturing behavior here.
… jmockit to Mockito
Removed the MockUp<LoggerFactory> that stubbed logger creation; the real SLF4J logger is harmless in these tests and nothing references the mock after construction.
…om jmockit to Mockito Removed the MockUp<LoggerFactory> that stubbed logger creation; the real SLF4J logger is harmless in these tests and nothing references the mock after construction.
Converted both @Capturing-param tests to MockedStatic patterns. For TimTransmogrifier (which has multiple static methods the production code calls), used Mockito.CALLS_REAL_METHODS as the default so only convertToXml is replaced with a throwing stub; updateRsuCreds/buildASD/etc. run real.
All tests in jpo-ode-core/plugins/svcs have been migrated to Mockito. This removes the jmockit dependency and the -javaagent line from the surefire argLine. Spring Boot 4.0.3's starter-test still brings in Mockito 5.x with the inline mock maker, which is all the migrated tests need.
Deleted the @disabled test `constructorShouldWithIOException` in `SnmpSessionTest` as the mocking limitations remain unresolved.
…njection Replaced `SnmpSession` constructor mocking with a factory pattern by injecting `SnmpSessionFactory`. Updated `TimDeleteController` and `TimQueryController` accordingly. Adjusted related tests for simplified mocking support.
Deleted the @disabled test `testSetChosenFieldException2` in `J2735ChoiceTest` as its mocking limitations remain unresolved and would require a production refactor or PowerMock to unblock.
Adds the factory infrastructure relied on by the SnmpSession refactor in 02ac21f: - SnmpSessionFactory functional interface - TransportMappingFactory functional interface - SnmpConfig @bean wiring SnmpSession::new as the default factory These were missed when staging the refactor commit; without them HEAD will not compile.
Reinstates interaction checks lost when these tests were converted from JMockit `Expectations`/`Verifications` blocks: - RsuHealthControllerTest now verifies RsuSnmp.sendSnmpV3Request was called with the expected username decoded from the auth header (null for no auth, "aladdin" for "Basic YWxhZGRpbjpvcGVuc2VzYW1l"). Previously the tests passed without exercising the Basic-auth decoding path. - RsuSnmpTest now verifies snmp.close() on the three success/no-response paths and verify(snmp, never()).close() on the IOException path, pinning down the resource-management contract of sendSnmpV3Request. - StompControllerTest.testGreeting: replaced the long jmockit-rationale comment with a one-liner. The existing getName() verification (which runs after Thread.sleep) already covers what the dropped Thread.sleep verification was checking.
Restore strictness lost during the JMockit→Mockito migration: - PdmControllerTest: replace any(Class.class) with eq(J2735PdmRequest.class) for JsonUtils.fromJson stubs and drop @MockitoSettings(LENIENT) so default strict-mode enforces argument-class matching and unused-stubbing checks. - RsuHealthControllerTest: assert exactly one DefaultUdpTransportMapping, Snmp, and USM are constructed per heartBeat call, and verify that the constructed USM is registered via SecurityModels.addSecurityModel — the original JMockit Expectations enforced this implicitly but the migrated test only verified the final RsuSnmp.sendSnmpV3Request delegation.
- SnmpConfig: add missing Javadoc class comment - TimDeleteController: reformat to 2-space indent (project standard) - TimQueryController: reformat to 2-space indent (project standard)
- TimDeleteController: add Javadoc to constructor and deleteTim, break long log line, restore license-header trailing whitespace to match master (drops empty-line JavadocParagraph noise) - TimQueryController: add ending period to bulkQuery Javadoc summary
There was a problem hiding this comment.
Pull request overview
This PR removes the legacy JMockit-based testing approach (and its Java agent) and migrates affected tests to Mockito so that JaCoCo/Sonar coverage can include the previously excluded test suite. It also introduces a small SNMP construction seam (factory injection) to replace JMockit constructor-mocking needs.
Changes:
- Removed the JMockit Maven dependency and Surefire
-javaagentconfiguration. - Migrated a large set of tests from JMockit idioms to Mockito (including static and constructor mocking).
- Refactored SNMP session creation to be injectable via new factory interfaces / Spring configuration to support Mockito-based tests.
Reviewed changes
Copilot reviewed 49 out of 49 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pom.xml | Removes JMockit dependency and its Surefire agent configuration. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimQueryControllerTest.java | Migrates TIM query controller tests from JMockit to Mockito; introduces SnmpSessionFactory mocking. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimDepositControllerTest.java | Replaces JMockit static/constructor mocking with Mockito static mocking. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimDeleteControllerTest.java | Migrates TIM delete controller tests to Mockito and adapts to SnmpSessionFactory. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/stomp/WebSocketConfigTest.java | Converts JMockit verifications to Mockito verify(...). |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/stomp/StompControllerTest.java | Migrates controller tests to Mockito + JUnit Jupiter. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/snmp/SnmpSessionTest.java | Updates SNMP session tests to Mockito; adds coverage for transport-construction failure via factory. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/rsuHealth/RsuSnmpTest.java | Migrates RSU SNMP tests to Mockito and adds interaction verification. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/rsuHealth/RsuHealthControllerTest.java | Replaces JMockit constructor/static mocking with Mockito mockConstruction/mockStatic. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/pdm/PdmUtilTest.java | Converts PDM util test to Mockito. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/pdm/PdmControllerTest.java | Migrates controller tests to Mockito static/constructor mocking for JsonUtils and SnmpSession. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/pdm/J2735PdmRequestTest.java | Removes JMockit usage; uses direct instantiation under JUnit Jupiter. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/SystemConfigTest.java | Updates assertions to JUnit Jupiter. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/OdePropertiesControllerTest.java | Migrates to Mockito + JUnit Jupiter and removes JMockit expectations. |
| jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimQueryController.java | Injects SnmpSessionFactory instead of direct new SnmpSession(...). |
| jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimDeleteController.java | Injects SnmpSessionFactory instead of direct new SnmpSession(...). |
| jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/TransportMappingFactory.java | New functional interface to abstract TransportMapping creation for testability. |
| jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpSessionFactory.java | New functional interface to abstract SnmpSession creation for controller testability. |
| jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpSession.java | Adds a transport-factory constructor to avoid constructor mocking. |
| jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpConfig.java | Registers a Spring bean providing the default SnmpSessionFactory. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/WeatherProbeBuilderTest.java | Migrates static builder stubbing to Mockito static mocking. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/VehicleSafetyExtensionsBuilderTest.java | Migrates builder static mocking to Mockito. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/TravelerMessageFromHumanToAsnConverterTest.java | Removes JMockit logger mocking setup. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/TimeStampConverterTest.java | Removes JMockit logger mocking setup; updates to JUnit Jupiter assertions. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/SupplementalVehicleExtensionsBuilderTest.java | Migrates multiple static builder stubs to Mockito static mocking. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/Position3DBuilderTest.java | Migrates static helper stubs to Mockito static mocking. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/EventDescriptionBuilderTest.java | Migrates static helper stubs to Mockito static mocking. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/BsmPart2ContentBuilderTest.java | Replaces JMockit capturing with managed Mockito static mocks and verification. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/BsmCoreDataBuilderTest.java | Replaces JMockit capturing with managed Mockito static mocks. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735VehicleStatusRequestTest.java | Removes JMockit; uses direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735TransmissionAndSpeedTest.java | Removes JMockit; updates to JUnit Jupiter assertions. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735TrailerUnitDescriptionTest.java | Removes JMockit; updates to JUnit Jupiter assertions. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735TrailerDataTest.java | Removes JMockit; uses direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735SupplementalVehicleExtensionsTest.java | Removes JMockit; uses direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735SpeedProfileTest.java | Removes JMockit; uses direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735SpecialVehicleExtensionTest.java | Removes JMockit; uses direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735RTCMPackageTest.java | Removes JMockit; uses direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735ProbeDataManagmentTest.java | Removes JMockit; uses direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735PathHistoryPointTest.java | Removes JMockit; uses direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735PathHistoryPointListTest.java | Removes JMockit; uses direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735FullPositionVectorTest.java | Removes JMockit; uses direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735EventDescriptionTest.java | Removes JMockit; uses direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735EmergencyDetailsTest.java | Removes JMockit; uses direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735ChoiceTest.java | Removes a JMockit-only exception test and updates to JUnit Jupiter assertions. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735BsmTest.java | Removes JMockit; uses direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/DdsAdvisoryDetailsTest.java | Removes JMockit instantiation; uses direct instantiation (still has some legacy imports). |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/generic/SituationDataWarehouseTest.java | Migrates to JUnit Jupiter assertions; removes JMockit. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/generic/RoadSideUnitTest.java | Migrates to JUnit Jupiter assertions; removes JMockit. |
| jpo-ode-core/src/test/java/us/dot/its/jpo/ode/snmp/SNMPTest.java | Migrates to JUnit Jupiter assertions; removes JMockit/JUnit4 patterns. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…rces Replaced manual `snmp.close()` calls with try-with-resources in `RsuHealthController` and adjusted relevant tests. Removed redundant `close()` verifications in `RsuSnmpTest` as the new approach guarantees resource cleanup.
Fixes checkstyle IndentationCheck violations flagged by reviewdog on PR #229. The try-with-resources refactor introduced 4-space indentation for the try body; Google style (basicOffset=2) requires 2 spaces per level. Reformatted the entire class for consistency and split the overlong method signature onto separate lines.
…at method Fixes missing-Javadoc and empty-line-before-tag checkstyle violations reported by the reviewdog bot on PR #229.
| Snmp snmp = new Snmp(transport); | ||
| USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0); | ||
| TransportMapping transport = new DefaultUdpTransportMapping(); | ||
| try (Snmp snmp = new Snmp(transport)) { |
There was a problem hiding this comment.
Note: I added this try-with-resources block to resolve a resource leak issue found during the test framework migration. It isn't necessary for the jmockit removal, but it is necessary to prevent resource leaks in the running application when an exception is thrown during SNMP command execution in RsuSnmp.sendSnmpV3Request
There was a problem hiding this comment.
Pull request overview
This PR removes JMockit usage across the codebase by migrating affected unit tests to Mockito (including static/construction mocking) so JaCoCo/Sonar can report coverage, and introduces a small SNMP session-construction seam to keep SNMP-related controllers testable without constructor mocking.
Changes:
- Removed the JMockit dependency and Surefire
-javaagentconfiguration from the rootpom.xml. - Rewrote a large set of tests from JMockit idioms to Mockito/JUnit 5 idioms.
- Updated SNMP-related production code to inject
SnmpSessioncreation via aSnmpSessionFactory, and added supporting factory/config types.
Reviewed changes
Copilot reviewed 51 out of 51 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pom.xml | Removes JMockit dependency and Surefire javaagent configuration. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimQueryControllerTest.java | Migrates TIM query controller tests from JMockit to Mockito. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimDepositControllerTest.java | Migrates TIM deposit controller tests to Mockito static mocking. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/traveler/TimDeleteControllerTest.java | Migrates TIM delete controller tests to Mockito with injected factory. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/stomp/WebSocketConfigTest.java | Replaces JMockit verifications with Mockito verify calls. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/stomp/StompControllerTest.java | Migrates to Mockito extension + JUnit 5 assertions. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/snmp/SnmpSessionTest.java | Updates SNMP session tests to use a transport factory seam instead of constructor mocking. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/rsuHealth/RsuSnmpTest.java | Migrates RSU SNMP unit tests from JMockit to Mockito. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/rsuHealth/RsuHealthControllerTest.java | Migrates heartbeat tests using Mockito static/construction mocking. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/pdm/PdmUtilTest.java | Migrates PDM util tests to Mockito. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/pdm/PdmControllerTest.java | Migrates PDM controller tests using Mockito static/construction mocking. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/pdm/J2735PdmRequestTest.java | Removes JMockit @Tested usage; uses direct construction. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/SystemConfigTest.java | Converts assertions to JUnit 5 style. |
| jpo-ode-svcs/src/test/java/us/dot/its/jpo/ode/OdePropertiesControllerTest.java | Migrates to Mockito extension + stubbing for properties. |
| jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimQueryController.java | Injects SnmpSessionFactory and uses it for session creation. |
| jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/traveler/TimDeleteController.java | Injects SnmpSessionFactory and uses it for session creation. |
| jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/TransportMappingFactory.java | Adds a transport factory interface to enable constructor-failure testing. |
| jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpSessionFactory.java | Adds a session factory interface for injection/testing. |
| jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpSession.java | Adds constructor overload using TransportMappingFactory. |
| jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/snmp/SnmpConfig.java | Provides a Spring bean for SnmpSessionFactory. |
| jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/heartbeat/RsuSnmp.java | Stops closing Snmp inside helper (caller now owns lifecycle). |
| jpo-ode-svcs/src/main/java/us/dot/its/jpo/ode/heartbeat/RsuHealthController.java | Uses try-with-resources to manage Snmp lifecycle and adds docs. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/WeatherProbeBuilderTest.java | Migrates static builder mocking to Mockito mockStatic. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/VehicleSafetyExtensionsBuilderTest.java | Migrates static builder mocking and updates assertion style. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/TravelerMessageFromHumanToAsnConverterTest.java | Removes logger mocking previously done with JMockit. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/TimeStampConverterTest.java | Removes JMockit logger mocking and updates assertions. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/SupplementalVehicleExtensionsBuilderTest.java | Migrates multiple static builder mocks to Mockito. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/Position3DBuilderTest.java | Migrates static builder mocking to Mockito and updates assertions. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/EventDescriptionBuilderTest.java | Migrates static CodecUtils mocking and updates assertion ordering. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/BsmPart2ContentBuilderTest.java | Reworks capturing/verifications into Mockito static mocks + verify. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/builders/BsmCoreDataBuilderTest.java | Adds lifecycle-managed Mockito static mocks for collaborating builders. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735VehicleStatusRequestTest.java | Replaces JMockit @Tested with direct instantiation and JUnit 5 assertions. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735TransmissionAndSpeedTest.java | Normalizes header formatting and uses JUnit 5 assertions. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735TrailerUnitDescriptionTest.java | Replaces JMockit @Tested with direct instantiation and JUnit 5 assertions. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735TrailerDataTest.java | Replaces JMockit @Tested with direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735SupplementalVehicleExtensionsTest.java | Replaces JMockit @Tested with direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735SpeedProfileTest.java | Replaces JMockit @Tested with direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735SpecialVehicleExtensionTest.java | Replaces JMockit @Tested with direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735RTCMPackageTest.java | Replaces JMockit @Tested with direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735ProbeDataManagmentTest.java | Replaces JMockit @Tested with direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735PathHistoryPointTest.java | Replaces JMockit @Tested with direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735PathHistoryPointListTest.java | Replaces JMockit @Tested with direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735FullPositionVectorTest.java | Replaces JMockit @Tested with direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735EventDescriptionTest.java | Replaces JMockit @Tested with direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735EmergencyDetailsTest.java | Replaces JMockit @Tested with direct instantiation. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735ChoiceTest.java | Removes a JMockit-based exception test that depended on mocking logging internals. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/J2735BsmTest.java | Replaces JMockit mocking with direct instantiation + JUnit 5 assertions. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/j2735/DdsAdvisoryDetailsTest.java | Removes JMockit @Tested usage while keeping test behavior. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/generic/SituationDataWarehouseTest.java | Replaces JMockit @Tested with direct instantiation and JUnit 5 assertions. |
| jpo-ode-plugins/src/test/java/us/dot/its/jpo/ode/plugin/generic/RoadSideUnitTest.java | Migrates to JUnit 5 assertions and removes JMockit @Tested. |
| jpo-ode-core/src/test/java/us/dot/its/jpo/ode/snmp/SNMPTest.java | Updates to JUnit 5 assertions and removes unused JMockit/JUnit4 annotations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| ResponseEvent responseEvent; | ||
| try { | ||
| responseEvent = snmp.send(pdu, target); | ||
| snmp.close(); |
There was a problem hiding this comment.
note: this was removed as the try-with-resources block we added in RsuHealthController now manages the lifecycle of the SNMP resource in both success and error conditions
PR Details
Description
This pull request removes JMockit from the project entirely and migrates every test that used it to Mockito, the mocking framework that ships with Spring Boot Test by default. The JMockit Maven dependency and its
-javaagentSurefire argument are deleted, and roughly forty test classes acrossjpo-ode-svcs,jpo-ode-core,jpo-ode-plugins, andjpo-ode-commonhave been rewritten to use Mockito idioms (@Mock,@InjectMocks,when(...).thenReturn(...),verify(...),mockStatic,mockConstruction).A small production change was needed to make one class testable without JMockit's constructor mocking:
SnmpSessionnow receives itsSnmpandTransportMappingcollaborators through newSnmpSessionFactoryandTransportMappingFactorySpring beans rather than constructing them directly. Two pre-existing tests that depended on JMockit's ability to mock unmockable third-party constructs (a logger field and anIOExceptionthrown from a final method) have been removed because they cannot be expressed in Mockito, and the scenarios they covered are not reachable through the public API.Related Issue
N/A.
Motivation and Context
JMockit has not had a meaningful release in years, and its bytecode-rewriting Java agent is incompatible with the JaCoCo agent that SonarCloud relies on for coverage. As long as JMockit was on the classpath, any test it touched was excluded from our SonarCloud coverage numbers, resulting in an artificially low and misleading coverage signal. Moving these tests to Mockito both removes a dead dependency and makes the affected code visible again in coverage analysis. Mockito is already a transitive dependency of
spring-boot-starter-test, so this change reduces our dependency footprint rather than expanding it.How Has This Been Tested?
The full Maven test suite (
mvn clean verify) was run locally and passed. CI runs the same suite on every push to this branch.Types of changes
Checklist:
ODE Contributing Guide