View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.surefire.its.fixture;
20  
21  import static java.lang.Double.parseDouble;
22  
23  /**
24   * Contains commonly used features for most tests, encapsulating
25   * common use cases.
26   * <br>
27   * Also includes thread-safe access to the extracted resource
28   * files, which AbstractSurefireIntegrationTestClass does not.
29   * Thread safe only for running in "classes" mode.
30   *
31   * @author Kristian Rosenvold
32   */
33  public abstract class SurefireJUnit4IntegrationTestCase {
34      private static final int JAVA9_VERSION = 9;
35  
36      public static final double JAVA_VERSION = javaVersion();
37  
38      public static final boolean IS_JAVA9_PLUS = isJDK9Plus();
39  
40      public OutputValidator executeErrorFreeTest(String sourceName, int total) {
41          return unpack(sourceName).executeTest().verifyErrorFree(total);
42      }
43  
44      public SurefireLauncher unpack(String sourceName) {
45          return unpack(getClass(), sourceName, "");
46      }
47  
48      public SurefireLauncher unpack(String sourceName, String suffix) {
49          return unpack(getClass(), sourceName, suffix);
50      }
51  
52      public SurefireLauncher unpack(String sourceName, String suffix, String[] cli) {
53          return unpack(getClass(), sourceName, suffix, cli);
54      }
55  
56      public static SurefireLauncher unpack(Class<?> testClass, String sourceName, String suffix) {
57          return unpack(testClass, sourceName, suffix, null);
58      }
59  
60      private static SurefireLauncher unpack(Class<?> testClass, String sourceName, String suffix, String[] cli) {
61          MavenLauncher mavenLauncher = new MavenLauncher(testClass, sourceName, suffix, cli);
62          return new SurefireLauncher(mavenLauncher);
63      }
64  
65      private static double javaVersion() {
66          return parseDouble(System.getProperty("java.specification.version"));
67      }
68  
69      private static boolean isJDK9Plus() {
70          return javaVersion() >= JAVA9_VERSION;
71      }
72  }