Argument API
Complete API reference for the Argument interface
The Argument<T> interface provides type-safe containers for test data.
Interface Definition
public interface Argument<T> {
String getName();
T getPayload();
boolean hasPayload();
<V> V getPayloadAs(Class<V> type);
}
Methods
getName()
Returns the display name of this argument.
Argument<String> arg = Argument.of("test-name", "value");
String name = arg.getName(); // Returns "test-name"
getPayload()
Returns the payload value.
Argument<Config> arg = Argument.of("config", new Config());
Config config = arg.getPayload();
hasPayload()
Checks if the payload is non-null.
Argument<String> arg = Argument.of("name", null);
boolean has = arg.hasPayload(); // Returns false
getPayloadAs(Class)
Casts the payload to a specific type.
Argument<?> arg = Argument.of("name", new DatabaseConfig());
DatabaseConfig config = arg.getPayloadAs(DatabaseConfig.class);
Factory Methods
Generic Arguments
Argument<T> of(String name, T payload)
Creates a named argument with a payload.
Primitive Type Factory Methods
Argument<Boolean> ofBoolean(boolean value)
Argument<Integer> ofInt(int value)
Argument<Long> ofLong(long value)
Argument<Double> ofDouble(double value)
Argument<String> ofString(String value)
BigDecimal and BigInteger
Argument<BigInteger> ofBigInteger(String value)
Argument<BigDecimal> ofBigDecimal(String value)
See Also
- Arguments - Using arguments in tests
- Argument Suppliers - Providing arguments
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.