[testng] 245/355: Add test for #87

Eugene Zhukov eugene-guest at moszumanska.debian.org
Tue Aug 18 10:20:11 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 ab2ef973c0fd57b426be40a26a7e9f40b86e3b5d
Author: Julien Herr <julien.herr at alcatel-lucent.com>
Date:   Thu Apr 30 13:02:59 2015 +0200

    Add test for #87
---
 src/main/java/org/testng/TestRunner.java           |  2 +-
 .../java/org/testng/internal/BaseClassFinder.java  |  2 +-
 .../java/org/testng/internal/ClassInfoMap.java     |  2 +-
 src/test/java/test/invokedmethodlistener/A.java    |  9 ++++++++
 src/test/java/test/invokedmethodlistener/B.java    | 13 +++++++++++
 src/test/java/test/invokedmethodlistener/C.java    | 13 +++++++++++
 .../InvokedMethodListener.java                     |  5 +++-
 .../InvokedMethodListenerTest.java                 | 27 ++++++++++++++++++++--
 8 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/testng/TestRunner.java b/src/main/java/org/testng/TestRunner.java
index 2772445..45b4621 100644
--- a/src/main/java/org/testng/TestRunner.java
+++ b/src/main/java/org/testng/TestRunner.java
@@ -100,7 +100,7 @@ public class TestRunner
   private Date m_endDate = null;
 
   /** A map to keep track of Class <-> IClass. */
-  transient private Map<Class<?>, ITestClass> m_classMap = Maps.newHashMap();
+  transient private Map<Class<?>, ITestClass> m_classMap = Maps.newLinkedHashMap(); // Changed to reproduce issue #87 (order is important)
 
   /** Where the reports will be created. */
   private String m_outputDirectory= Constants.getDefaultValueFor(Constants.PROP_OUTPUT_DIR);
