001: package test.confordering;
002:
003: import java.util.ArrayList;
004: import java.util.List;
005:
006: import org.testng.Assert;
007: import org.testng.TestNG;
008:
009: import test.confordering.subpckg1.Parent;
010: import test.confordering.subpckg2.NonOverriddingChild;
011: import test.confordering.subpckg2.OverriddingChild;
012: import test.confordering.subpckg2.SimpleOverriddingChild;
013:
014: import testhelper.OutputDirectoryPatch;
015:
016: public class ConfigurationMethodOrderingTest {
017: public static List LOG;
018:
019: /**
020: * @testng.test
021: */
022: public void checkConfOrderInInheritanceWithNoOverrides() {
023: LOG = new ArrayList();
024: TestNG tng = new TestNG();
025: tng.setOutputDirectory(OutputDirectoryPatch
026: .getOutputDirectory());
027: tng.setTestClasses(new Class[] { NonOverriddingChild.class });
028: tng.setVerbose(1);
029: tng.run();
030: System.out.println("[[NonOverriddingChild]]:" + LOG.toString());
031:
032: assertIsBefore(LOG, "parentBeforeTestClass",
033: "childBeforeTestClass");
034: assertIsBefore(LOG, "parentInheritBeforeTestClass",
035: "childBeforeTestClass");
036: assertIsBefore(LOG, "parentBeforeTestMethod",
037: "childBeforeTestMethod");
038: assertIsBefore(LOG, "parentInheritBeforeTestMethod",
039: "childBeforeTestMethod");
040: assertIsAfter(LOG, "parentAfterTestMethod",
041: "childAfterTestMethod");
042: assertIsAfter(LOG, "parentInheritAfterTestMethod",
043: "childAfterTestMethod");
044: assertIsAfter(LOG, "parentInheritAfterTestClass",
045: "childAfterTestClass");
046: assertIsAfter(LOG, "parentAfterTestClass",
047: "childAfterTestClass");
048: }
049:
050: /**
051: * @testng.test
052: */
053: public void checkConfOrderInInheritanceWithSimpleOverrides() {
054: LOG = new ArrayList();
055: TestNG tng = new TestNG();
056: tng.setOutputDirectory(OutputDirectoryPatch
057: .getOutputDirectory());
058: tng
059: .setTestClasses(new Class[] { SimpleOverriddingChild.class });
060: tng.setVerbose(1);
061: tng.run();
062: System.out.println("[[SimpleOverriddingChild]]:"
063: + LOG.toString());
064:
065: assertIsBefore(LOG, "parentBeforeTestClass",
066: "childBeforeTestClass");
067: assertIsBefore(LOG, "parentBeforeTestClass",
068: "childInheritBeforeTestClass");
069: assertIsBefore(LOG, "parentBeforeTestMethod",
070: "childBeforeTestMethod");
071: assertIsBefore(LOG, "parentBeforeTestMethod",
072: "childInheritBeforeTestMethod");
073: assertIsAfter(LOG, "parentAfterTestMethod",
074: "childAfterTestMethod");
075: assertIsAfter(LOG, "parentAfterTestMethod",
076: "childInheritAfterTestMethod");
077: assertIsAfter(LOG, "parentAfterTestClass",
078: "childInheritAfterTestClass");
079: assertIsAfter(LOG, "parentAfterTestClass",
080: "childAfterTestClass");
081: }
082:
083: /**
084: * @testng.test
085: */
086: public void checkConfOrderInInheritanceWithFullOverrides() {
087: LOG = new ArrayList();
088: TestNG tng = new TestNG();
089: tng.setOutputDirectory(OutputDirectoryPatch
090: .getOutputDirectory());
091: tng.setTestClasses(new Class[] { OverriddingChild.class });
092: tng.setVerbose(1);
093: tng.run();
094: System.out.println("[[OverriddingChild]]:" + LOG.toString());
095:
096: assertIsBefore(LOG, "parentBeforeTestClass",
097: "childBeforeTestClass");
098: assertIsBefore(LOG, "parentBeforeTestClass",
099: "childInheritBeforeTestClass");
100: assertIsBefore(LOG, "parentBeforeTestMethod",
101: "childBeforeTestMethod");
102: assertIsBefore(LOG, "parentBeforeTestMethod",
103: "childInheritBeforeTestMethod");
104: assertIsAfter(LOG, "parentAfterTestMethod",
105: "childAfterTestMethod");
106: assertIsAfter(LOG, "parentAfterTestMethod",
107: "childInheritAfterTestMethod");
108: assertIsAfter(LOG, "parentAfterTestClass",
109: "childInheritAfterTestClass");
110: assertIsAfter(LOG, "parentAfterTestClass",
111: "childAfterTestClass");
112: }
113:
114: private void assertIsBefore(List list, final String first,
115: final String second) {
116: int firstIdx = list.indexOf(first);
117: int secondIdx = list.indexOf(second);
118:
119: Assert.assertTrue(firstIdx != -1, "<" + first
120: + "> should be in the list");
121: Assert.assertTrue(secondIdx != -1, "<" + second
122: + "> should be in the list");
123: Assert.assertTrue(firstIdx < secondIdx, "<" + first
124: + "> should be before <" + second + ">");
125: }
126:
127: private void assertIsAfter(List list, final String second,
128: final String first) {
129: assertIsBefore(list, first, second);
130: }
131: }
|