/* 109: */ /* 110: */ private static Description makeDescription(Test test) /* 111: */ { /* 112: 96 */ if ((test instanceof TestCase)) /* 113: */ { /* 114: 97 */ TestCase tc = (TestCase) test; /* 115: 98 */ return Description.createTestDescription(tc.getClass(), tc.getName()); /* 116: */ } /* 117: 99 */ if ((test instanceof TestSuite)) /* 118: */ { /* 119:100 */ TestSuite ts = (TestSuite) test; /* 120:101 */ String name = ts.getName() == null ? createSuiteDescription(ts) : ts.getName(); /* 121:102 */ Description description = Description.createSuiteDescription(name, new Annotation[0]); /* 122:103 */ int n = ts.testCount(); /* 123:104 */ for (int i = 0; i < n; i++) /* 124: */ { /* 125:105 */ Description made = makeDescription(ts.testAt(i)); /* 126:106 */ description.addChild(made); /* 127: */ } /* 128:108 */ return description; /* 129: */ } /* 130:109 */ if ((test instanceof Describable)) /* 131: */ { /* 132:110 */ Describable adapter = (Describable) test; /* 133:111 */ return adapter.getDescription(); /* 134: */ } /* 135:112 */ if ((test instanceof TestDecorator)) /* 136: */ { /* 137:113 */ TestDecorator decorator = (TestDecorator) test; /* 138:114 */ return makeDescription(decorator.getTest()); /* 139: */ } /* 140:117 */ return Description.createSuiteDescription(test.getClass()); /* 141: */ }
/* 142: */ /* 143: */ private static String createSuiteDescription(TestSuite ts) /* 144: */ { /* 145:122 */ int count = ts.countTestCases(); /* 146:123 */ String example = count == 0 ? "" : String.format(" [example: %s]", new Object[] {ts.testAt(0)}); /* 147:124 */ return String.format( "TestSuite with %s tests%s", new Object[] {Integer.valueOf(count), example}); /* 148: */ }
private static Description makeDescription(Test test) { if (test instanceof TestCase) { TestCase tc = (TestCase) test; return Description.createTestDescription(tc.getClass(), tc.getName(), getAnnotations(tc)); } else if (test instanceof TestSuite) { TestSuite ts = (TestSuite) test; String name = ts.getName() == null ? createSuiteDescription(ts) : ts.getName(); Description description = Description.createSuiteDescription(name); int n = ts.testCount(); for (int i = 0; i < n; i++) { Description made = makeDescription(ts.testAt(i)); description.addChild(made); } return description; } else if (test instanceof Describable) { Describable adapter = (Describable) test; return adapter.getDescription(); } else if (test instanceof TestDecorator) { TestDecorator decorator = (TestDecorator) test; return makeDescription(decorator.getTest()); } else { // This is the best we can do in this case return Description.createSuiteDescription(test.getClass()); } }
/** * Copies non-distributed test suite into distributed one. * * @param suite Test suite to copy. */ public GridJunit3TestSuite(TestSuite suite) { super(suite.getName()); if (copy == null) { copy = new TestSuite(suite.getName()); } for (int i = 0; i < suite.testCount(); i++) { addTest(suite.testAt(i)); } }
/** * @param suite Test suite to wrap. * @param factory Proxy factory. */ GridJunit3TestSuiteProxy(TestSuite suite, GridJunit3ProxyFactory factory) { assert suite != null; assert factory != null; original = suite; setName(suite.getName()); this.factory = factory; for (int i = 0; i < suite.testCount(); i++) { addTest(suite.testAt(i)); } }
public void filter(Filter filter) throws NoTestsRemainException { if (getTest() instanceof Filterable) { Filterable adapter = (Filterable) getTest(); adapter.filter(filter); } else if (getTest() instanceof TestSuite) { TestSuite suite = (TestSuite) getTest(); TestSuite filtered = new TestSuite(suite.getName()); int n = suite.testCount(); for (int i = 0; i < n; i++) { Test test = suite.testAt(i); if (filter.shouldRun(makeDescription(test))) { filtered.addTest(test); } } setTest(filtered); } }
/** * Handles test fail. * * @param result Test result. * @param origTest Original JUnit test. * @param e Exception thrown from grid. */ private void handleFail(TestResult result, GridJunit3SerializableTest origTest, Throwable e) { // Simulate that all tests were run. origTest.getTest().run(result); // For the tests suite we assume that all tests failed because // entire test suite execution failed and there is no way to get // broken tests. if (origTest.getTest() instanceof GridJunit3TestSuiteProxy) { TestSuite suite = (((TestSuite) origTest.getTest())); for (int j = 0; j < suite.testCount(); j++) { result.addError(suite.testAt(j), e); } } else if (origTest.getTest() instanceof GridJunit3TestCaseProxy) { result.addError(origTest.getTest(), e); } }
/* 149: */ /* 150: */ public void filter(Filter filter) /* 151: */ throws NoTestsRemainException /* 152: */ { /* 153:128 */ if ((getTest() instanceof Filterable)) /* 154: */ { /* 155:129 */ Filterable adapter = (Filterable) getTest(); /* 156:130 */ adapter.filter(filter); /* 157: */ } /* 158:131 */ else if ((getTest() instanceof TestSuite)) /* 159: */ { /* 160:132 */ TestSuite suite = (TestSuite) getTest(); /* 161:133 */ TestSuite filtered = new TestSuite(suite.getName()); /* 162:134 */ int n = suite.testCount(); /* 163:135 */ for (int i = 0; i < n; i++) /* 164: */ { /* 165:136 */ Test test = suite.testAt(i); /* 166:137 */ if (filter.shouldRun(makeDescription(test))) { /* 167:138 */ filtered.addTest(test); /* 168: */ } /* 169: */ } /* 170:140 */ setTest(filtered); /* 171: */ } /* 172: */ }
private static String createSuiteDescription(TestSuite ts) { int count = ts.countTestCases(); String example = count == 0 ? "" : String.format(" [example: %s]", ts.testAt(0)); return String.format("TestSuite with %s tests%s", count, example); }
/** {@inheritDoc} */ @Override public Test testAt(int index) { return isDisabled ? copy.testAt(index) : super.testAt(index); }