ExtractorAsserts


@UnstableApi
public final class ExtractorAsserts


Assertion methods for Extractor.

Summary

Nested types

A config for the assertions made (e.g. dump file location).

Builder for AssertionConfig instances.

A TestParameterValuesProvider that provides SimulationConfig objects from configs to exercise different extractor paths.

A factory for Extractor instances.

A config of different environments to simulate and extractor behaviours to test.

Constants

static final int

Public methods

static void
assertBehavior(
    ExtractorAsserts.ExtractorFactory factory,
    String file,
    ExtractorAsserts.SimulationConfig simulationConfig
)

Asserts that an extractor consumes valid input data successfully under the conditions specified by simulationConfig.

static void
assertBehavior(
    ExtractorAsserts.ExtractorFactory factory,
    String file,
    ExtractorAsserts.AssertionConfig assertionConfig,
    ExtractorAsserts.SimulationConfig simulationConfig
)

Asserts that an extractor consumes valid input data successfully under the conditions specified by simulationConfig.

static void
assertBehavior(
    ExtractorAsserts.ExtractorFactory factory,
    String file,
    int peekLimit,
    ExtractorAsserts.SimulationConfig simulationConfig
)

Asserts that an extractor consumes valid input data successfully under the conditions specified by simulationConfig.

static void
assertBehavior(
    ExtractorAsserts.ExtractorFactory factory,
    String file,
    int peekLimit,
    ExtractorAsserts.AssertionConfig assertionConfig,
    ExtractorAsserts.SimulationConfig simulationConfig
)

Asserts that an extractor consumes valid input data successfully under the conditions specified by simulationConfig.

static void
assertSniff(
    Extractor extractor,
    FakeExtractorInput input,
    boolean expectedResult
)

Asserts that sniff returns the expectedResult for a given input, retrying repeatedly when SimulatedIOException is thrown.

static ImmutableList<ExtractorAsserts.SimulationConfig>

Returns a list of arrays containing SimulationConfig objects to exercise different extractor paths.

static List<Object[]>

Returns a list of arrays containing SimulationConfig objects to exercise different extractor paths in which the input is not sniffed.

Constants

PEEK_LIMIT_FAIL_WITH_MAX

public static final int PEEK_LIMIT_FAIL_WITH_MAX = -2

Public methods

assertBehavior

public static void assertBehavior(
    ExtractorAsserts.ExtractorFactory factory,
    String file,
    ExtractorAsserts.SimulationConfig simulationConfig
)

Asserts that an extractor consumes valid input data successfully under the conditions specified by simulationConfig.

The output of the extractor is compared against prerecorded dump files whose names are derived from the file parameter as specified in the docs for dumpFilesPrefix.

Parameters
ExtractorAsserts.ExtractorFactory factory

An ExtractorFactory which creates instances of the Extractor class which is to be tested.

String file

The path to the input sample.

ExtractorAsserts.SimulationConfig simulationConfig

Details on the environment to simulate and behaviours to assert.

Throws
java.io.IOException

If reading from the input fails.

assertBehavior

public static void assertBehavior(
    ExtractorAsserts.ExtractorFactory factory,
    String file,
    ExtractorAsserts.AssertionConfig assertionConfig,
    ExtractorAsserts.SimulationConfig simulationConfig
)

Asserts that an extractor consumes valid input data successfully under the conditions specified by simulationConfig.

The output of the extractor is compared against prerecorded dump files.

Parameters
ExtractorAsserts.ExtractorFactory factory

An ExtractorFactory which creates instances of the Extractor class which is to be tested.

String file

The input file to pass to the extractor.

ExtractorAsserts.AssertionConfig assertionConfig

Details of how to read and process the source and dump files.

ExtractorAsserts.SimulationConfig simulationConfig

Details on the environment to simulate and behaviours to assert.

Throws
java.io.IOException

If reading from the input fails.

assertBehavior

public static void assertBehavior(
    ExtractorAsserts.ExtractorFactory factory,
    String file,
    int peekLimit,
    ExtractorAsserts.SimulationConfig simulationConfig
)

Asserts that an extractor consumes valid input data successfully under the conditions specified by simulationConfig.

The output of the extractor is compared against prerecorded dump files whose names are derived from the file parameter as specified in the docs for dumpFilesPrefix.

Parameters
ExtractorAsserts.ExtractorFactory factory

An ExtractorFactory which creates instances of the Extractor class which is to be tested.

String file

The path to the input sample.

int peekLimit

The limit that getPeekPosition is permitted to advance ahead of getPosition. LENGTH_UNSET disables enforcement of this limit. PEEK_LIMIT_FAIL_WITH_MAX forces the test to fail at the end and print the max limit that was used (which can be helpful when setting this value).

ExtractorAsserts.SimulationConfig simulationConfig

Details on the environment to simulate and behaviours to assert.

Throws
java.io.IOException

If reading from the input fails.

assertBehavior

public static void assertBehavior(
    ExtractorAsserts.ExtractorFactory factory,
    String file,
    int peekLimit,
    ExtractorAsserts.AssertionConfig assertionConfig,
    ExtractorAsserts.SimulationConfig simulationConfig
)

Asserts that an extractor consumes valid input data successfully under the conditions specified by simulationConfig.

The output of the extractor is compared against prerecorded dump files.

Parameters
ExtractorAsserts.ExtractorFactory factory

An ExtractorFactory which creates instances of the Extractor class which is to be tested.

String file

The input file to pass to the extractor.

int peekLimit

The limit that getPeekPosition is permitted to advance ahead of getPosition. LENGTH_UNSET disables enforcement of this limit. PEEK_LIMIT_FAIL_WITH_MAX forces the test to fail at the end and print the max limit that was used (which can be helpful when setting this value).

ExtractorAsserts.AssertionConfig assertionConfig

Details of how to read and process the source and dump files.

ExtractorAsserts.SimulationConfig simulationConfig

Details on the environment to simulate and behaviours to assert.

Throws
java.io.IOException

If reading from the input fails.

assertSniff

public static void assertSniff(
    Extractor extractor,
    FakeExtractorInput input,
    boolean expectedResult
)

Asserts that sniff returns the expectedResult for a given input, retrying repeatedly when SimulatedIOException is thrown.

Parameters
Extractor extractor

The extractor to test.

FakeExtractorInput input

The extractor input.

boolean expectedResult

The expected return value.

Throws
java.io.IOException

If reading from the input fails.

configs

public static ImmutableList<ExtractorAsserts.SimulationConfigconfigs()

Returns a list of arrays containing SimulationConfig objects to exercise different extractor paths.

This is intended to be used from tests using ParameterizedRobolectricTestRunner or org.junit.runners.Parameterized.

configsNoSniffing

public static List<Object[]> configsNoSniffing()

Returns a list of arrays containing SimulationConfig objects to exercise different extractor paths in which the input is not sniffed.

This is intended to be used from tests using ParameterizedRobolectricTestRunner or org.junit.runners.Parameterized.