1 package test.assertion;
2 
3 import org.testng.annotations.BeforeMethod;
4 import org.testng.annotations.Test;
5 import org.testng.asserts.LoggingAssert;
6 
7 import static org.assertj.core.api.Assertions.assertThat;
8 
9 public class AssertionTest {
10   private LoggingAssert m_assert;
11   private MyRawAssertion rawAssertion;
12 
13   @BeforeMethod
bm()14   public void bm() {
15     m_assert = new LoggingAssert();
16     rawAssertion = new MyRawAssertion();
17   }
18 
19   @Test(expectedExceptions = AssertionError.class)
test1()20   public void test1() {
21     m_assert.assertTrue(false, "new TestNG Assertion Failed");
22   }
23 
24   @Test
test2()25   public void test2() {
26     rawAssertion.assertTrue(true);
27     rawAssertion.myAssert("test", true, "Raw test");
28 
29     assertThat(rawAssertion.getMethods())
30         .containsExactly("onBeforeAssert", "onAssertSuccess", "onAfterAssert",
31                          "onBeforeAssert", "onAssertSuccess", "onAfterAssert");
32   }
33 
34   @Test(expectedExceptions = AssertionError.class, expectedExceptionsMessageRegExp = "Raw test .*")
test2_fails()35   public void test2_fails() {
36     try {
37       rawAssertion.assertTrue(true);
38       rawAssertion.myAssert("test", false, "Raw test");
39     } catch (AssertionError error) {
40 
41       assertThat(rawAssertion.getMethods())
42           .containsExactly("onBeforeAssert", "onAssertSuccess", "onAfterAssert",
43                            "onBeforeAssert", "onAssertFailure", "deprecated_onAssertFailure", "onAfterAssert");
44 
45       throw error;
46     }
47   }
48 }
49