[testng] 280/355: Add test

Eugene Zhukov eugene-guest at moszumanska.debian.org
Tue Aug 18 10:20:15 UTC 2015


This is an automated email from the git hooks/post-receive script.

eugene-guest pushed a commit to annotated tag OpenBSD
in repository testng.

commit 6abfe244ee3f6ce3a4c02bb4105383f570c85277
Author: Julien Herr <julien.herr at alcatel-lucent.com>
Date:   Fri May 8 08:51:11 2015 +0200

    Add test
---
 src/test/java/test/assertion/AssertionTest.java  | 29 ++++++++++
 src/test/java/test/assertion/MyRawAssertion.java | 72 ++++++++++++++++++++++++
 2 files changed, 101 insertions(+)

diff --git a/src/test/java/test/assertion/AssertionTest.java b/src/test/java/test/assertion/AssertionTest.java
index 4633ead..bf6f3b8 100644
--- a/src/test/java/test/assertion/AssertionTest.java
+++ b/src/test/java/test/assertion/AssertionTest.java
@@ -4,16 +4,45 @@ import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.Test;
 import org.testng.asserts.LoggingAssert;
 
+import static org.assertj.core.api.Assertions.assertThat;
+
 public class AssertionTest {
   private LoggingAssert m_assert;
+  private MyRawAssertion rawAssertion;
 
   @BeforeMethod
   public void bm() {
     m_assert = new LoggingAssert();
+    rawAssertion = new MyRawAssertion();
   }
 
   @Test(expectedExceptions = AssertionError.class)
   public void test1() {
     m_assert.assertTrue(false, "new TestNG Assertion Failed");
   }
+
+  @Test
+  public void test2() {
+    rawAssertion.assertTrue(true);
+    rawAssertion.myAssert("test", true, "Raw test");
+
+    assertThat(rawAssertion.getMethods())
+        .containsExactly("onBeforeAssert", "onAssertSuccess", "onAfterAssert",
+                         "onBeforeAssert", "onAssertSuccess", "onAfterAssert");
+  }
+
+  @Test(expectedExceptions = AssertionError.class, expectedExceptionsMessageRegExp = "Raw test .*")
+  public void test2_fails() {
+    try {
+      rawAssertion.assertTrue(true);
+      rawAssertion.myAssert("test", false, "Raw test");
+    } catch (AssertionError error) {
+
+      assertThat(rawAssertion.getMethods())
+          .containsExactly("onBeforeAssert", "onAssertSuccess", "onAfterAssert",
+                           "onBeforeAssert", "onAssertFailure", "deprecated_onAssertFailure", "onAfterAssert");
+
+      throw error;
+    }
+  }
 }
diff --git a/src/test/java/test/assertion/MyRawAssertion.java b/src/test/java/test/assertion/MyRawAssertion.java
new file mode 100644
index 0000000..0f35db2
--- /dev/null
+++ b/src/test/java/test/assertion/MyRawAssertion.java
@@ -0,0 +1,72 @@
+package test.assertion;
+
+import org.testng.Assert;
+import org.testng.asserts.Assertion;
+import org.testng.asserts.IAssert;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class MyRawAssertion extends Assertion {
+
+  private final List<String> methods = new ArrayList<>();
+
+  @Override
+  public void onAssertSuccess(IAssert assertCommand) {
+    methods.add("onAssertSuccess");
+    super.onAssertSuccess(assertCommand);
+  }
+
+  @Override
+  public void onAssertFailure(IAssert assertCommand) {
+    methods.add("deprecated_onAssertFailure");
+    super.onAssertFailure(assertCommand);
+  }
+
+  @Override
+  public void onAssertFailure(IAssert assertCommand, AssertionError ex) {
+    methods.add("onAssertFailure");
+    super.onAssertFailure(assertCommand, ex);
+  }
+
+  @Override
+  public void onBeforeAssert(IAssert assertCommand) {
+    methods.add("onBeforeAssert");
+    super.onBeforeAssert(assertCommand);
+  }
+
+  @Override
+  public void onAfterAssert(IAssert assertCommand) {
+    methods.add("onAfterAssert");
+    super.onAfterAssert(assertCommand);
+  }
+
+  public List<String> getMethods() {
+    return methods;
+  }
+
+  public void myAssert(final String actual, final boolean expected, final String message) {
+    doAssert(new IAssert() {
+      @Override
+      public String getMessage() {
+        return message;
+      }
+
+      @Override
+      public void doAssert() {
+        Assert.assertNotNull(actual, message);
+        Assert.assertTrue(expected, message);
+      }
+
+      @Override
+      public Object getActual() {
+        return actual;
+      }
+
+      @Override
+      public Object getExpected() {
+        return expected;
+      }
+    });
+  }
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/testng.git



More information about the pkg-java-commits mailing list