source: java2python/mockito-t/test/testcode/MockitoBasicTest.java@ 1014

Last change on this file since 1014 was 1014, checked in by wouter, 4 months ago

#303 added test showing that ArgumentMatchers.eq() is not translated properly

File size: 1.2 KB
Line 
1package testcode;
2
3import static org.junit.Assert.assertEquals;
4import static org.mockito.ArgumentMatchers.eq;
5import static org.mockito.Mockito.mock;
6import static org.mockito.Mockito.when;
7
8import org.junit.Test;
9import org.junit.internal.runners.JUnit4ClassRunner;
10import org.junit.runner.RunWith;
11
12class TestClass {
13 public int f(int x) {
14 return x + 1;
15 }
16}
17
18/**
19 * Test for mockito translator. This program is going to be translated and run
20 * in python.
21 */
22@RunWith(JUnit4ClassRunner.class)
23public class MockitoBasicTest {
24
25 /**
26 * NOTE NO CONSTRUCTOR. This is needed to check that the proper constructor,
27 * matching in this case the implicit superclass TestCase from Python, is
28 * created. This is a special case, in normal cases java already enforces
29 * all required code including the call to super().
30 */
31
32 @Test
33 public void testStub1() {
34 TestClass test = mock(TestClass.class);
35 when(test.f(3)).thenReturn(1);
36 // the mock did not do any when.thenReturn and should fail
37 assertEquals(1, test.f(3));
38
39 }
40
41 @Test
42 public void testEqMatcher() {
43 TestClass test = mock(TestClass.class);
44 when(test.f(eq(3))).thenReturn(1);
45 assertEquals(1, test.f(3));
46 }
47
48}
Note: See TracBrowser for help on using the repository browser.