Search in sources :

Example 16 with TestCase

use of com.sun.tck.test.TestCase in project jtharness by openjdk.

the class TestBefore method beforeNotFound.

@Test
public void beforeNotFound() {
    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 Mytest() {

        @TestCase
        @TestData("setup")
        @com.sun.tck.lib.tgf.Before("myBeforeThatDoesNotExist")
        public void test(int i) {
            methodCalled[0] = true;
            counter[0]++;
        }
    }, log, ref, TU.EMPTY_ARGV);
    assertFalse(status.isOK());
    assertFalse(methodCalled[0]);
    assertEquals(0, counter[0]);
    Assert.assertEquals("Failed. test cases: 1; all failed", status.toString());
    InOrder inOrder = inOrder(log, ref);
    inOrder.verify(log).println("Method \"myBeforeThatDoesNotExist\" doesn't exist.");
    inOrder.verify(log).println("test: Failed. Failed trying to invoke @Before method \"myBeforeThatDoesNotExist\"");
    inOrder.verify(log).flush();
    inOrder.verify(ref).flush();
    verifyNoMoreInteractions(log, ref);
}
Also used : InOrder(org.mockito.InOrder) TestCase(com.sun.tck.test.TestCase) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 17 with TestCase

use of com.sun.tck.test.TestCase in project jtharness by openjdk.

the class TestBefore method beforeIsBeforeValuesInitialization.

@Test
public void beforeIsBeforeValuesInitialization() {
    final boolean[] beforeCalled = new boolean[1];
    final boolean[] valuesInited = new boolean[1];
    com.oracle.tck.lib.autd2.TestResult status = com.oracle.tck.lib.autd2.unittests.TU.runTestGroup(new BaseTestGroup() {

        Object[] objects() {
            valuesInited[0] = true;
            return new Object[] { new Object() };
        }

        private void before() {
            Assert.assertFalse(valuesInited[0]);
            beforeCalled[0] = true;
        }

        @TestCase
        @TestData("objects")
        @Before("before")
        public void test(Object o) {
            Assert.assertTrue(beforeCalled[0]);
        }
    }, TU.EMPTY_ARGV);
    assertTrue(status.isOK());
    assertTrue(beforeCalled[0]);
    assertTrue(valuesInited[0]);
}
Also used : com.oracle.tck.lib.autd2(com.oracle.tck.lib.autd2) TestCase(com.sun.tck.test.TestCase) BaseTestGroup(com.oracle.tck.lib.autd2.unittests.BaseTestGroup) Test(org.junit.Test)

Example 18 with TestCase

use of com.sun.tck.test.TestCase in project jtharness by openjdk.

the class TestBefore method beforeThrowsException_NoParams.

@Test
public void beforeThrowsException_NoParams() {
    PrintWriter log = TU.createMockedPrintWriter();
    PrintWriter ref = TU.createMockedPrintWriter();
    final boolean[] beforeCalled = new boolean[1];
    final boolean[] methodCalled = new boolean[1];
    final int[] counter = new int[] { 0 };
    TestResult status = TU.runTestGroup(new Mytest() {

        private void myBefore() {
            org.junit.Assert.assertFalse(methodCalled[0]);
            beforeCalled[0] = true;
            throw new ExceptionThrownFromBefore();
        }

        @TestCase
        @com.sun.tck.lib.tgf.Before("myBefore")
        public void myTestWithNoParams() {
            // this won't be called
            methodCalled[0] = true;
            counter[0]++;
        }
    }, log, ref, TU.EMPTY_ARGV);
    assertFalse(status.isOK());
    assertTrue(beforeCalled[0]);
    assertFalse(methodCalled[0]);
    assertEquals(0, counter[0]);
    Assert.assertEquals("Failed. test cases: 1; all failed", status.toString());
    InOrder inOrder = inOrder(log, ref);
    inOrder.verify(log).println("hahaha, it's mocked printStackTrace method");
    // log.println("Failed trying to invoke @Before method \"myBefore\"");
    inOrder.verify(log).println("Method \"myBefore\" has thrown an exception com.oracle.tck.lib.autd2.unittests.tgfported.beforeafter.TestBefore$ExceptionThrownFromBefore: Before throws this exception");
    inOrder.verify(log).println("myTestWithNoParams: Failed. Failed trying to invoke @Before method \"myBefore\"");
    inOrder.verify(log).flush();
    inOrder.verify(ref).flush();
    verifyNoMoreInteractions(log, ref);
}
Also used : InOrder(org.mockito.InOrder) TestCase(com.sun.tck.test.TestCase) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 19 with TestCase

use of com.sun.tck.test.TestCase in project jtharness by openjdk.

the class TestBeforeAndAfter method beforeThrowsException.

