toReceivePaper<U extends Unit<Paper>, S extends UnitState<Paper, U>> static method

  1. @isTest
void toReceivePaper<U extends Unit<Paper>, S extends UnitState<Paper, U>>(
  1. String description, {
  2. required Unit<Paper> unit,
  3. void setup(
    1. S state,
    2. AgentValidator agentValidator
    )?,
  4. required Paper paper,
  5. required Agent<Paper> from(
    1. S state
    ),
  6. required dynamic expected,
  7. String? testOn,
  8. Timeout? timeout,
  9. dynamic skip,
  10. dynamic tags,
  11. Map<String, dynamic>? onPlatform,
  12. int? retry,
})

Create a test to verify the operations when U unit receive paper that reported by from with the given description. U is type the of target unit. S is the type of corresponding state of U.

unit is the Unit for testing.

setup is for initializing and preparing required dependencies for the unit. setup is called at very first. setup is optional.

paper is the paper will be reported by the child from.

from is function to return the agents that will send paper to the unit.

expected is the matcher of the expected paper.

testOn is equivalent to testOn of test in flutter_test.

timeout is equivalent to timeout of test in flutter_test.

skip is equivalent to skip of test in flutter_test.

tags is equivalent to tags of test in flutter_test.

onPlatform is equivalent to onPlatform of test in flutter_test.

retry is equivalent to retry of test in flutter_test.

Refer to TestUnit for an example.

Implementation

@isTest
static void
    toReceivePaper<U extends Unit<Paper>, S extends UnitState<Paper, U>>(
  String description, {
  required Unit unit,
  void Function(S state, AgentValidator agentValidator)? setup,
  required Paper paper,
  required Agent Function(S state) from,
  required dynamic expected,
  String? testOn,
  flutter_test.Timeout? timeout,
  dynamic skip,
  dynamic tags,
  Map<String, dynamic>? onPlatform,
  int? retry,
}) {
  final tester = UnitTestingEnvironment();

  flutter_test.test(
    description,
    () async {
      await tester.setupTestingUnit(unit);
      final state = tester.context!.state;
      final agentValidator = tester.network.agentValidator;
      final child = from(state);
      setup?.call(state, agentValidator);

      if (child is UnitAgent) {
        await child.init();
      }
      if (child is WidgetAgent) {
        await child.constructAsRoot();
      }

      final listener = AgentTestingSupporter().getReporter(child);

      final output = await listener?.getPaper(paper);

      flutter_test.expect(output, expected);
    },
    testOn: testOn,
    timeout: timeout,
    skip: skip,
    tags: tags,
    onPlatform: onPlatform,
    retry: retry,
  );
}