update existing enums that have an 'unknown' value to not throw on unrecognized values
Showing
8 changed files
with
16 additions
and
16 deletions
| @@ -20,7 +20,7 @@ enum AddressType { | @@ -20,7 +20,7 @@ enum AddressType { | ||
| 20 | case 2: | 20 | case 2: |
| 21 | return AddressType.home; | 21 | return AddressType.home; |
| 22 | default: | 22 | default: |
| 23 | - throw ArgumentError.value(value, 'value', 'Invalid raw value.'); | 23 | + return AddressType.unknown; |
| 24 | } | 24 | } |
| 25 | } | 25 | } |
| 26 | 26 |
| @@ -70,7 +70,7 @@ enum BarcodeType { | @@ -70,7 +70,7 @@ enum BarcodeType { | ||
| 70 | case 12: | 70 | case 12: |
| 71 | return BarcodeType.driverLicense; | 71 | return BarcodeType.driverLicense; |
| 72 | default: | 72 | default: |
| 73 | - throw ArgumentError.value(value, 'value', 'Invalid raw value.'); | 73 | + return BarcodeType.unknown; |
| 74 | } | 74 | } |
| 75 | } | 75 | } |
| 76 | 76 |
| @@ -17,12 +17,12 @@ void main() { | @@ -17,12 +17,12 @@ void main() { | ||
| 17 | } | 17 | } |
| 18 | }); | 18 | }); |
| 19 | 19 | ||
| 20 | - test('invalid raw value throws argument error', () { | 20 | + test('invalid raw value returns AddressType.unknown', () { |
| 21 | const int negative = -1; | 21 | const int negative = -1; |
| 22 | const int outOfRange = 3; | 22 | const int outOfRange = 3; |
| 23 | 23 | ||
| 24 | - expect(() => AddressType.fromRawValue(negative), throwsArgumentError); | ||
| 25 | - expect(() => AddressType.fromRawValue(outOfRange), throwsArgumentError); | 24 | + expect(() => AddressType.fromRawValue(negative), AddressType.unknown); |
| 25 | + expect(() => AddressType.fromRawValue(outOfRange), AddressType.unknown); | ||
| 26 | }); | 26 | }); |
| 27 | 27 | ||
| 28 | test('can be converted to raw value', () { | 28 | test('can be converted to raw value', () { |
| @@ -27,12 +27,12 @@ void main() { | @@ -27,12 +27,12 @@ void main() { | ||
| 27 | } | 27 | } |
| 28 | }); | 28 | }); |
| 29 | 29 | ||
| 30 | - test('invalid raw value throws argument error', () { | 30 | + test('invalid raw value returns BarcodeType.unknown', () { |
| 31 | const int negative = -1; | 31 | const int negative = -1; |
| 32 | const int outOfRange = 13; | 32 | const int outOfRange = 13; |
| 33 | 33 | ||
| 34 | - expect(() => BarcodeType.fromRawValue(negative), throwsArgumentError); | ||
| 35 | - expect(() => BarcodeType.fromRawValue(outOfRange), throwsArgumentError); | 34 | + expect(() => BarcodeType.fromRawValue(negative), BarcodeType.unknown); |
| 35 | + expect(() => BarcodeType.fromRawValue(outOfRange), BarcodeType.unknown); | ||
| 36 | }); | 36 | }); |
| 37 | 37 | ||
| 38 | test('can be converted to raw value', () { | 38 | test('can be converted to raw value', () { |
| @@ -17,12 +17,12 @@ void main() { | @@ -17,12 +17,12 @@ void main() { | ||
| 17 | } | 17 | } |
| 18 | }); | 18 | }); |
| 19 | 19 | ||
| 20 | - test('invalid raw value throws argument error', () { | 20 | + test('invalid raw value returns EmailType.unknown', () { |
| 21 | const int negative = -1; | 21 | const int negative = -1; |
| 22 | const int outOfRange = 3; | 22 | const int outOfRange = 3; |
| 23 | 23 | ||
| 24 | - expect(() => EmailType.fromRawValue(negative), throwsArgumentError); | ||
| 25 | - expect(() => EmailType.fromRawValue(outOfRange), throwsArgumentError); | 24 | + expect(() => EmailType.fromRawValue(negative), EmailType.unknown); |
| 25 | + expect(() => EmailType.fromRawValue(outOfRange), EmailType.unknown); | ||
| 26 | }); | 26 | }); |
| 27 | 27 | ||
| 28 | test('can be converted to raw value', () { | 28 | test('can be converted to raw value', () { |
| @@ -19,12 +19,12 @@ void main() { | @@ -19,12 +19,12 @@ void main() { | ||
| 19 | } | 19 | } |
| 20 | }); | 20 | }); |
| 21 | 21 | ||
| 22 | - test('invalid raw value throws argument error', () { | 22 | + test('invalid raw value returns PhoneType.unknown', () { |
| 23 | const int negative = -1; | 23 | const int negative = -1; |
| 24 | const int outOfRange = 5; | 24 | const int outOfRange = 5; |
| 25 | 25 | ||
| 26 | - expect(() => PhoneType.fromRawValue(negative), throwsArgumentError); | ||
| 27 | - expect(() => PhoneType.fromRawValue(outOfRange), throwsArgumentError); | 26 | + expect(() => PhoneType.fromRawValue(negative), PhoneType.unknown); |
| 27 | + expect(() => PhoneType.fromRawValue(outOfRange), PhoneType.unknown); | ||
| 28 | }); | 28 | }); |
| 29 | 29 | ||
| 30 | test('can be converted to raw value', () { | 30 | test('can be converted to raw value', () { |
-
Please register or login to post a comment