Quick revision
The short answer
I would first assess: count the tests per library and per module, list the features they use, such as constructor and static mocking, partial mocks and strict expectations, and find which tests break on Java 25. Then I would migrate JMockit first, because it blocks the JDK upgrade, and leave working EasyMock tests for later. Automated recipes such as OpenRewrite's do the bulk of the mechanical conversion, people fix the rest, static and constructor mocking becomes mockStatic and mockConstruction or, better, injected dependencies, and the work goes module by module with both libraries side by side and a visible count of remaining legacy tests.
What to remember
In this answer, we planned a migration of 6,000 JMockit and EasyMock tests to Mockito. We assessed usage and ran the suite on Java 25, migrated JMockit first because it blocks the upgrade, used OpenRewrite recipes for the mechanical part and fixed the rest by hand, translated static and constructor mocking to mockStatic and mockConstruction or replaced it with injected dependencies, and moved module by module with both libraries side by side and a count of remaining legacy tests.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
I would first assess: count the tests per library and per module, list the features they use, such as constructor and static mocking, partial mocks and strict expectations, and find which tests break on Java 25. Then I would migrate JMockit first, because it blocks the JDK upgrade, and leave working EasyMock tests for later. Automated recipes such as OpenRewrite's do the bulk of the mechanical conversion, people fix the rest, static and constructor mocking becomes mockStatic and mockConstruction or, better, injected dependencies, and the work goes module by module with both libraries side by side and a visible count of remaining legacy tests.
Why this question is asked
Six thousand tests is too many to rewrite by hand in one go and too valuable to delete. A migration like this competes with feature work, so it must be planned to keep the build green every day and to deliver the JDK upgrade as early as possible. Interviewers ask this scenario to see how we break a large technical change into safe, measurable steps. In this answer, we will start with the assessment, decide the order, see how automated conversion and manual fixes divide the work, look at the hardest translations with code, and finish with how the migration runs module by module.
1Assess What We Actually Have
Before choosing tools, we need numbers. A few hours of scripting over the code base gives most of them: grep for imports of mockit. (JMockit) and org.easymock. (EasyMock) per module, then count the test classes and methods. For JMockit, we also count the features used, because they differ a lot in how hard they are to convert: Expectations and Verifications blocks, @Mocked and @Injectable fields, partial mocking, MockUp<T> fakes (which replace methods of real classes, including statics and constructors), and strict expectation ordering.
Then we run the suite on Java 25 in a branch. That shows which tests actually break, which is often fewer than all JMockit tests at first but enough to block the upgrade. The result might look like the table below.
| Library and feature | Tests | Breaks on Java 25 |
|---|---|---|
JMockit, plain @Mocked and Expectations | 1,800 | yes, agent fails |
JMockit, MockUp on statics and constructors | 700 | yes |
| JMockit, partial mocks of real classes | 300 | yes |
EasyMock, default and nice mocks | 2,700 | no |
EasyMock, strict mocks with call order | 500 | no |
2Decide the Order
The assessment answers the ordering question. JMockit runs as a Java agent that depends on JVM internals, and it is the library failing on Java 25, so its 2,800 tests are on the critical path of the upgrade. EasyMock works on the new JDK, so its 3,200 tests can wait: they cost nothing to keep, and migrating them is a quality improvement we can schedule later, or do only when tests are touched.
This order matters because it delivers value early. Converting the JMockit tests first unblocks Java 25 for the whole system, which is the business reason the migration exists. If we started with the easier EasyMock tests to build momentum, we would spend weeks without moving the upgrade at all.
3Automate the Mechanical Part
Much of the conversion is mechanical: changing imports, turning @Mocked fields into @Mock, turning an Expectations block with a result into when().thenReturn(), turning Verifications into verify(). OpenRewrite, a tool that applies automated refactoring recipes to source code, has recipes for migrating JMockit and EasyMock to Mockito. We should check how much of our usage they cover, because coverage of advanced features varies by recipe version.
We run the recipe on one module first, compile, run the tests, and sort the results into three groups: converted and passing, converted but failing, and not converted. That tells us how much manual work each module will need.
Notice one semantic difference the recipe cannot judge for us. JMockit expectations are, by default, also checked: if repo.find(7L) is never called, the test fails. Mockito's strict stubs mode with MockitoExtension gives a similar safety net by reporting unused stubs, so we run the converted tests with the extension to keep that behaviour.
4Translate the Hard Cases by Hand
The tests the recipe cannot convert are mostly the powerful JMockit features. Static methods and constructors replaced with MockUp have direct Mockito equivalents, mockStatic and mockConstruction, both active only inside a try-with-resources block on the current thread.
The direct translation keeps the test working, and for 700 tests it may be the right first step. But each MockUp of a static or a constructor marks a place where the code creates or reaches for its own dependency. Where the class is still being developed, the better fix is to inject a Clock or the client and drop the static mocking entirely, which also removes the dependency on bytecode agents that caused the problem in the first place.
Partial mocks of real classes become Mockito spies, with doReturn().when(spy) for the stubbed methods. Strict ordering in JMockit or EasyMock becomes InOrder, but only where the order is a real requirement; often the strictness was incidental and can be dropped.
5Migrate Module by Module
We do not convert 6,000 tests in one pull request. Both libraries stay on the test classpath during the transition, so converted and unconverted tests run side by side, and every module is migrated in its own small pull requests that keep the build green. The order follows dependency and risk: shared libraries first, then services with the most JMockit tests.
A dashboard shows the count of remaining JMockit and EasyMock tests per module, and a build check prevents new tests from importing the legacy libraries. Once JMockit reaches zero, we remove its agent from the build and switch the JDK to 25. EasyMock then continues on a slower schedule, converted when tests are touched or in quiet periods, until it too can be removed.
- Assess usage and run on Java 25counts, features, breaking tests
- Block new legacy importsbuild check
- Run OpenRewrite per modulesort: passing, failing, not converted
- Fix the rest by hand
mockStatic, spies, or inject the dependency - JMockit count at zero?YesRemove its agent, upgrade to Java 25NoNext module
- Convert EasyMock when touchedremove it when the count reaches zero
6 steps in order. Play them, or step through them one at a time.
6Follow-up questions
Why not keep JMockit and pin the JDK?
Because staying on an old JDK blocks security updates and new language features for the whole system, and JMockit is unlikely to catch up reliably. The migration cost is finite; the cost of being stuck grows every year.
How do you know the converted tests still test the same thing?
Run both versions on the old JDK before deleting the original, and for critical modules use mutation testing to compare how many mutants each version kills. A drop shows where a conversion weakened a test.
What if some tests are not worth converting?
Some legacy tests only mirror the implementation. If a test has no clear behaviour to check, it can be replaced with a better test or deleted, after agreement with the owning team and with coverage and mutation checks.
7Conclusion
In this answer, we planned a migration of 6,000 JMockit and EasyMock tests to Mockito. We assessed usage and ran the suite on Java 25, migrated JMockit first because it blocks the upgrade, used OpenRewrite recipes for the mechanical part and fixed the rest by hand, translated static and constructor mocking to mockStatic and mockConstruction or replaced it with injected dependencies, and moved module by module with both libraries side by side and a count of remaining legacy tests.
Open with
I would start with an assessment: count tests per library and module, list the JMockit and EasyMock features in use, such as Expectations, MockUp for statics and constructors, partial mocks and strict ordering, and run the suite on Java 25 in a branch to see what actually breaks.
Then, if they want more
JMockit is the blocker, because it runs as an agent that depends on JVM internals, so I would migrate it first; EasyMock still works and can wait.
For the conversion I would use OpenRewrite's recipes for JMockit and EasyMock to Mockito, after checking how much of our usage they cover, run them per module and sort the results into passing, failing and not converted. The rest is manual.
MockUp of statics and constructors becomes mockStatic and mockConstruction inside try-with-resources, but where the code is still evolving I would rather inject a Clock or the client and drop the static mocking. Partial mocks become spies, and strict ordering becomes InOrder only where order really matters.
I would keep both libraries during the transition, migrate module by module in small green pull requests, block new legacy imports, track the remaining count, and upgrade the JDK as soon as JMockit reaches zero.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 25
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- JUnit user guide, Mockito documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A legacy project has 6,000 tests using JMockit and EasyMock, and the upgrade to Java 25...": https://scrivio-interview-library.netlify.app/java/mocking/558fa4dabe/