2013-02-22 23 views
6

org.mockito.AdditionalMatchersの仕組みを理解しようとしていますが、失敗しました。なぜこのテストは失敗しますか?org.mockito.AdditionalMatchers.gtの使用方法を教えてください。

import static org.hamcrest.CoreMatchers.is; 
import static org.junit.Assert.*; 
import static org.mockito.AdditionalMatchers.*; 

public class DemoTest { 

    @Test 
    public void testGreaterThan() throws Exception { 

     assertThat(17 
      , is(gt(10)) 
     ); 
    } 
} 

出力は次のとおりです。

java.lang.AssertionError: 
Expected: is <0> 
    got: <17> 

答えて

6

あなたはこのような場合のためにHamcrestのgreaterThanを使用する必要があります。 gtは、モックオブジェクトのメソッド呼び出しの引数を検証するためのものです。

public class DemoTest { 

    private List<Integer> list = Mockito.mock(List.class); 

    @Test 
    public void testGreaterThan() throws Exception { 
     assertThat(17, is(org.hamcrest.Matchers.greaterThan(10))); 

     list.add(17); 
     verify(list).add(org.mockito.AdditionalMatchers.gt(10)); 
    } 

} 
関連する問題