langtools/test/tools/javac/classfiles/attributes/lib/TestResult.java
author aeremeev
Tue, 12 Aug 2014 13:24:40 +0400
changeset 26101 d5dd2ecd2353
parent 25434 823512a72660
child 27552 8a4b2d3639c1
permissions -rw-r--r--
8042251: Implement classfile tests for InnerClasses attribute. Reviewed-by: jjg, anazarov, shurailine
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     1
/*
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     4
 *
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     8
 *
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    13
 * accompanied this code).
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    14
 *
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    18
 *
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    21
 * questions.
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    22
 */
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    23
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    24
import java.io.PrintWriter;
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    25
import java.io.StringWriter;
26101
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    26
import java.util.*;
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    27
import java.util.stream.Stream;
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    28
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    29
import static java.lang.String.format;
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    30
import static java.util.stream.Collectors.joining;
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    31
26101
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    32
/**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    33
 * This class accumulates test results. Test results can be checked with method @{code checkStatus}.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    34
 */
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    35
public class TestResult extends TestBase {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    36
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    37
    private final List<Info> testCases;
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    38
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    39
    public TestResult() {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    40
        testCases = new ArrayList<>();
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    41
        testCases.add(new Info("Global test info"));
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    42
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    43
26101
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    44
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    45
     * Adds new test case info.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    46
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    47
     * @param info the information about test case
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    48
     */
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    49
    public void addTestCase(String info) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    50
        testCases.add(new Info(info));
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    51
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    52
26101
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    53
    private String errorMessage() {
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    54
        return testCases.stream().filter(Info::isFailed)
26101
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    55
                .map(tc -> format("Failure in test case:\n%s\n%s", tc.info(), tc.getMessage()))
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    56
                .collect(joining("\n"));
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    57
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    58
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    59
    @Override
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    60
    public void assertEquals(Object actual, Object expected, String message) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    61
        getLastTestCase().assertEquals(actual, expected, message);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    62
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    63
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    64
    @Override
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    65
    public void assertNull(Object actual, String message) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    66
        getLastTestCase().assertEquals(actual, null, message);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    67
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    68
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    69
    @Override
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    70
    public void assertNotNull(Object actual, String message) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    71
        getLastTestCase().assertNotNull(actual, message);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    72
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    73
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    74
    @Override
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    75
    public void assertFalse(boolean actual, String message) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    76
        getLastTestCase().assertEquals(actual, false, message);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    77
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    78
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    79
    @Override
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    80
    public void assertTrue(boolean actual, String message) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    81
        getLastTestCase().assertEquals(actual, true, message);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    82
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    83
26101
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    84
    public void assertContains(Set<?> found, Set<?> expected, String message) {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    85
        Set<?> copy = new HashSet<>(expected);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    86
        copy.removeAll(found);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    87
        assertTrue(found.containsAll(expected), message + " : " + copy);
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    88
    }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    89
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    90
    public void addFailure(Throwable th) {
26101
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
    91
        testCases.get(testCases.size() - 1).addFailure(th);
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    92
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    93
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    94
    private Info getLastTestCase() {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    95
        if (testCases.size() == 1) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    96
            throw new IllegalStateException("Test case should be created");
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    97
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    98
        return testCases.get(testCases.size() - 1);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
    99
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   100
26101
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   101
    /**
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   102
     * Throws {@code TestFailedException} if one of the asserts are failed
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   103
     * or an exception occurs. Prints error message of failed test cases.
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   104
     *
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   105
     * @throws TestFailedException if one of the asserts are failed
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   106
     *                             or an exception occurs
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   107
     */
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   108
    public void checkStatus() throws TestFailedException {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   109
        if (testCases.stream().anyMatch(Info::isFailed)) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   110
            echo(errorMessage());
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   111
            throw new TestFailedException("Test failed");
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   112
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   113
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   114
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   115
    private class Info {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   116
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   117
        private final String info;
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   118
        private final List<String> asserts;
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   119
        private final List<Throwable> errors;
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   120
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   121
        private Info(String info) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   122
            this.info = info;
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   123
            asserts = new ArrayList<>();
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   124
            errors = new ArrayList<>();
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   125
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   126
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   127
        public String info() {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   128
            return info;
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   129
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   130
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   131
        public boolean isFailed() {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   132
            return !asserts.isEmpty() || !errors.isEmpty();
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   133
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   134
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   135
        public void addFailure(Throwable th) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   136
            errors.add(th);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   137
            printf("[ERROR] : %s\n", getStackTrace(th));
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   138
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   139
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   140
        public void addFailure(String message) {
26101
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   141
            String stackTrace = Stream.of(Thread.currentThread().getStackTrace())
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   142
                    // just to get stack trace without TestResult and Thread
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   143
                    .filter(e -> !"TestResult.java".equals(e.getFileName()) &&
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   144
                            !"java.lang.Thread".equals(e.getClassName()))
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   145
                    .map(e -> "\tat " + e)
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   146
                    .collect(joining("\n"));
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   147
            asserts.add(format("%s\n%s", message, stackTrace));
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   148
            printf("[ASSERT] : %s\n", message);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   149
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   150
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   151
        public void assertEquals(Object actual, Object expected, String message) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   152
            echo("Testing : " + message);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   153
            if (!Objects.equals(actual, expected)) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   154
                addFailure(message + ": Got: " + actual + ", " + "Expected: " + expected);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   155
            }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   156
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   157
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   158
        public void assertNotNull(Object actual, String message) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   159
            echo("Testing : " + message);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   160
            if (actual == null) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   161
                addFailure(message + " : Expected not null value");
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   162
            }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   163
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   164
26101
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   165
        public String getMessage() {
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   166
            return (asserts.size() > 0 ? getAssertMessage() + "\n" : "") + getErrorMessage();
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   167
        }
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   168
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   169
        public String getAssertMessage() {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   170
            return asserts.stream()
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   171
                    .map(failure -> "[ASSERT] : " + failure)
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   172
                    .collect(joining("\n"));
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   173
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   174
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   175
        public String getErrorMessage() {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   176
            return errors.stream()
26101
d5dd2ecd2353 8042251: Implement classfile tests for InnerClasses attribute.
aeremeev
parents: 25434
diff changeset
   177
                    .map(throwable -> format("[ERROR] : %s", getStackTrace(throwable)))
25434
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   178
                    .collect(joining("\n"));
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   179
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   180
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   181
        public String getStackTrace(Throwable throwable) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   182
            StringWriter stringWriter = new StringWriter();
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   183
            try (PrintWriter printWriter = new PrintWriter(stringWriter)) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   184
                throwable.printStackTrace(printWriter);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   185
            }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   186
            return stringWriter.toString();
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   187
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   188
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   189
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   190
    public static class TestFailedException extends Exception {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   191
        public TestFailedException(String message) {
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   192
            super(message);
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   193
        }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   194
    }
823512a72660 8042261: Implement classfile tests for Deprecated attribute.
jjg
parents:
diff changeset
   195
}