diff --git a/src/main/java/org/testng/internal/BaseClassFinder.java b/src/main/java/org/testng/internal/BaseClassFinder.java
index 90ac311..1247dbe 100755
--- a/src/main/java/org/testng/internal/BaseClassFinder.java
+++ b/src/main/java/org/testng/internal/BaseClassFinder.java
@@ -17,7 +17,7 @@ import java.util.Map;
  * @author <a href="mailto:cedric at beust.com">Cedric Beust</a>
  */
 abstract public class BaseClassFinder implements ITestClassFinder {
-  private Map<Class, IClass> m_classes = Maps.newHashMap();
+  private Map<Class, IClass> m_classes = Maps.newLinkedHashMap(); // Changed to reproduce issue #87 (order is important)
 
   @Override
   public IClass getIClass(Class cls) {
diff --git a/src/main/java/org/testng/internal/ClassInfoMap.java b/src/main/java/org/testng/internal/ClassInfoMap.java
index b57a03f..50a17f4 100644
--- a/src/main/java/org/testng/internal/ClassInfoMap.java
+++ b/src/main/java/org/testng/internal/ClassInfoMap.java
@@ -8,7 +8,7 @@ import java.util.Map;
 import java.util.Set;
 
 public class ClassInfoMap {
-  private Map<Class<?>, XmlClass> m_map = Maps.newHashMap();
+  private Map<Class<?>, XmlClass> m_map = Maps.newLinkedHashMap(); // Changed to reproduce issue #87 (order is important)
   private boolean includeNestedClasses;
 
   public ClassInfoMap() {
diff --git a/src/test/java/test/invokedmethodlistener/A.java b/src/test/java/test/invokedmethodlistener/A.java
new file mode 100644
index 0000000..24fadc3
--- /dev/null
+++ b/src/test/java/test/invokedmethodlistener/A.java
@@ -0,0 +1,9 @@
+package test.invokedmethodlistener;
+
+import org.testng.annotations.BeforeSuite;
+
+public class A {
+
+  @BeforeSuite(alwaysRun=false)
+  public static void someMethod1() {}
+}
diff --git a/src/test/java/test/invokedmethodlistener/B.java b/src/test/java/test/invokedmethodlistener/B.java
new file mode 100644
index 0000000..8f2eb36
--- /dev/null
+++ b/src/test/java/test/invokedmethodlistener/B.java
@@ -0,0 +1,13 @@
+package test.invokedmethodlistener;
+
+import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.Test;
+
+ at Test(enabled=false)
+public class B extends A{
+
+  @BeforeSuite
+  public static void someMethod2() {}
+
+  public void someTest() {}
+}
diff --git a/src/test/java/test/invokedmethodlistener/C.java b/src/test/java/test/invokedmethodlistener/C.java
new file mode 100644
index 0000000..335ba00
--- /dev/null
+++ b/src/test/java/test/invokedmethodlistener/C.java
@@ -0,0 +1,13 @@
+package test.invokedmethodlistener;
+
+import org.testng.annotations.BeforeSuite;
+import org.testng.annotations.Test;
+
+ at Test
+public class C extends A{
+
+  @BeforeSuite
+  public static void someMethod3() {}
+
+  public void someTest() {}
+}
diff --git a/src/test/java/test/invokedmethodlistener/InvokedMethodListener.java b/src/test/java/test/invokedmethodlistener/InvokedMethodListener.java
index c9a0f7e..e25014a 100644
--- a/src/test/java/test/invokedmethodlistener/InvokedMethodListener.java
+++ b/src/test/java/test/invokedmethodlistener/InvokedMethodListener.java
@@ -9,7 +9,7 @@ import java.util.List;
 
 public class InvokedMethodListener implements IInvokedMethodListener {
 
-  public static List<IInvokedMethod> m_methods = Lists.newArrayList();
+  private final List<IInvokedMethod> m_methods = Lists.newArrayList();
 
   @Override
   public void beforeInvocation(IInvokedMethod method, ITestResult testResult) {
@@ -20,4 +20,7 @@ public class InvokedMethodListener implements IInvokedMethodListener {
   public void afterInvocation(IInvokedMethod method, ITestResult testResult) {
   }
 
+  public List<IInvokedMethod> getInvokedMethods() {
+    return m_methods;
+  }
 }
diff --git a/src/test/java/test/invokedmethodlistener/InvokedMethodListenerTest.java b/src/test/java/test/invokedmethodlistener/InvokedMethodListenerTest.java
index e687aef..232e32b 100644
--- a/src/test/java/test/invokedmethodlistener/InvokedMethodListenerTest.java
+++ b/src/test/java/test/invokedmethodlistener/InvokedMethodListenerTest.java
@@ -56,9 +56,10 @@ public class InvokedMethodListenerTest extends SimpleBaseTest {
   @Test
   public void sameMethodInvokedMultipleTimesShouldHaveDifferentTimeStamps() {
     TestNG tng = create(Sample.class);
-    tng.addListener(new InvokedMethodListener());
+    InvokedMethodListener listener = new InvokedMethodListener();
+    tng.addListener(listener);
     tng.run();
-    List<IInvokedMethod> m = InvokedMethodListener.m_methods;
+    List<IInvokedMethod> m = listener.getInvokedMethods();
     IInvokedMethod beforeSuite = m.get(0);
     Assert.assertFalse(beforeSuite.getTestMethod().isAfterMethodConfiguration());
     Assert.assertTrue(beforeSuite.isConfigurationMethod());
@@ -113,4 +114,26 @@ public class InvokedMethodListenerTest extends SimpleBaseTest {
     Assert.assertTrue(l.configurationMethodsFromTM.contains("beforeSuite"));
     Assert.assertTrue(l.configurationMethodsFromTM.contains("afterSuite"));
   }
+
+  @Test
+  public void issue87_method_orderning_with_disable_test_class() {
+    assertIssue87(A.class, B.class, C.class);
+    assertIssue87(A.class, C.class, B.class);
+    assertIssue87(B.class, A.class, C.class);
+  }
+
+  private void assertIssue87(Class<?>... tests) {
+    TestNG tng = create(tests);
+    tng.setVerbose(10);
+    tng.setParallel("false");
+    tng.setPreserveOrder(true);
+    InvokedMethodListener listener = new InvokedMethodListener();
+    tng.addListener(listener);
+    tng.run();
+    List<IInvokedMethod> m = listener.getInvokedMethods();
+    Assert.assertEquals(m.get(0).getTestMethod().getMethodName(), "someMethod1");
+    Assert.assertEquals(m.get(1).getTestMethod().getMethodName(), "someMethod3");
+    Assert.assertEquals(m.get(2).getTestMethod().getMethodName(), "someTest");
+    Assert.assertEquals(m.size(), 3);
+  }
 }

-- 
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