1f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beustpackage test.assertion;
2f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beust
3f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beustimport org.testng.annotations.BeforeMethod;
4f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beustimport org.testng.annotations.Test;
5f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beustimport org.testng.asserts.LoggingAssert;
6f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beust
76abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herrimport static org.assertj.core.api.Assertions.assertThat;
86abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr
9f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beustpublic class AssertionTest {
10f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beust  private LoggingAssert m_assert;
116abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr  private MyRawAssertion rawAssertion;
12f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beust
13f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beust  @BeforeMethod
14f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beust  public void bm() {
15f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beust    m_assert = new LoggingAssert();
166abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr    rawAssertion = new MyRawAssertion();
17f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beust  }
18f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beust
19f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beust  @Test(expectedExceptions = AssertionError.class)
20f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beust  public void test1() {
21f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beust    m_assert.assertTrue(false, "new TestNG Assertion Failed");
22f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beust  }
236abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr
246abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr  @Test
256abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr  public void test2() {
266abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr    rawAssertion.assertTrue(true);
276abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr    rawAssertion.myAssert("test", true, "Raw test");
286abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr
296abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr    assertThat(rawAssertion.getMethods())
306abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr        .containsExactly("onBeforeAssert", "onAssertSuccess", "onAfterAssert",
316abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr                         "onBeforeAssert", "onAssertSuccess", "onAfterAssert");
326abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr  }
336abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr
346abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr  @Test(expectedExceptions = AssertionError.class, expectedExceptionsMessageRegExp = "Raw test .*")
356abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr  public void test2_fails() {
366abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr    try {
376abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr      rawAssertion.assertTrue(true);
386abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr      rawAssertion.myAssert("test", false, "Raw test");
396abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr    } catch (AssertionError error) {
406abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr
416abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr      assertThat(rawAssertion.getMethods())
426abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr          .containsExactly("onBeforeAssert", "onAssertSuccess", "onAfterAssert",
436abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr                           "onBeforeAssert", "onAssertFailure", "deprecated_onAssertFailure", "onAfterAssert");
446abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr
456abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr      throw error;
466abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr    }
476abfe244ee3f6ce3a4c02bb4105383f570c85277Julien Herr  }
48f35367c2f0ff22815b04fb0d97733ff2b56bbb7aCédric Beust}
49