Test for interleaving factories.


diff --git a/test/src/test/factory/FactoryInterleavingSampleA.java b/test/src/test/factory/FactoryInterleavingSampleA.java
new file mode 100644
index 0000000..f21ecda
--- /dev/null
+++ b/test/src/test/factory/FactoryInterleavingSampleA.java
@@ -0,0 +1,44 @@
+package test.factory;
+
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class FactoryInterleavingSampleA {
+  public int m_n;
+
+  public FactoryInterleavingSampleA(int n) {
+    m_n = n;
+  }
+
+  private void log(Integer s) {
+    FactoryInterleavingTest.LOG.add(m_n * 10 + s);
+//    System.out.println(" Instance " + m_n + " " + s);
+  }
+
+  @Override
+  public String toString() {
+    return "[A n:" + m_n + "]";
+  }
+
+  @BeforeClass
+  public void bc() {
+    log(0);
+  }
+
+  @AfterClass
+  public void ac() {
+    log(3);
+  }
+
+  @Test
+  public void f1() {
+    log(1);
+  }
+
+  @Test
+  public void f2() {
+    log(2);
+  }
+
+}
diff --git a/test/src/test/factory/FactoryInterleavingSampleFactory.java b/test/src/test/factory/FactoryInterleavingSampleFactory.java
new file mode 100644
index 0000000..84a7580
--- /dev/null
+++ b/test/src/test/factory/FactoryInterleavingSampleFactory.java
@@ -0,0 +1,19 @@
+package test.factory;
+
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Factory;
+
+public class FactoryInterleavingSampleFactory {
+  @Factory
+  public Object[] factory() {
+    return new Object[] {
+        new FactoryInterleavingSampleA(1), new FactoryInterleavingSampleA(2)
+    };
+  }
+
+  @BeforeClass
+  public void beforeB() {
+    System.out.println("Before B");
+  }
+}
+
diff --git a/test/src/test/factory/FactoryInterleavingTest.java b/test/src/test/factory/FactoryInterleavingTest.java
new file mode 100644
index 0000000..e800fc3
--- /dev/null
+++ b/test/src/test/factory/FactoryInterleavingTest.java
@@ -0,0 +1,33 @@
+package test.factory;
+
+import org.testng.Assert;
+import org.testng.TestNG;
+import org.testng.annotations.Test;
+import org.testng.collections.Lists;
+
+import test.SimpleBaseTest;
+
+import java.util.Arrays;
+import java.util.List;
+
+public class FactoryInterleavingTest extends SimpleBaseTest {
+
+  public static List<Integer> LOG = Lists.newArrayList();
+
+  @Test
+  public void methodsShouldBeInterleaved() {
+    TestNG tng = create(FactoryInterleavingSampleFactory.class);
+    tng.run();
+    Integer[] valid1 = {
+        10, 11, 12, 13,
+        20, 21, 22, 23,
+    };
+
+    Integer[] valid2 = {
+        20, 21, 22, 23,
+        10, 11, 12, 13,
+    };
+    Integer[] logArray = LOG.toArray(new Integer[LOG.size()]);
+    Assert.assertTrue(Arrays.equals(logArray, valid1) || Arrays.equals(logArray, valid2));
+  }
+}