Search in sources :

Example 26 with TestCase

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

the class Exclusion method check_Mixed_4.

private void check_Mixed_4(List<Integer> allData, List<Integer> expectedPassedToTestCase, String expectedStatusMessage, final int expectedMyTestCounter, final int expectedBlablaCounter, String... args) {
    final int[] myTestCounter = new int[] { 0 };
    final int[] blablaCounter = new int[] { 0 };
    final int[] fooCounter = new int[] { 0 };
    com.oracle.tck.lib.autd2.TestResult status = com.oracle.tck.lib.autd2.unittests.TU.runTestGroup(new BaseTestGroup() {

        private List mySetup() {
            return allData;
        }

        @TestCase
        public void myTest() {
            myTestCounter[0]++;
        }

        @TestCase
        public void blabla() {
            blablaCounter[0]++;
        }

        @TestCase
        @TestData("mySetup")
        public void foo(int i) {
            Assert.assertEquals((int) expectedPassedToTestCase.get(fooCounter[0]), i);
            fooCounter[0]++;
        }
    }, args);
    Assert.assertTrue(status.isOK());
    Assert.assertEquals(expectedStatusMessage, status.toString());
    Assert.assertEquals(expectedMyTestCounter, myTestCounter[0]);
    Assert.assertEquals(expectedBlablaCounter, blablaCounter[0]);
    Assert.assertEquals(expectedPassedToTestCase.size(), fooCounter[0]);
}
Also used : TestData(com.sun.tck.lib.tgf.TestData) TestCase(com.sun.tck.test.TestCase) BaseTestGroup(com.oracle.tck.lib.autd2.unittests.BaseTestGroup) List(java.util.List) ArrayList(java.util.ArrayList)

Example 27 with TestCase

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

the class Exclusion method test_excludedArg.

@Test
public void test_excludedArg() {
    final int[] methodCounter = new int[] { 0 };
    final ArrayList<Integer> expectedArgValues = new ArrayList<Integer>() {

        {
            add(2);
            add(3);
        }
    };
    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);
        }

        @TestCase
        @TestData("mySetup")
        public void myTest(int i) {
            Assert.assertTrue(i + " is not among expected", expectedArgValues.contains(i));
            methodCounter[0]++;
        }
    }, new String[] { EXCLUDE_WORD, "myTest" });
    Assert.assertTrue(status.isOK());
    Assert.assertEquals(0, methodCounter[0]);
}
Also used : TestData(com.sun.tck.lib.tgf.TestData) ArrayList(java.util.ArrayList) Values(com.sun.tck.lib.tgf.Values) BaseTestGroup(com.oracle.tck.lib.autd2.unittests.BaseTestGroup) TestCase(com.sun.tck.test.TestCase) Test(org.junit.Test)

Example 28 with TestCase

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

the class Filtering method absorbingExceptions_exceptionThrownOut.

@Test
public void absorbingExceptions_exceptionThrownOut() {
    try {
        final TestResult run = com.oracle.tck.lib.autd2.unittests.TU.runTestGroup(new BaseTestGroup() {

            Values values = createColumn(Double.class, Class.class).filter((Values.Transformer1<Class<?>>) c -> c.getConstructor().newInstance());

            @TestCase
            @TestData("values")
            public void myTest(Object s) {
                System.out.println("s = " + s);
            }
        });
        Assert.fail("Exception expected");
    } catch (RuntimeException e) {
        Assert.assertTrue(e.getCause() instanceof InvocationTargetException);
        Assert.assertTrue(e.getCause().getCause() instanceof NoSuchMethodException);
        Assert.assertEquals("java.lang.Double.<init>()", e.getCause().getCause().getMessage());
    }
}
Also used : java.util(java.util) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) BaseTestGroup(com.oracle.tck.lib.autd2.unittests.BaseTestGroup) TU(com.oracle.tck.lib.autd2.unittests.TU) TestResult(com.oracle.tck.lib.autd2.TestResult) ValuesComparison(com.oracle.tck.lib.autd2.unittests.ValuesComparison) InvocationTargetException(java.lang.reflect.InvocationTargetException) java.awt(java.awt) DataFactory.createValues(com.sun.tck.lib.tgf.DataFactory.createValues) TestCase(com.sun.tck.test.TestCase) DataFactory.createRow(com.sun.tck.lib.tgf.DataFactory.createRow) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Assert(org.junit.Assert) DataFactory.createColumn(com.sun.tck.lib.tgf.DataFactory.createColumn) Assert.assertEquals(org.junit.Assert.assertEquals) com.sun.tck.lib.tgf(com.sun.tck.lib.tgf) javax.swing(javax.swing) TestCase(com.sun.tck.test.TestCase) DataFactory.createValues(com.sun.tck.lib.tgf.DataFactory.createValues) BaseTestGroup(com.oracle.tck.lib.autd2.unittests.BaseTestGroup) TestResult(com.oracle.tck.lib.autd2.TestResult) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 29 with TestCase

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