@Test
public void beforeThrowsException() {
    final boolean[] afterCalled = new boolean[1];
    final boolean[] beforeCalled = new boolean[1];
    final boolean[] methodCalled = new boolean[1];
    final int[] methodCounter = new int[] { 0 };
    final int[] afterCounter = new int[] { 0 };
    final int[] beforeCounter = new int[] { 0 };
    com.oracle.tck.lib.autd2.TestResult status = com.oracle.tck.lib.autd2.unittests.TU.runTestGroup(new BaseTestGroup() {

        protected Values mySetup() {
            return DataFactory.createColumn(1, 2, 3);
        }

        private void myAfter() {
            afterCalled[0] = true;
            afterCounter[0]++;
            org.junit.Assert.fail("This must not be called");
        }

        private void myBefore() {
            org.junit.Assert.assertFalse(beforeCalled[0]);
            org.junit.Assert.assertFalse(methodCalled[0]);
            org.junit.Assert.assertFalse(afterCalled[0]);
            beforeCalled[0] = true;
            beforeCounter[0]++;
            throw new RuntimeException("Exception thrown from before");
        }

        @TestCase
        @Before("myBefore")
        @After("myAfter")
        @TestData("mySetup")
        public void test(int i) {
            methodCalled[0] = true;
            methodCounter[0]++;
            org.junit.Assert.fail("This must not be called");
        }
    }, TU.EMPTY_ARGV);
    Assert.assertFalse(status.isOK());
    Assert.assertFalse(afterCalled[0]);
    Assert.assertTrue(beforeCalled[0]);
    Assert.assertFalse(methodCalled[0]);
    Assert.assertEquals(0, methodCounter[0]);
    Assert.assertEquals(0, afterCounter[0]);
    Assert.assertEquals(1, beforeCounter[0]);
}
Also used : BaseTestGroup(com.oracle.tck.lib.autd2.unittests.BaseTestGroup) TestCase(com.sun.tck.test.TestCase) Test(org.junit.Test)

Example 20 with TestCase

use of com.sun.tck.test.TestCase in project jtharness by openjdk.

the class TestBeforeAndAfter method plain.

@Test
public void plain() {
    final boolean[] afterCalled = new boolean[1];
    final boolean[] beforeCalled = new boolean[1];
    final boolean[] methodCalled = new boolean[1];
    final int[] methodCounter = new int[] { 0 };
    final int[] afterCounter = new int[] { 0 };
    final int[] beforeCounter = new int[] { 0 };
    com.oracle.tck.lib.autd2.TestResult status = com.oracle.tck.lib.autd2.unittests.TU.runTestGroup(new BaseTestGroup() {

        protected Values mySetup() {
            return DataFactory.createColumn(1, 2, 3);
        }

        private void myAfter() {
            org.junit.Assert.assertTrue(beforeCalled[0]);
            org.junit.Assert.assertTrue(methodCalled[0]);
            org.junit.Assert.assertFalse(afterCalled[0]);
            afterCalled[0] = true;
            afterCounter[0]++;
        }

        private void myBefore() {
            org.junit.Assert.assertFalse(beforeCalled[0]);
            org.junit.Assert.assertFalse(methodCalled[0]);
            org.junit.Assert.assertFalse(afterCalled[0]);
            beforeCalled[0] = true;
            beforeCounter[0]++;
        }

        @TestCase
        @Before("myBefore")
        @After("myAfter")
        @TestData("mySetup")
        public void test(int i) {
            org.junit.Assert.assertFalse(afterCalled[0]);
            org.junit.Assert.assertTrue(beforeCalled[0]);
            methodCalled[0] = true;
            methodCounter[0]++;
        }
    }, TU.EMPTY_ARGV);
    Assert.assertTrue(status.isOK());
    Assert.assertTrue(afterCalled[0]);
    Assert.assertTrue(beforeCalled[0]);
    Assert.assertTrue(methodCalled[0]);
    Assert.assertEquals(3, methodCounter[0]);
    Assert.assertEquals(1, afterCounter[0]);
    Assert.assertEquals(1, beforeCounter[0]);
}
Also used : BaseTestGroup(com.oracle.tck.lib.autd2.unittests.BaseTestGroup) TestCase(com.sun.tck.test.TestCase) Test(org.junit.Test)

Aggregations

TestCase (com.sun.tck.test.TestCase)147 BaseTestGroup (com.oracle.tck.lib.autd2.unittests.BaseTestGroup)126 Test (org.junit.Test)77 ArrayList (java.util.ArrayList)72 TestData (com.sun.tck.lib.tgf.TestData)57 TestResult (com.oracle.tck.lib.autd2.TestResult)28 Values (com.sun.tck.lib.tgf.Values)28 HashSet (java.util.HashSet)13 DataFactory.createValues (com.sun.tck.lib.tgf.DataFactory.createValues)12 NonTestCase (com.oracle.tck.lib.autd2.NonTestCase)10 Operation (com.sun.tck.lib.tgf.data.Operation)10 TestObject (com.oracle.tck.lib.autd2.unittests.TestObject)9 PrintWriter (java.io.PrintWriter)8 InOrder (org.mockito.InOrder)8 List (java.util.List)4 DataFactory.createColumn (com.sun.tck.lib.tgf.DataFactory.createColumn)3 DataFactory.createRow (com.sun.tck.lib.tgf.DataFactory.createRow)3 java.util (java.util)3 Assert (org.junit.Assert)3 Assert.assertEquals (com.sun.tck.lib.Assert.assertEquals)2