Package net.shibboleth.shared.testing

# Class TestSupport

java.lang.Object
net.shibboleth.shared.testing.TestSupport

public final class TestSupport extends Object
A collection of methods supporting test class execution. Methods named `isJavaV` x `OrLater` are for use by tests needing to vary what they test, or the results they expect, depending on the version of Java under which the test is executing. For example, code which behaves differently depending on the presence of cryptographic algorithms only available from some specific version of the Java platform may be gated by such a method. The code under test should instead operate on the basis of the presence or absence of the algorithm in question. The API provided for Java version detection provides only `isJavaV` x `OrLater` and not a generic `getJavaVersion` to avoid any dependency in test code of knowledge of the ordering of Java version numbers. Such an `int` scheme is used internally, but not exposed except for self-tests. Methods named `has` X, describing the presence of specific features of the run-time environment, are to be preferred over version-based methods. We don't have any of these yet, though.

## Constructor Summary

Constructors
Modifier
Constructor
Description
`private`
`TestSupport()`
Constructor.

## Method Summary

Modifier and Type
Method
Description
`protected static int`
`getJavaVersion(String versionStr)`
Extracts the major version number from a Java version string.
`static boolean`
`isJavaV11OrLater()`
Deprecated, for removal: This API element is subject to removal in a future version.
`static boolean`
`isJavaV7OrLater()`
Deprecated, for removal: This API element is subject to removal in a future version.
`static boolean`
`isJavaV8OrLater()`
Deprecated, for removal: This API element is subject to removal in a future version.
`static boolean`
`isJavaV9OrLater()`
Deprecated, for removal: This API element is subject to removal in a future version.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### TestSupport

private TestSupport()
Constructor.

## Method Details

### getJavaVersion

protected static int getJavaVersion(@Nonnull String versionStr)
Extracts the major version number from a Java version string. This is not part of the API of the class, but is available as a protected method for self-testing. The version string given by the `java.version` property has changed format multiple times in its history. This method acts as a parser for such strings. It is only required to handle versions of Java from the current platform baseline onwards (and thus their particular version string quirks) but in practice may support previous versions. For Java 6, 7 and 8, the version string has a format like "1.X.0_123" where X is the version of Java. This means that there will always be at least two components separated by periods, and that the first such component will always be "1". Examples of versions strings observed in practice:

- `1.6.0_65-b14-468`
- `1.7.0_51`
- `1.8.0_144`

For Java 9, the version string format is described in JEP 223. For Java 10, the version string format is described in JEP 322 Both JEP 223 and JEP 322 allow for an arbitrary number of numeric components separated by periods, but the possibility exists for this to be a single component. Following this a number of other components delimited by either `+` or `-` may appear. This means that version strings like "10+43" are possible, and have been observed.

Parameters:
  `versionStr` - version string to extract the version from
Returns:
  the major version number
See Also:
  - JEP 223
  - JEP 322

### isJavaV7OrLater

@Deprecated(forRemoval=true, since="4.1") public static boolean isJavaV7OrLater()
Deprecated, for removal: This API element is subject to removal in a future version.
Indicates whether the tests are running under Java 7 or a later version.

Returns:
  `true` if the runtime environment is Java 7 or later

### isJavaV8OrLater

@Deprecated(forRemoval=true, since="4.1") public static boolean isJavaV8OrLater()
Deprecated, for removal: This API element is subject to removal in a future version.
Indicates whether the tests are running under Java 8 or a later version.

Returns:
  `true` if the runtime environment is Java 8 or later

### isJavaV9OrLater

@Deprecated(forRemoval=true, since="4.1") public static boolean isJavaV9OrLater()
Deprecated, for removal: This API element is subject to removal in a future version.
Indicates whether the tests are running under Java 9 or a later version.

Returns:
  `true` if the runtime environment is Java 9 or later

### isJavaV11OrLater

@Deprecated(forRemoval=true, since="4.1") public static boolean isJavaV11OrLater()
Deprecated, for removal: This API element is subject to removal in a future version.
Indicates whether the tests are running under Java 11 or a later version.

Returns:
  `true` if the runtime environment is Java 11 or later