1 package test.assertion;
2 
3 import org.testng.Assert;
4 import org.testng.asserts.Assertion;
5 import org.testng.asserts.IAssert;
6 
7 import java.util.ArrayList;
8 import java.util.List;
9 
10 public class MyRawAssertion extends Assertion {
11 
12   private final List<String> methods = new ArrayList<>();
13 
14   @Override
onAssertSuccess(IAssert assertCommand)15   public void onAssertSuccess(IAssert assertCommand) {
16     methods.add("onAssertSuccess");
17     super.onAssertSuccess(assertCommand);
18   }
19 
20   @Override
onAssertFailure(IAssert assertCommand)21   public void onAssertFailure(IAssert assertCommand) {
22     methods.add("deprecated_onAssertFailure");
23     super.onAssertFailure(assertCommand);
24   }
25 
26   @Override
onAssertFailure(IAssert assertCommand, AssertionError ex)27   public void onAssertFailure(IAssert assertCommand, AssertionError ex) {
28     methods.add("onAssertFailure");
29     super.onAssertFailure(assertCommand, ex);
30   }
31 
32   @Override
onBeforeAssert(IAssert assertCommand)33   public void onBeforeAssert(IAssert assertCommand) {
34     methods.add("onBeforeAssert");
35     super.onBeforeAssert(assertCommand);
36   }
37 
38   @Override
onAfterAssert(IAssert assertCommand)39   public void onAfterAssert(IAssert assertCommand) {
40     methods.add("onAfterAssert");
41     super.onAfterAssert(assertCommand);
42   }
43 
getMethods()44   public List<String> getMethods() {
45     return methods;
46   }
47 
myAssert(final String actual, final boolean expected, final String message)48   public void myAssert(final String actual, final boolean expected, final String message) {
49     doAssert(new IAssert() {
50       @Override
51       public String getMessage() {
52         return message;
53       }
54 
55       @Override
56       public void doAssert() {
57         Assert.assertNotNull(actual, message);
58         Assert.assertTrue(expected, message);
59       }
60 
61       @Override
62       public Object getActual() {
63         return actual;
64       }
65 
66       @Override
67       public Object getExpected() {
68         return expected;
69       }
70     });
71   }
72 }
73