Upgrade Mockito from 1.x to 3.x

MSAL

Upgrade Mockito from 1.x to 3.x.

org.openrewrite.java.testing.mockito.Mockito1to3Migration
mod run . --recipe=org.openrewrite.java.testing.mockito.Mockito1to3Migration

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.

Recipe list

It runs these recipes, in this order.

  1. Change type org.mockito.MockitoAnnotations.Mock to org.mockito.Mock
  2. Replace Mockito 1.x anyString()/any() with nullable(Class)
  3. Change type Matchers to ArgumentMatchers
  4. Convert ArgumentMatcher<T> anonymous class to lambda
  5. Change method name org.mockito.* anyVararg() to any
  6. Change method name org.mockito.* anyObject() to any
  7. Delete method argument 0 in methods org.mockito.* anyListOf(java.lang.Class)
  8. Change method name org.mockito.* anyListOf() to anyList
  9. Delete method argument 0 in methods org.mockito.* anySetOf(java.lang.Class)
  10. Change method name org.mockito.* anySetOf() to anySet
  11. Delete method argument 0 in methods org.mockito.* anyMapOf(java.lang.Class, java.lang.Class)
  12. Delete method argument 0 in methods org.mockito.* anyMapOf(java.lang.Class)
  13. Change method name org.mockito.* anyMapOf() to anyMap
  14. Delete method argument 0 in methods org.mockito.* anyCollectionOf(java.lang.Class)
  15. Change method name org.mockito.* anyCollectionOf() to anyCollection
  16. Delete method argument 0 in methods org.mockito.* anyIterableOf(java.lang.Class)
  17. Change method name org.mockito.* anyIterableOf() to anyIterable
  18. Delete method argument 0 in methods org.mockito.* isNull(java.lang.Class)
  19. Delete method argument 0 in methods org.mockito.* notNull(java.lang.Class)
  20. Reorder method arguments
  21. Replace verifyZeroInteractions() with verifyNoMoreInteractions()
  22. Change method name org.mockito.Mockito verifyZeroInteractions(..) to verifyNoInteractions
  23. Change method name org.mockito.invocation.InvocationOnMock getArgumentAt(int, java.lang.Class) to getArgument
  24. Change type TooLittleActualInvocations to TooFewActualInvocations
  25. Change type org.mockito.configuration.AnnotationEngine to org.mockito.plugins.AnnotationEngine
  26. Change type InstantiatorProvider to InstantiatorProvider2
  27. Change type org.mockito.runners.MockitoJUnitRunner to org.mockito.junit.MockitoJUnitRunner
  28. Replace undeclared checked exceptions in thenThrow with RuntimeException
  29. Cleanup Mockito imports
  30. Use static form of Mockito MockUtil
  31. Replace PowerMock with raw Mockito
  32. JUnit 4 MockitoJUnit to JUnit Jupiter MockitoExtension
  33. Add @MockitoSettings(strictness = Strictness.WARN) for legacy Mockito modules
  34. Replace MockitoTestExecutionListener (JUnit Jupiter projects)
  35. Replace MockitoTestExecutionListener (JUnit 4 projects)
  36. Replace MockitoTestExecutionListener (TestNG projects)
  37. Remove MockitoAnnotations.initMocks(this) and openMocks(this) if JUnit runners specified
  38. Remove doNothing() for void methods on @Mock fields
  39. Change Gradle or Maven dependency org.mockito:mockito-all
  40. Upgrade Gradle or Maven dependency versions org.mockito:*:3.x
  41. Change Gradle or Maven dependency org.mockito:mockito-all
  42. Upgrade Gradle or Maven dependency versions net.bytebuddy:byte-buddy*:1.11.13
  43. Upgrade Byte Buddy along with Mockito 3