use of com.sun.tck.test.TestCase in project jtharness by openjdk.
the class TestAfter method afterWasCalled.
@Test
public void afterWasCalled() {
final boolean[] afterCalled = new boolean[1];
final boolean[] methodCalled = new boolean[1];
final int[] counter = new int[] { 0 };
final int[] afterCounter = new int[] { 0 };
com.oracle.tck.lib.autd2.TestResult status = com.oracle.tck.lib.autd2.unittests.TU.runTestGroup(new TestAfter.Mytest() {
private void myAfter() {
org.junit.Assert.assertTrue(methodCalled[0]);
afterCalled[0] = true;
afterCounter[0]++;
}
// this is optional
@TestCase
@TestData("setup")
@com.sun.tck.lib.tgf.After("myAfter")
public void test(int i) {
org.junit.Assert.assertFalse(afterCalled[0]);
methodCalled[0] = true;
counter[0]++;
}
}, TU.EMPTY_ARGV);
assertTrue(status.isOK());
assertTrue(afterCalled[0]);
assertTrue(methodCalled[0]);
assertEquals(3, counter[0]);
assertEquals(1, afterCounter[0]);
Assert.assertEquals("Passed. test cases: 1; all passed", status.toString());
}
use of com.sun.tck.test.TestCase in project jtharness by openjdk.
the class TestAfter method afterOfNonVoidTypeWasCalled_NoParams.
@Test
public void afterOfNonVoidTypeWasCalled_NoParams() {
final boolean[] afterCalled = new boolean[1];
final boolean[] methodCalled = new boolean[1];
final int[] counter = new int[] { 0 };
final int[] afterCounter = new int[] { 0 };
com.oracle.tck.lib.autd2.TestResult status = com.oracle.tck.lib.autd2.unittests.TU.runTestGroup(new TestAfter.Mytest() {
private Class myAfter() {
org.junit.Assert.assertTrue(methodCalled[0]);
afterCalled[0] = true;
afterCounter[0]++;
return Runtime.class;
}
@TestCase
@com.sun.tck.lib.tgf.After("myAfter")
public void test() {
org.junit.Assert.assertFalse(afterCalled[0]);
methodCalled[0] = true;
counter[0]++;
}
}, TU.EMPTY_ARGV);
assertTrue(status.isOK());
assertTrue(afterCalled[0]);
assertTrue(methodCalled[0]);
assertEquals(1, counter[0]);
assertEquals(1, afterCounter[0]);
}
use of com.sun.tck.test.TestCase in project jtharness by openjdk.
the class TestAfter method ifTestThrowsExceptionAfterIsNotCalled.
@Test
public void ifTestThrowsExceptionAfterIsNotCalled() {
final boolean[] afterCalled = new boolean[1];
final boolean[] methodCalled = new boolean[1];
final int[] counter = new int[] { 0 };
final int[] afterCounter = new int[] { 0 };
com.oracle.tck.lib.autd2.TestResult status = com.oracle.tck.lib.autd2.unittests.TU.runTestGroup(new TestAfter.Mytest() {
private void myAfter() {
org.junit.Assert.assertTrue(methodCalled[0]);
afterCalled[0] = true;
afterCounter[0]++;
}
@TestCase
@TestData("setup")
@com.sun.tck.lib.tgf.After("myAfter")
public void test(int i) {
org.junit.Assert.assertFalse(afterCalled[0]);
methodCalled[0] = true;
counter[0]++;
throw new RuntimeException("Thrown from test");
}
}, TU.EMPTY_ARGV);
assertFalse(status.isOK());
assertTrue(afterCalled[0]);
assertTrue(methodCalled[0]);
assertEquals(3, counter[0]);
assertEquals(1, afterCounter[0]);
}
use of com.sun.tck.test.TestCase in project jtharness by openjdk.
the class TestAfter method afterNotFound.
@Test
public void afterNotFound() {
PrintWriter log = TU.createMockedPrintWriter();
PrintWriter ref = TU.createMockedPrintWriter();
final boolean[] methodCalled = new boolean[1];
final int[] counter = new int[] { 0 };
TestResult status = TU.runTestGroup(new TestAfter.Mytest() {
protected Values mySetup() {
return DataFactory.createColumn(1, 2, 3);
}
@TestCase
@TestData("mySetup")
@com.sun.tck.lib.tgf.After("myAfterThatDoesnotExist")
public void test(int i) {
methodCalled[0] = true;
counter[0]++;
}
}, log, ref, TU.EMPTY_ARGV);
assertTrue(!status.isOK());
assertTrue(methodCalled[0]);
assertEquals(3, counter[0]);
InOrder inOrder = inOrder(log, ref);
inOrder.verify(log).println("Method \"myAfterThatDoesnotExist\" doesn't exist.");
inOrder.verify(log).println("test: Failed. Failed trying to invoke @After method \"myAfterThatDoesnotExist\"");
inOrder.verify(log).flush();
inOrder.verify(ref).flush();
verifyNoMoreInteractions(log, ref);
}
use of com.sun.tck.test.TestCase in project jtharness by openjdk.
the class TestAfter method runtimeSkippingFromAfter_testFails.
@Test
public void runtimeSkippingFromAfter_testFails() {
com.oracle.tck.lib.autd2.TestResult status = com.oracle.tck.lib.autd2.unittests.TU.runTestGroup(new TestAfter.Mytest() {
protected Values mySetup() {
return DataFactory.createColumn(1, 2, 3);
}
private void myAfter() {
com.sun.tck.lib.Assert.reportNotApplicable(true);
}
@TestCase
@TestData("mySetup")
@com.sun.tck.lib.tgf.After("myAfter")
public void test(int i) {
Assert.fail("Failed!!!");
}
}, TU.EMPTY_ARGV);
assertTrue(status.isOK());
assertEquals("test cases: 1; all not applicable", status.getMessage());
}
Aggregations