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 factory for Extractor instances.

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

Public methods

static void

Asserts that an extractor behaves correctly given valid input data.

static void
assertAllBehaviors(
    ExtractorAsserts.ExtractorFactory factory,
    String file,
    String dumpFilesPrefix
)

Asserts that an extractor behaves correctly given valid input data:

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 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.

Public methods

assertAllBehaviors

public static void assertAllBehaviors(
    ExtractorAsserts.ExtractorFactory factory,
    String file
)

Asserts that an extractor behaves correctly given valid input data.

  • Calls seek and release without calling init to check these calls do not fail.
  • Calls assertOutput with all possible combinations of "simulate" parameters.
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.

Throws
java.io.IOException

If reading from the input fails.

assertAllBehaviors

public static void assertAllBehaviors(
    ExtractorAsserts.ExtractorFactory factory,
    String file,
    String dumpFilesPrefix
)

Asserts that an extractor behaves correctly given valid input data:

  • Calls seek and release without calling init to check these calls do not fail.
  • Calls assertOutput with all possible combinations of "simulate" parameters.
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.

String dumpFilesPrefix

The dump files prefix appended to the dump files path.

Throws
java.io.IOException

If reading from the input fails.

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 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.

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.