/** * Generates a test case verifying that calling any waitForXxx method when not occupying the * monitor produces an IllegalMonitorStateException. */ private static TestCase generateWaitForWhenNotOccupyingTestCase( final Method method, final boolean fair) { final boolean timed = isTimed(method); // Not going to bother with all timeouts, just 0ms. String testName = method.getName() + (fair ? "(fair)" : "(nonfair)") + (timed ? "(0ms)" : "()") + "/NotOccupying->IMSE"; return new TestCase(testName) { @Override protected void runTest() throws Throwable { Monitor monitor = new Monitor(fair); FlagGuard guard = new FlagGuard(monitor); Object[] arguments = (timed ? new Object[] {guard, 0L, TimeUnit.MILLISECONDS} : new Object[] {guard}); try { method.invoke(monitor, arguments); fail("expected IllegalMonitorStateException"); } catch (InvocationTargetException e) { assertEquals(IllegalMonitorStateException.class, e.getTargetException().getClass()); } } }; }
final Method method, final boolean fair1, final boolean fair2) { final boolean timed = isTimed(method); // Not going to bother with all timeouts, just 0ms. return new TestCase(method.getName() + (timed ? "(0ms)" : "()") + "/WrongMonitor->IMSE") { @Override protected void runTest() throws Throwable {
protected static Test error(final String message) { return new TestCase("error") { protected void runTest() { fail(message); } }; }
// Set is looking for tc2 and finds object with same ref, because of previous set.add(tc2); System.out.println(set.add(tc2));//fails and gives us false. // You create new object with new reference. tc2 = new TestCase(4, 8); // Yes, because you changed tc2 variable and assigned new reference to it. System.out.println(set.add(tc2));//succeeds and gives us true?
public class Grid { Browser browser = new Browser(); TestCase testCase = new TestCase(); public Grid() { ...
public static Test suite() { if (isDebugClassTestable()) { return new TestSuite(DebugTest.class); } else { return new TestCase(DebugTest.class.getName()) { @Override public void runTest() { System.out.println(DebugTest.class + ": test will not be performed: Debug.DEBUG == false"); } }; } }
public static Test suite() { if (DDDB.isInstalled()) { return new TestSuite(DDDBTest.class); } else { return new TestCase(DDDBTest.class.getName()) { @Override public void runTest() { System.out.println(); System.out.println(DDDBTest.class + ": warning: test will not be performed: DDDB not installed: "); System.out.println(DDDB.DB_DIR_PATH); } }; } }
/** * Generates a test case verifying that calling any waitForXxx method when not occupying the * monitor produces an IllegalMonitorStateException. */ private static TestCase generateWaitForWhenNotOccupyingTestCase(final Method method, final boolean fair) { final boolean timed = isTimed(method); // Not going to bother with all timeouts, just 0ms. String testName = method.getName() + (fair ? "(fair)" : "(nonfair)") + (timed ? "(0ms)" : "()") + "/NotOccupying->IMSE"; return new TestCase(testName) { @Override protected void runTest() throws Throwable { Monitor monitor = new Monitor(fair); FlagGuard guard = new FlagGuard(monitor); Object[] arguments = (timed ? new Object[] {guard, 0L, TimeUnit.MILLISECONDS} : new Object[] {guard}); try { method.invoke(monitor, arguments); fail("expected IllegalMonitorStateException"); } catch (InvocationTargetException e) { assertEquals(IllegalMonitorStateException.class, e.getTargetException().getClass()); } } }; }
private static void addGenericTests(TestSuite suite, final String processorName, final Class<? extends TransformerFactory> transformerFactoryClass) { for (final Class sbf : sourceBuilderFactories) { for (final Class rbf : resultBuilderFactories) { String testName = "test" + processorName + shortName(sbf) + shortName(rbf); suite.addTest(new TestCase(testName) { @Override public void runTest() throws Throwable { String oldTransformerFactory = TransformerFactory.newInstance().getClass().getName(); System.setProperty(TransformerFactory.class.getName(), transformerFactoryClass.getName()); test(sbf, rbf); System.setProperty(TransformerFactory.class.getName(), oldTransformerFactory); } }); } } }
final boolean fair2) { final boolean timed = isTimed(method); // Not going to bother with all timeouts, just 0ms. return new TestCase(method.getName() + (timed ? "(0ms)" : "()") + "/WrongMonitor->IMSE") { @Override protected void runTest() throws Throwable { Monitor monitor1 = new Monitor(fair1);