Package org.mockito.internal.util
Class JavaEightUtil
java.lang.Object
org.mockito.internal.util.JavaEightUtil
Helper 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 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic Object
Creates an empty DoubleStream using reflection to stay backwards-compatible with older JDKs.static Object
Creates an empty Duration using reflection to stay backwards-compatible with older JDKs.static Object
Creates an empty IntStream using reflection to stay backwards-compatible with older JDKs.static Object
Creates an empty LongStream using reflection to stay backwards-compatible with older JDKs.static Object
Creates an empty Optional using reflection to stay backwards-compatible with older JDKs.static Object
Creates an empty OptionalDouble using reflection to stay backwards-compatible with older JDKs.static Object
Creates an empty OptionalInt using reflection to stay backwards-compatible with older JDKs.static Object
Creates an empty OptionalLong using reflection to stay backwards-compatible with older JDKs.static Object
Creates an empty Period using reflection to stay backwards-compatible with older JDKs.static Object
Creates an empty Stream using reflection to stay backwards-compatible with older JDKs.private static Class<?>
Returns theClass
object associated with the class or interface with the given string name.private static Method
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 Object
getStaticFieldValue
(String fqcn, String fieldName) Gets a value of the classes' field using reflection to stay backwards-compatible with older JDKs.private static Object
invokeNullaryFactoryMethod
(String fqcn, String methodName) Invokes a nullary static factory method using reflection to stay backwards-compatible with older JDKs.
-
Field Details
-
emptyOptional
-
emptyOptionalDouble
-
emptyOptionalInt
-
emptyOptionalLong
-
emptyDuration
-
emptyPeriod
-
-
Constructor Details
-
JavaEightUtil
private JavaEightUtil()
-
-
Method Details
-
emptyOptional
Creates an empty Optional using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty Optional.
-
emptyOptionalDouble
Creates an empty OptionalDouble using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty OptionalDouble.
-
emptyOptionalInt
Creates an empty OptionalInt using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty OptionalInt.
-
emptyOptionalLong
Creates an empty OptionalLong using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty OptionalLong.
-
emptyStream
Creates an empty Stream using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty Stream.
-
emptyDoubleStream
Creates an empty DoubleStream using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty DoubleStream.
-
emptyIntStream
Creates an empty IntStream using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty IntStream.
-
emptyLongStream
Creates an empty LongStream using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty LongStream.
-
emptyDuration
Creates an empty Duration using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty (ZERO) Duration.
-
emptyPeriod
Creates an empty Period using reflection to stay backwards-compatible with older JDKs.- Returns:
- an empty (ZERO) Period.
-
invokeNullaryFactoryMethod
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
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
Returns theClass
object 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
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.
-