2016-11-18 5 views
0

anyList()/anyListOf(Class<T>)isNull()マッチャーの対応はありますか?以下のコードスニペットを使って、これも可能ですか、それとも間違っていますか?Mockito matcher:anyListに対応するisNull

@Mock private Calling calling; 

@Test 
public void test() { 
    final Object VALUE_ONE = new Object(); 
    final Object VALUE_TWO = null; 

    when(calling.read(any(), anyList(), anyList)).thenReturn(VALUE_ONE); 

    // Should be 
    // when(calling.read(any(), anyList(), isNull())).thenReturn(VALUE_TWO); 
    when(calling.read(any(), anyList(), anyList)).thenReturn(VALUE_TWO); 

    TestClass resposne = TestHelper.read(calling, 1l); 
    ... 
} 
+0

のisNull引数マッチャがあります:http://static.javadoc.io/org.mockito/mockito-core/2.2が。 19/org/mockito/ArgumentMatchers.html#ヌル引数に一致するように設計されたisNull() – sprinter

答えて

0

あなたはMockitoでこのようにそれを書くことができます。..

Mockito.when(mo.read(Mockito.any(), Mockito.anyList(), Mockito.eq(null))).thenReturn(VALUE_ONE); 
関連する問題