Class OptionalArg
- java.lang.Object
-
- com.lmax.simpledsl.api.SimpleDslArg
-
- com.lmax.simpledsl.api.OptionalArg
-
- All Implemented Interfaces:
DslArg
public class OptionalArg extends SimpleDslArg
An optional argument.Callers may omit this argument and the call is still considered valid. When provided, the argument name must be specified, e.g.
"firstName: Joan". Optional argument can have a default value that is used when no other value is provided.By default, only a single value is allowed. Multiple values can be allowed by calling
SimpleDslArg.setAllowMultipleValues().Optional arguments are useful as a way of reducing boilerplate in tests by providing default settings and as a way to optionally assert behaviours or values. For example providing a method that checks the first name and/or the last name:
DslParams params = new DslParams(args, new OptionalParam("firstName"), new OptionalParam("lastName")); params.valueAsOptional("firstName").ifPresent(driver::checkFirstName); params.valueAsOptional("lastName").ifPresent(driver::checkLastName);Selective assertions like this help tests be flexible to changes outside the area they intend to test by only asserting on the values that are actually relevant.
- See Also:
DslValues.valueAsOptional(String)
-
-
Constructor Summary
Constructors Constructor Description OptionalArg(java.lang.String name)
-
Method Summary
-
Methods inherited from class com.lmax.simpledsl.api.SimpleDslArg
getAllowedValues, getDefaultValue, getMultipleValueSeparator, getName, isAllowMultipleValues, isRequired, setAllowedValues, setAllowedValues, setAllowMultipleValues, setAllowMultipleValues, setDefault
-
-