forked from CodeOpsTech/DesignPatternsJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMockByteCodeTests.java
More file actions
37 lines (35 loc) · 983 Bytes
/
Copy pathMockByteCodeTests.java
File metadata and controls
37 lines (35 loc) · 983 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
import static org.mockito.Mockito.*;
import static org.junit.Assert.*;
import java.util.List;
import org.junit.*;
import java.util.*;
public class MockByteCodeTest {
private ByteCode byteCode = mock(ByteCode.class);
private Stack<Integer> execStack = new Stack<>();
@Test
public void checkByteCode() {
assertTrue(byteCode instanceof ByteCode);
}
@Test
public void checkByteCodeDefaultInit() {
assertEquals(0, byteCode.exec(execStack));
}
@Test
public void checkByteCodeMockExecMethod() {
when(byteCode.exec(execStack)).thenReturn(10);
assertEquals(10, byteCode.exec(execStack));
}
@Test
public void mockBIPUSHByteCode() {
BIPUSH bipush10 = new BIPUSH(10);
when(bipush10.exec(execStack)).thenReturn(10);
assertEquals(10, byteCode.exec(execStack));
}
@Test
public void mockIADDByteCode() {
BIPUSH bipush10 = new BIPUSH(10);
BIPUSH bipush20 = new BIPUSH(20);
IADD iadd = new IADD();
assertEquals(10, byteCode.exec(execStack));
}
}