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