Package org.mockito.internal.util
Class JavaEightUtil
- java.lang.Object
-
- org.mockito.internal.util.JavaEightUtil
-
public final class JavaEightUtil extends java.lang.ObjectHelper class to work with features that were introduced in Java versions after 1.5. This class uses reflection in most places to avoid coupling with a newer JDK.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.ObjectemptyDurationprivate static java.lang.ObjectemptyOptionalprivate static java.lang.ObjectemptyOptionalDoubleprivate static java.lang.ObjectemptyOptionalIntprivate static java.lang.ObjectemptyOptionalLongprivate static java.lang.ObjectemptyPeriod
-
Constructor Summary
Constructors Modifier Constructor Description privateJavaEightUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.ObjectemptyDoubleStream()Creates an empty DoubleStream using reflection to stay backwards-compatible with older JDKs.static java.lang.ObjectemptyDuration()Creates an empty Duration using reflection to stay backwards-compatible with older JDKs.static java.lang.ObjectemptyIntStream()Creates an empty IntStream using reflection to stay backwards-compatible with older JDKs.static java.lang.ObjectemptyLongStream()Creates an empty LongStream using reflection to stay backwards-compatible with older JDKs.static java.lang.ObjectemptyOptional()Creates an empty Optional using reflection to stay backwards-compatible with older JDKs.static java.lang.ObjectemptyOptionalDouble()Creates an empty OptionalDouble using reflection to stay backwards-compatible with older JDKs.static java.lang.ObjectemptyOptionalInt()Creates an empty OptionalInt using reflection to stay backwards-compatible with older JDKs.static java.lang.ObjectemptyOptionalLong()Creates an empty OptionalLong using reflection to stay backwards-compatible with older JDKs.static java.lang.ObjectemptyPeriod()Creates an empty Period using reflection to stay backwards-compatible with older JDKs.static java.lang.ObjectemptyStream()Creates an empty Stream using reflection to stay backwards-compatible with older JDKs.private static java.lang.Class<?>getClass(java.lang.String fqcn)Returns theClassobject associated with the class or interface with the given string name.private static java.lang.reflect.MethodgetMethod(java.lang.String fqcn, java.lang.String methodName, java.lang.Class<?>... parameterClasses)Returns a Method object that reflects the specified public member method of the class or interface represented by the fully qualified class name.private static java.lang.ObjectgetStaticFieldValue(java.lang.String fqcn, java.lang.String fieldName)Gets a value of the classes' field using reflection to stay backwards-compatible with older JDKs.private static java.lang.ObjectinvokeNullaryFactoryMethod(java.lang.String fqcn, java.lang.String methodName)Invokes a nullary static factory method using reflection to stay backwards-compatible with older JDKs.
-
-
-
Field Detail
-
emptyOptional
private static java.lang.Object emptyOptional
-
emptyOptionalDouble
private static java.lang.Object emptyOptionalDouble
-
emptyOptionalInt
private static java.lang.Object emptyOptionalInt
-
emptyOptionalLong
private static java.lang.Object emptyOptionalLong
-
emptyDuration
private static java.lang.Object emptyDuration
-
emptyPeriod
private static java.lang.Object emptyPeriod
-
-
Method Detail
-
emptyOptional
public static java.lang.Object emptyOptional()
Creates an empty Optional using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty Optional.
-
emptyOptionalDouble
public static java.lang.Object emptyOptionalDouble()
Creates an empty OptionalDouble using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty OptionalDouble.
-
emptyOptionalInt
public static java.lang.Object emptyOptionalInt()
Creates an empty OptionalInt using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty OptionalInt.
-
emptyOptionalLong
public static java.lang.Object emptyOptionalLong()
Creates an empty OptionalLong using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty OptionalLong.
-
emptyStream
public static java.lang.Object emptyStream()
Creates an empty Stream using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty Stream.
-
emptyDoubleStream
public static java.lang.Object emptyDoubleStream()
Creates an empty DoubleStream using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty DoubleStream.
-
emptyIntStream
public static java.lang.Object emptyIntStream()
Creates an empty IntStream using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty IntStream.
-
emptyLongStream
public static java.lang.Object emptyLongStream()
Creates an empty LongStream using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty LongStream.
-
emptyDuration
public static java.lang.Object emptyDuration()
Creates an empty Duration using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty (ZERO) Duration.
-
emptyPeriod
public static java.lang.Object emptyPeriod()
Creates an empty Period using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty (ZERO) Period.
-
invokeNullaryFactoryMethod
private static java.lang.Object invokeNullaryFactoryMethod(java.lang.String fqcn, java.lang.String methodName)Invokes a nullary static factory method using reflection to stay backwards-compatible with older JDKs.- Parameters:
fqcn- The fully qualified class name of the type to be produced.methodName- The name of the factory method.- Returns:
- the object produced.
-
getStaticFieldValue
private static java.lang.Object getStaticFieldValue(java.lang.String fqcn, java.lang.String fieldName)Gets a value of the classes' field using reflection to stay backwards-compatible with older JDKs.- Parameters:
fqcn- The fully qualified class name of the type to be produced.fieldName- The name of th classes' field which value is going to be returned.- Returns:
- the restored value.
-
getClass
private static java.lang.Class<?> getClass(java.lang.String fqcn)
Returns theClassobject associated with the class or interface with the given string name.- Parameters:
fqcn- The fully qualified class name of the type to be produced.- Returns:
- the Class object for the class with the specified name.
-
getMethod
private static java.lang.reflect.Method getMethod(java.lang.String fqcn, java.lang.String methodName, java.lang.Class<?>... parameterClasses)Returns a Method object that reflects the specified public member method of the class or interface represented by the fully qualified class name.- Parameters:
fqcn- The fully qualified class name of the type to be produced.methodName- The name of the method.parameterClasses- The list of parameters.- Returns:
- The Method object that matches the specified name and parameterTypes.
-
-