Navaron Bracke

add DetectionSpeed test

@@ -27,7 +27,7 @@ enum DetectionSpeed { @@ -27,7 +27,7 @@ enum DetectionSpeed {
27 case 2: 27 case 2:
28 return DetectionSpeed.unrestricted; 28 return DetectionSpeed.unrestricted;
29 default: 29 default:
30 - return DetectionSpeed.normal; 30 + throw ArgumentError.value(value, 'value', 'Invalid raw value.');
31 } 31 }
32 } 32 }
33 33
  1 +import 'package:flutter_test/flutter_test.dart';
  2 +import 'package:mobile_scanner/src/enums/detection_speed.dart';
  3 +
  4 +void main() {
  5 + group('$DetectionSpeed tests', () {
  6 + test('can be created from raw value', () {
  7 + const values = <int, DetectionSpeed>{
  8 + 0: DetectionSpeed.noDuplicates,
  9 + 1: DetectionSpeed.normal,
  10 + 2: DetectionSpeed.unrestricted,
  11 + };
  12 +
  13 + for (final MapEntry<int, DetectionSpeed> entry in values.entries) {
  14 + final DetectionSpeed result = DetectionSpeed.fromRawValue(entry.key);
  15 +
  16 + expect(result, entry.value);
  17 + }
  18 + });
  19 +
  20 + test('invalid raw value throws argument error', () {
  21 + const int negative = -1;
  22 + const int outOfRange = 3;
  23 +
  24 + expect(() => DetectionSpeed.fromRawValue(negative), throwsArgumentError);
  25 + expect(() => DetectionSpeed.fromRawValue(outOfRange), throwsArgumentError);
  26 + });
  27 +
  28 + test('can be converted to raw value', () {
  29 + const values = <DetectionSpeed, int>{
  30 + DetectionSpeed.noDuplicates: 0,
  31 + DetectionSpeed.normal: 1,
  32 + DetectionSpeed.unrestricted: 2,
  33 + };
  34 +
  35 + for (final MapEntry<DetectionSpeed, int> entry in values.entries) {
  36 + final int result = entry.key.rawValue;
  37 +
  38 + expect(result, entry.value);
  39 + }
  40 + });
  41 + });
  42 +}