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

Last change on this file since 1011 was 1011, checked in by wouter, 3 months ago

#343 improved the when() translator. Not perfect but more robust

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