the class Examples method test_03.

@Test
public void test_03() {
    @TestGroup
    class Test {

        Values colors = createColumn(BLUE, BLACK, WHITE).<Color>filter(c -> createRow(c.darker(), c.brighter()));

        @TestCase
        @TestData("colors")
        public void test(Color darker, Color brighter) {
            assertTrue(darker.getRed() <= brighter.getRed());
            assertTrue(darker.getGreen() <= brighter.getGreen());
            assertTrue(darker.getBlue() <= brighter.getBlue());
        }
    }
    com.oracle.tck.lib.autd2.TestResult s = TU.runTestGroup(new Test());
    Assert.assertTrue(s.isOK());
    Assert.assertEquals("test cases: 1; all passed", s.getMessage());
}
Also used : Color(java.awt.Color) IntStream(java.util.stream.IntStream) TestData(com.sun.tck.lib.tgf.TestData) DataFactory(com.sun.tck.lib.tgf.DataFactory) Arrays(java.util.Arrays) Longs(com.sun.tck.lib.tgf.data.Longs) MULTIPLY(com.sun.tck.lib.tgf.data.Operation.TYPE.MULTIPLY) Test(org.junit.Test) TestResult(com.oracle.tck.lib.autd2.TestResult) ColorSpace(java.awt.color.ColorSpace) Operation(com.sun.tck.lib.tgf.data.Operation) TestGroup(com.sun.tck.test.TestGroup) RandomAccess(java.util.RandomAccess) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) TestCase(com.sun.tck.test.TestCase) DataFactory.createRow(com.sun.tck.lib.tgf.DataFactory.createRow) Transform(com.sun.tck.lib.tgf.Transform) ExpectedExceptions(com.sun.tck.lib.ExpectedExceptions) Values(com.sun.tck.lib.tgf.Values) Assert(org.junit.Assert) Assert.assertTrue(com.sun.tck.lib.Assert.assertTrue) DataFactory.createColumn(com.sun.tck.lib.tgf.DataFactory.createColumn) Assert.assertEquals(com.sun.tck.lib.Assert.assertEquals) Test(org.junit.Test) Color(java.awt.Color) Values(com.sun.tck.lib.tgf.Values) TestGroup(com.sun.tck.test.TestGroup) TestResult(com.oracle.tck.lib.autd2.TestResult) Test(org.junit.Test)

Example 30 with TestCase

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

the class Filtering method absorbingExceptions_exceptionThrownOut_1.

@Test
public void absorbingExceptions_exceptionThrownOut_1() {
    final ArrayList<String> arrayList = new ArrayList<String>();
    final Throwable throwable = new Throwable();
    try {
        com.oracle.tck.lib.autd2.unittests.TU.runTestGroup(new BaseTestGroup() {

            Values values = createColumn("1", "2").filter((String s) -> {
                throw throwable;
            });

            @TestCase
            @TestData("values")
            public void myTest(Object s) {
                arrayList.add(s.getClass().getCanonicalName());
            }
        });
        Assert.fail("Exception expected");
    } catch (RuntimeException e) {
        Assert.assertTrue(e.getCause() instanceof InvocationTargetException);
        Assert.assertSame(throwable, e.getCause().getCause());
    }
}
Also used : TestCase(com.sun.tck.test.TestCase) DataFactory.createValues(com.sun.tck.lib.tgf.DataFactory.createValues) BaseTestGroup(com.oracle.tck.lib.autd2.unittests.BaseTestGroup) InvocationTargetException(java.lang.reflect.InvocationTargetException) 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