View Javadoc
1   /*
2    * MIT License
3    * Copyright (c) 2006-2025 JMockit developers
4    * See LICENSE file for full license text.
5    */
6   package otherTests.testng;
7   
8   import static org.testng.Assert.assertEquals;
9   import static org.testng.Assert.assertNull;
10  
11  import mockit.Mock;
12  import mockit.MockUp;
13  
14  import org.testng.IHookCallBack;
15  import org.testng.IHookable;
16  import org.testng.ITestResult;
17  import org.testng.annotations.AfterMethod;
18  import org.testng.annotations.BeforeMethod;
19  
20  public class BaseTestNGDecoratorTest implements IHookable {
21      // Makes sure TestNG integration works with test classes which implement IHookable.
22      @Override
23      public void run(IHookCallBack callBack, ITestResult testResult) {
24          callBack.runTestMethod(testResult);
25      }
26  
27      // Lightweight test-only class to be mocked.
28      public static class SimpleComponent {
29          public String getInfo() {
30              return null;
31          }
32      }
33  
34      public static class FakeClass1 extends MockUp<SimpleComponent> {
35          @Mock
36          public String getInfo() {
37              return "TEST1";
38          }
39      }
40  
41      @BeforeMethod
42      public final void beforeBase() {
43          assertNull(new SimpleComponent().getInfo());
44          new FakeClass1();
45          assertEquals(new SimpleComponent().getInfo(), "TEST1");
46      }
47  
48      @AfterMethod
49      public final void afterBase() {
50          assertEquals(new SimpleComponent().getInfo(), "TEST1");
51      }
52  }