Skip to content
loading...

MockitoでClassオブジェクトを返す

twitter logo github logo ・1 min read  

MockitoでClassオブジェクトを返すメソッドをモック化しようとした。

Foo foo = mock(Foo.class);
when(foo.getBar()).thenReturn(Bar.class);

が、以下のエラーが発生。

The method thenReturn(Class<capture#1-of ?>) in the type OngoingStubbing<Class<capture#1-of ?>> is not applicable for the arguments (Class<capture#3-of ?>)

doReturnを使うことで解決。

doReturn(Bar.class).when(foo).getBar();
twitter logo DISCUSS
Classic DEV Post from Jul 2 '19

How Personal Projects Make You A Better Developer

Sometimes it's hard to see the point of working on personal projects since it's just for you. If you feel this way, you are missing out on A LOT of benefits. Learn why you should always be working on a personal project.

Kentama7 profile image