| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_BUFFER_SIZE
The default buffer size in bytes.
|
static int |
DEFAULT_TIMEOUT_MS
The default timeout value of 30000 milliseconds.
|
| Constructor and Description |
|---|
ExpectBuilder()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
Expect |
build()
Creates a ready to use
Expect instance. |
ExpectBuilder |
withAutoFlushEcho(boolean autoFlushEcho)
Enables automatic flushing of the echo input and output after each match operation
if the given echo object(s) implements
Flushable interface. |
ExpectBuilder |
withBufferSize(int bufferSize)
Sets the size of the input buffer in bytes.
|
ExpectBuilder |
withCharset(Charset charset)
Sets the character encoding used to covert bytes when working with byte streams.
|
ExpectBuilder |
withCombineInputs(boolean combineInputs)
Combines input streaming data into one input.
|
ExpectBuilder |
withEchoInput(Appendable firstInput,
Appendable... otherInputs)
Enables printing of all the received data.
|
ExpectBuilder |
withEchoOutput(Appendable echoOutput)
Enables printing of all the sent data.
|
ExpectBuilder |
withEchoOutput(EchoOutput echoOutput)
Deprecated.
|
ExpectBuilder |
withErrorOnTimeout(boolean errorOnTimeout)
Deprecated.
This method is deprecated and will be removed. Use
withExceptionOnFailure() instead. |
ExpectBuilder |
withExceptionOnFailure()
Enables throwing an
ExpectIOException if an expect operation
was not successful. |
ExpectBuilder |
withExecutor(ExecutorService executor)
Set the executor used to create internal thread.
|
ExpectBuilder |
withInfiniteTimeout()
Sets the default timeout to infinity.
|
ExpectBuilder |
withInputFilters(Filter filter,
Filter... moreFilters)
Sets a filter for the input.
|
ExpectBuilder |
withInputs(InputStream... inputs)
Sets the input streams for expect operations.
|
ExpectBuilder |
withLineSeparator(String lineSeparator)
Sets the line separator used by the
Expect.sendLine() method. |
ExpectBuilder |
withOutput(OutputStream output)
Sets the output stream where
Expect sends command to. |
ExpectBuilder |
withTimeout(long duration,
TimeUnit unit)
Sets the default timeout in the given unit for expect operations.
|
public static final int DEFAULT_TIMEOUT_MS
public static final int DEFAULT_BUFFER_SIZE
public final ExpectBuilder withOutput(OutputStream output)
Expect sends command to. Optional,
if not set then all the
send method are expected to throw NullPointerException.output - the output streampublic final ExpectBuilder withInputs(InputStream... inputs)
inputs - the input streampublic final ExpectBuilder withTimeout(long duration, TimeUnit unit)
duration - the timeout valueunit - the time unitIllegalArgumentException - if the timeout <= 0public final ExpectBuilder withInfiniteTimeout()
@Deprecated public final ExpectBuilder withEchoOutput(EchoOutput echoOutput)
echoOutput - an instance of echo output. Refer to .EchoAdapters for adapter
static methods for common use cases.public final ExpectBuilder withEchoOutput(Appendable echoOutput)
echoOutput - where to echo the sent data.public final ExpectBuilder withEchoInput(Appendable firstInput, Appendable... otherInputs)
firstInput is specified then the data received from all the inputs is
echoed to it.
The build method throws an IllegalArgumentException if the number of the
otherInputs
parameters does not correspond to the number of the input streams. That is,
if otherInputs
is specified, the number of them must be equal to the number of inputs minus 1.
The byte data received from the input streams is converted to strings using the
builder's charset. See withCharset(java.nio.charset.Charset) for
more information.firstInput - where to echo the received data for the first input. If otherInputs are empty, then
all the data will be echoed to it.otherInputs - where to echo the received data for other inputs.public final ExpectBuilder withCharset(Charset charset)
Charset.defaultCharset.charset - the charsetpublic final ExpectBuilder withInputFilters(Filter filter, Filter... moreFilters)
filter - the filtermoreFilters - more filter to apply. if specified then all the filters are combined
using the
Filters.chain(Filter...) method.s@Deprecated public final ExpectBuilder withErrorOnTimeout(boolean errorOnTimeout)
withExceptionOnFailure() instead.AssertionError if any expect operation times out.
Optional, disabled by default.errorOnTimeout - the error flagpublic final ExpectBuilder withExceptionOnFailure()
ExpectIOException if an expect operation
was not successful. Optional, disabled by default.public final ExpectBuilder withLineSeparator(String lineSeparator)
Expect.sendLine() method. Optional, default
is '\n'.
The default line separator was intentionally made non-system specific to avoid issues like
when the tool is running on Windows and sending CRLF to a Unix system which threats
them as two new lines.
lineSeparator - the line separatorpublic final ExpectBuilder withBufferSize(int bufferSize)
bufferSize - the buffer sizeIllegalArgumentException - if bufferSize is <= 0public final ExpectBuilder withAutoFlushEcho(boolean autoFlushEcho)
Flushable interface.autoFlushEcho - the auto flushing flag.public final ExpectBuilder withCombineInputs(boolean combineInputs)
combineInputs - the combine inputs flag.public final ExpectBuilder withExecutor(ExecutorService executor)
executor - the executor service to use.public final Expect build() throws IOException
Expect instance.
This method creates an instance and starts background threads that receive input data
through NIO pipes. The
created instance must be disposed after use by calling the .Expect#close() method,
The instance is not thread safe and intended to be used in a single thread.IOException - if I/O error occursIllegalStateException - if the inputs are incorrectCopyright © 2014–2018 Alexey Gavrilov and contributors. All rights reserved.