1
2
3
4
5
6 package otherTests.testng;
7
8 import static org.testng.Assert.assertNotNull;
9 import static org.testng.Assert.assertNull;
10
11 import mockit.Expectations;
12 import mockit.Mocked;
13
14 import org.testng.ITestContext;
15 import org.testng.annotations.Test;
16
17 public final class TestNGCascadingTest {
18 static class Foo {
19 Bar getBar() {
20 return null;
21 }
22 }
23
24 static class Bar {
25 String getValue() {
26 return null;
27 }
28 }
29
30 @Mocked
31 Foo foo;
32
33 @Test
34 public void useExpectationResultRecordedOnCascadedInstance(ITestContext ctx) {
35 new Expectations() {
36 {
37 foo.getBar().getValue();
38 result = "test";
39 }
40 };
41
42 String value = foo.getBar().getValue();
43
44 assertNotNull(value);
45 }
46
47 @Test
48 public void getUnrecordedResultFromCascadedInstance() {
49 String value = foo.getBar().getValue();
50
51 assertNull(value);
52 }
53 }