Search in sources :

Example 6 with TestedAPI

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

the class TestCaseContext method handleTestedStatements.

/**
 * If <code>@TestedStatement</code> annotations are attached to the method of the failed testcase
 * all the available data is printed to the log
 * @param tcName name of the testcase
 */
private void handleTestedStatements(String tcName) {
    List<TestedStatement> statements = new ArrayList<>();
    // first adding all @TestedStatement present at testgroup level and all super classes/interfaces
    ReflectionUtils.getClassHierarchy(getTestGroupInstance().getClass()).forEach(c -> statements.addAll(Arrays.asList(c.getAnnotationsByType(TestedStatement.class))));
    // then processing @TestedStatements present at testcase level
    statements.addAll(Arrays.asList(testCaseMethod.getAnnotationsByType(TestedStatement.class)));
    if (!statements.isEmpty()) {
        printlnToLog(format("Testcase \"{0}\" is based on the following statements: ", tcName));
        for (TestedStatement statement : statements) {
            StringJoiner texts = new StringJoiner(", ");
            for (String text : statement.value()) {
                texts.add("\"" + text + "\"");
            }
            printlnToLog(" - " + texts.toString());
            if (!TestedStatement.DEFAULT_SOURCE.equals(statement.source())) {
                printlnToLog(" -- from source: \"" + statement.source() + "\"");
            } else {
                TestedAPI testedAPI = parentContext.getTestGroupInstance().getClass().getAnnotation(TestedAPI.class);
                if (testedAPI != null) {
                    String[] classes = testedAPI.testedClass();
                    String[] members = testedAPI.testedMember();
                    String[] packages = testedAPI.testedPackage();
                    String source = beautifulizeArrayToString(packages) + // filtering out the case when tested class or member are not specified - by default it's an array of {""}
                    (Arrays.equals(classes, new String[] { "" }) ? "" : "." + beautifulizeArrayToString(classes)) + (Arrays.equals(members, new String[] { "" }) ? "" : "." + beautifulizeArrayToString(members));
                    printlnToLog(" -- from source: " + source);
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) StringJoiner(java.util.StringJoiner) TestedAPI(com.sun.tck.test.TestedAPI)

Example 7 with TestedAPI

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

the class FailingSimpleTestCases method testedAPI_package_classes_methods.

@Test
public void testedAPI_package_classes_methods() {
    @TestedAPI(testedPackage = "s.e.g", testedClass = { "TheClass", "TheClass" }, testedMember = { "method1", "method2" })
    @TestGroup
    class MyTest {

        @TestCase
        @TestedStatement("a statement")
        public void testCase() {
            Assert.fail();
        }
    }
    TestResult s = TU.runTestGroup(new MyTest(), TU.EMPTY_ARGV);
    Assert.assertTrue(!s.isOK());
    Assert.assertEquals("test cases: 1; all failed", s.getMessage());
}
Also used : TestGroup(com.sun.tck.test.TestGroup) TestResult(com.oracle.tck.lib.autd2.TestResult) TestedAPI(com.sun.tck.test.TestedAPI) Test(org.junit.Test)

Example 8 with TestedAPI

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

the class FailingSimpleTestCases method testedAPI_packages_classes.

@Test
public void testedAPI_packages_classes() {
    @TestedAPI(testedPackage = { "x.e.r", "s.e.g", "e.t.r" }, testedClass = { "TheClass", "AnotherClass" })
    @TestGroup
    class MyTest {

        @TestCase
        @TestedStatement("a statement")
        public void testCase() {
            Assert.fail();
        }
    }
    TestResult s = TU.runTestGroup(new MyTest(), TU.EMPTY_ARGV);
    Assert.assertTrue(!s.isOK());
    Assert.assertEquals("test cases: 1; all failed", s.getMessage());
}
Also used : TestGroup(com.sun.tck.test.TestGroup) TestResult(com.oracle.tck.lib.autd2.TestResult) TestedAPI(com.sun.tck.test.TestedAPI) Test(org.junit.Test)

Example 9 with TestedAPI

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

the class FailingSimpleTestCases method testedAPI_packages_classes_method.

@Test
public void testedAPI_packages_classes_method() {
    @TestedAPI(testedPackage = { "x.e.r", "s.e.g", "e.t.r" }, testedClass = { "TheClass", "AnotherClass" }, testedMember = "method")
    @TestGroup
    class MyTest {

        @TestCase
        @TestedStatement("a statement")
        public void testCase() {
            Assert.fail();
        }
    }
    TestResult s = TU.runTestGroup(new MyTest(), TU.EMPTY_ARGV);
    Assert.assertTrue(!s.isOK());
    Assert.assertEquals("test cases: 1; all failed", s.getMessage());
}
Also used : TestGroup(com.sun.tck.test.TestGroup) TestResult(com.oracle.tck.lib.autd2.TestResult) TestedAPI(com.sun.tck.test.TestedAPI) Test(org.junit.Test)

Example 10 with TestedAPI

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

the class FailingSimpleTestCases method testedAPI_packages_classes_methods.

@Test
public void testedAPI_packages_classes_methods() {
    @TestedAPI(testedPackage = { "x.e.r", "s.e.g", "e.t.r" }, testedClass = { "TheClass", "AnotherClass" }, testedMember = { "method1", "method2" })
    @TestGroup
    class MyTest {

        @TestCase
        @TestedStatement("a statement")
        public void testCase() {
            Assert.fail();
        }
    }
    TestResult s = TU.runTestGroup(new MyTest(), TU.EMPTY_ARGV);
    Assert.assertTrue(!s.isOK());
    Assert.assertEquals("test cases: 1; all failed", s.getMessage());
}
Also used : TestGroup(com.sun.tck.test.TestGroup) TestResult(com.oracle.tck.lib.autd2.TestResult) TestedAPI(com.sun.tck.test.TestedAPI) Test(org.junit.Test)

Aggregations

TestedAPI (com.sun.tck.test.TestedAPI)11 TestResult (com.oracle.tck.lib.autd2.TestResult)10 TestGroup (com.sun.tck.test.TestGroup)10 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)1 StringJoiner (java.util.StringJoiner)1