Supported Features - effiban/scala2javaext-mockito GitHub Wiki
When deployed, the extension will be automatically enabled for any source file which includes an import starting with org.mockito.
Mockito is commonly used together with JUnit, along with the custom library mockito-junit-jupiter.
Specifically a JUnit test will typically be annotated with @ExtendWith(MockitoExtension.class) to support automatic processing of Mockito annotations.
The extension anticipates this, and will automatically add the annotation above to any class in the source file.
While this is done without any validation, it has a minor impact and can be easily removed if unneeded.
The extension should correctly process most of the language elements related to mocks, spies and captors.
Examples:
| Scala | Java | Comment |
|---|---|---|
import org.mockito.MockitoSugar.mock |
import org.mockito.Mockito.mock; |
|
class MyTest extends MockitoSugar {} |
public class MyTest {} |
|
val foo = mock[Foo] |
@MockFoo foo;
|
class member only |
val foo = mock[Foo] |
var foo = mock(Foo.class); |
|
val foo = spy(new Foo()) |
@SpyFoo foo = new Foo();
|
class member only |
def createFooSpy() = spy[Foo](aFoo) |
Foo createFooSpy() { return spy(aFoo); } |
|
val fooCaptor = ArgCaptor[Foo] |
@CaptorArgumentCaptor<Foo> foo;
|
class member only |
val fooCaptor = ArgCaptor[Foo] |
var fooCaptor = ArgumentCaptor.forClass(Foo.class); |
The extension should correctly process most of the language elements related to the common argument matchers (not all are supported).
Examples:
| Scala | Java | Comment |
|---|---|---|
import org.mockito.ArgumentMatchersSugar.any |
import org.mockito.ArgumentMatchers.any; |
|
when(a.b(eqTo(c)) |
when(a.b(eq(c))) |
|
when(a.b(any[C])) |
when(a.b(any(C.class))) |
|
when(a.b(anyList[C])) |
when(a.b(any(List<C>.class))) |
Due to a known issue with the core tool - the extra generics remain |