mockito常用句式

when(i.next()).thenReturn("Hello").thenReturn("World");

when(c.compareTo("Test")).thenReturn(1);

when(c.compareTo(anyInt())).thenReturn(-1);

doThrow(new IOException()).when(mock).close();

 

verify:确认某个方法被调用过

verify(mock).close();

verify(mock).write(argThat(arrayStartingWithA), eq(0),eq(1));   

 

参考链接:http://gojko.net/2009/10/23/mockito-in-six-easy-examples/

posted @ 2013-03-21 13:10  mongg  阅读(218)  评论(0编辑  收藏  举报