1/*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23package java.util.stream;
24
25/**
26 * Runtime modes of test execution.
27 */
28public enum LambdaTestMode {
29    /**
30     * Execution mode with no particular runtime constraints.
31     */
32    NORMAL,
33
34    /**
35     * Execution mode where tests are executed for testing lambda serialization
36     * and deserialization.
37     *
38     * <p>This mode may be queried by tests or data supplied by data
39     * providers, which cannot otherwise be assigned to the test group
40     * <em>serialization-hostile</em>, to not execute or declare
41     * serialization-hostile code or data.
42     *
43     * <p>This mode is enabled if the boolean system property
44     * {@code org.openjdk.java.util.stream.sand.mode} is declared with a
45     * {@code true} value.
46     */
47    SERIALIZATION;
48
49    /**
50     * {@code true} if tests are executed in the mode for testing lambda
51     * Serialization ANd Deserialization (SAND).
52     */
53    private static final boolean IS_LAMBDA_SERIALIZATION_MODE =
54            Boolean.getBoolean("org.openjdk.java.util.stream.sand.mode");
55
56    /**
57     *
58     * @return the mode of test execution.
59     */
60    public static LambdaTestMode getMode() {
61        return IS_LAMBDA_SERIALIZATION_MODE ? SERIALIZATION : NORMAL;
62    }
63
64    /**
65     *
66     * @return {@code true} if normal test mode.
67     */
68    public static boolean isNormalMode() {
69        return getMode() == NORMAL;
70    }
71}
72