1package test.assertion; 2 3import org.testng.annotations.BeforeMethod; 4import org.testng.annotations.Test; 5import org.testng.asserts.LoggingAssert; 6 7import static org.assertj.core.api.Assertions.assertThat; 8 9public class AssertionTest { 10 private LoggingAssert m_assert; 11 private MyRawAssertion rawAssertion; 12 13 @BeforeMethod 14 public void bm() { 15 m_assert = new LoggingAssert(); 16 rawAssertion = new MyRawAssertion(); 17 } 18 19 @Test(expectedExceptions = AssertionError.class) 20 public void test1() { 21 m_assert.assertTrue(false, "new TestNG Assertion Failed"); 22 } 23 24 @Test 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 .*") 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