001/*-------------------------------------------------------------------------+
002|                                                                          |
003| Copyright (c) 2009-2018 CQSE GmbH                                        |
004|                                                                          |
005+-------------------------------------------------------------------------*/
006package org.conqat.lib.commons.test;
007
008import java.util.Map;
009
010/** Test utils. */
011public class TestUtils {
012
013        /** Can be used to mock being on a CI server. */
014        private static boolean simulateCiServer = false;
015
016        /** Returns whether this test case is being executed on the CI server. */
017        public static boolean isExecutionOnCiServer() {
018                return isExecutionOnCiServer(System.getenv());
019        }
020
021        /**
022         * True if this is being executed on the CI server, see <a href=
023         * "https://docs.gitlab.com/ee/ci/variables/#predefined-variables-environment-variables">GitLab
024         * predefined variables</a>
025         */
026        public static boolean isExecutionOnCiServer(Map<String, String> environment) {
027                return simulateCiServer || environment.get("CI") != null;
028        }
029
030        /**
031         * Enable CI server simulation. Future calls to this class will behave as if
032         * they were executed in a CI environment.
033         */
034        public static void enableCiServerEnvironment() {
035                simulateCiServer = true;
036        }
037
038        /**
039         * Disable CI server simulation. Future calls to this class will no longer
040         * behave as if they were executed in a CI environment.
041         */
042        public static void disableCiServerEnvironment() {
043                simulateCiServer = false;
044        }
045}