Interface ArgumentsAccessor
-
- All Known Implementing Classes:
DefaultArgumentsAccessor
@API(status=EXPERIMENTAL, since="5.2") public interface ArgumentsAccessorArgumentsAccessordefines the public API for accessing arguments provided by anArgumentsProviderfor a single invocation of a@ParameterizedTestmethod.Specifically, an
ArgumentsAccessoraggregates a set of arguments for a given invocation of a parameterized test and provides convenience methods for accessing those arguments in a type-safe manner with support for automatic type conversion.An instance of
ArgumentsAccessorwill be automatically supplied for any parameter of typeArgumentsAccessorin a parameterized test. In addition,ArgumentsAggregatorimplementations are given access to anArgumentsAccessor.This interface is not intended to be implemented by clients.
Additional Kotlin arguments accessors can be found as extension functions in the
org.junit.jupiter.params.aggregatorpackage.- Since:
- 5.2
- See Also:
ArgumentsAggregator,ParameterizedTest
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Objectget(int index)Get the value of the argument at the given index as anObject.<T> Tget(int index, java.lang.Class<T> requiredType)Get the value of the argument at the given index as an instance of the required type.java.lang.BooleangetBoolean(int index)Get the value of the argument at the given index as aBoolean, performing automatic type conversion as necessary.java.lang.BytegetByte(int index)Get the value of the argument at the given index as aByte, performing automatic type conversion as necessary.java.lang.CharactergetCharacter(int index)Get the value of the argument at the given index as aCharacter, performing automatic type conversion as necessary.java.lang.DoublegetDouble(int index)Get the value of the argument at the given index as aDouble, performing automatic type conversion as necessary.java.lang.FloatgetFloat(int index)Get the value of the argument at the given index as aFloat, performing automatic type conversion as necessary.java.lang.IntegergetInteger(int index)Get the value of the argument at the given index as aInteger, performing automatic type conversion as necessary.java.lang.LonggetLong(int index)Get the value of the argument at the given index as aLong, performing automatic type conversion as necessary.java.lang.ShortgetShort(int index)Get the value of the argument at the given index as aShort, performing automatic type conversion as necessary.java.lang.StringgetString(int index)Get the value of the argument at the given index as aString, performing automatic type conversion as necessary.intsize()Get the number of arguments in this accessor.java.lang.Object[]toArray()Get all arguments in this accessor as an array.java.util.List<java.lang.Object>toList()Get all arguments in this accessor as an immutable list.
-
-
-
Method Detail
-
get
java.lang.Object get(int index) throws ArgumentAccessExceptionGet the value of the argument at the given index as anObject.- Parameters:
index- the index of the argument to get; must be greater than or equal to zero and less thansize()- Returns:
- the value at the given index, potentially
null - Throws:
ArgumentAccessException
-
get
<T> T get(int index, java.lang.Class<T> requiredType) throws ArgumentAccessExceptionGet the value of the argument at the given index as an instance of the required type.- Parameters:
index- the index of the argument to get; must be greater than or equal to zero and less thansize()requiredType- the required type of the value; nevernull- Returns:
- the value at the given index, potentially
null - Throws:
ArgumentAccessException
-
getCharacter
java.lang.Character getCharacter(int index) throws ArgumentAccessExceptionGet the value of the argument at the given index as aCharacter, performing automatic type conversion as necessary.- Parameters:
index- the index of the argument to get; must be greater than or equal to zero and less thansize()- Returns:
- the value at the given index, potentially
null - Throws:
ArgumentAccessException- if the value cannot be accessed or converted to the desired type
-
getBoolean
java.lang.Boolean getBoolean(int index) throws ArgumentAccessExceptionGet the value of the argument at the given index as aBoolean, performing automatic type conversion as necessary.- Parameters:
index- the index of the argument to get; must be greater than or equal to zero and less thansize()- Returns:
- the value at the given index, potentially
null - Throws:
ArgumentAccessException- if the value cannot be accessed or converted to the desired type
-
getByte
java.lang.Byte getByte(int index) throws ArgumentAccessExceptionGet the value of the argument at the given index as aByte, performing automatic type conversion as necessary.- Parameters:
index- the index of the argument to get; must be greater than or equal to zero and less thansize()- Returns:
- the value at the given index, potentially
null - Throws:
ArgumentAccessException- if the value cannot be accessed or converted to the desired type
-
getShort
java.lang.Short getShort(int index) throws ArgumentAccessExceptionGet the value of the argument at the given index as aShort, performing automatic type conversion as necessary.- Parameters:
index- the index of the argument to get; must be greater than or equal to zero and less thansize()- Returns:
- the value at the given index, potentially
null - Throws:
ArgumentAccessException- if the value cannot be accessed or converted to the desired type
-
getInteger
java.lang.Integer getInteger(int index) throws ArgumentAccessExceptionGet the value of the argument at the given index as aInteger, performing automatic type conversion as necessary.- Parameters:
index- the index of the argument to get; must be greater than or equal to zero and less thansize()- Returns:
- the value at the given index, potentially
null - Throws:
ArgumentAccessException- if the value cannot be accessed or converted to the desired type
-
getLong
java.lang.Long getLong(int index) throws ArgumentAccessExceptionGet the value of the argument at the given index as aLong, performing automatic type conversion as necessary.- Parameters:
index- the index of the argument to get; must be greater than or equal to zero and less thansize()- Returns:
- the value at the given index, potentially
null - Throws:
ArgumentAccessException- if the value cannot be accessed or converted to the desired type
-
getFloat
java.lang.Float getFloat(int index) throws ArgumentAccessExceptionGet the value of the argument at the given index as aFloat, performing automatic type conversion as necessary.- Parameters:
index- the index of the argument to get; must be greater than or equal to zero and less thansize()- Returns:
- the value at the given index, potentially
null - Throws:
ArgumentAccessException- if the value cannot be accessed or converted to the desired type
-
getDouble
java.lang.Double getDouble(int index) throws ArgumentAccessExceptionGet the value of the argument at the given index as aDouble, performing automatic type conversion as necessary.- Parameters:
index- the index of the argument to get; must be greater than or equal to zero and less thansize()- Returns:
- the value at the given index, potentially
null - Throws:
ArgumentAccessException- if the value cannot be accessed or converted to the desired type
-
getString
java.lang.String getString(int index) throws ArgumentAccessExceptionGet the value of the argument at the given index as aString, performing automatic type conversion as necessary.- Parameters:
index- the index of the argument to get; must be greater than or equal to zero and less thansize()- Returns:
- the value at the given index, potentially
null - Throws:
ArgumentAccessException- if the value cannot be accessed or converted to the desired type
-
size
int size()
Get the number of arguments in this accessor.
-
toArray
java.lang.Object[] toArray()
Get all arguments in this accessor as an array.
-
toList
java.util.List<java.lang.Object> toList()
Get all arguments in this accessor as an immutable list.
-
-