-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestIM.java
More file actions
37 lines (30 loc) · 928 Bytes
/
testIM.java
File metadata and controls
37 lines (30 loc) · 928 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package mockito;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import org.junit.*;
public class testIM {
public I mock1;
@Before
public void setup() throws Exception{
mock1 = mock(I.class);
when(mock1.methodeInt()).thenReturn(1,2,3,4);
doThrow(new IndexOutOfBoundsException("truc")).when(mock1).methodeVoid();
when(mock1.methodParam(3)).thenReturn(3);
when(mock1.methodParam(5)).thenReturn(10);
}
@Test
public void test() throws Exception{
//assertEquals(mock1.methodeInt(),0);
assertEquals(mock1.methodParam(3),3);
assertEquals(mock1.methodParam(5),10);
assertEquals(mock1.methodParam(0),0);
for (int i=0;i<4;i++) mock1.methodeInt();
verify(mock1,times(4)).methodeInt();
try{mock1.methodeVoid();}
catch (IndexOutOfBoundsException e){
System.out.println("test"+ e);
assertTrue(e.toString().contains("Index"));
assertTrue(e.getMessage().contains("truc"));
}
}
}