|
| 1 | +import 'package:sentry/src/hub.dart'; |
| 2 | +import 'package:test/expect.dart'; |
| 3 | +import 'package:test/scaffolding.dart'; |
| 4 | + |
| 5 | +void main() { |
| 6 | + late Fixture fixture; |
| 7 | + |
| 8 | + setUp(() { |
| 9 | + fixture = Fixture(); |
| 10 | + }); |
| 11 | + |
| 12 | + group('unsupported throwable types', () { |
| 13 | + test('wrapped string throwable does not throw when expanding', () async { |
| 14 | + final throwableHandler = fixture.sut; |
| 15 | + final unsupportedThrowable = 'test throwable'; |
| 16 | + final wrappedThrowable = |
| 17 | + throwableHandler.wrapIfUnsupportedType(unsupportedThrowable); |
| 18 | + |
| 19 | + expect(() { |
| 20 | + fixture.expando[wrappedThrowable]; |
| 21 | + }, returnsNormally); |
| 22 | + }); |
| 23 | + |
| 24 | + test('wrapped int throwable does not throw when expanding', () async { |
| 25 | + final throwableHandler = fixture.sut; |
| 26 | + final unsupportedThrowable = 1; |
| 27 | + final wrappedThrowable = |
| 28 | + throwableHandler.wrapIfUnsupportedType(unsupportedThrowable); |
| 29 | + |
| 30 | + expect(() { |
| 31 | + fixture.expando[wrappedThrowable]; |
| 32 | + }, returnsNormally); |
| 33 | + }); |
| 34 | + |
| 35 | + test('wrapped double throwable does not throw when expanding', () async { |
| 36 | + final throwableHandler = fixture.sut; |
| 37 | + final unsupportedThrowable = 1.0; |
| 38 | + final wrappedThrowable = |
| 39 | + throwableHandler.wrapIfUnsupportedType(unsupportedThrowable); |
| 40 | + |
| 41 | + expect(() { |
| 42 | + fixture.expando[wrappedThrowable]; |
| 43 | + }, returnsNormally); |
| 44 | + }); |
| 45 | + |
| 46 | + test('wrapped bool throwable does not throw when expanding', () async { |
| 47 | + final throwableHandler = fixture.sut; |
| 48 | + final unsupportedThrowable = true; |
| 49 | + final wrappedThrowable = |
| 50 | + throwableHandler.wrapIfUnsupportedType(unsupportedThrowable); |
| 51 | + |
| 52 | + expect(() { |
| 53 | + fixture.expando[wrappedThrowable]; |
| 54 | + }, returnsNormally); |
| 55 | + }); |
| 56 | + |
| 57 | + test( |
| 58 | + 'creating multiple instances of string wrapped exceptions accesses the same expando value', |
| 59 | + () async { |
| 60 | + final unsupportedThrowable = 'test throwable'; |
| 61 | + final throwableHandler = fixture.sut; |
| 62 | + |
| 63 | + final first = |
| 64 | + throwableHandler.wrapIfUnsupportedType(unsupportedThrowable); |
| 65 | + fixture.expando[first] = 1; |
| 66 | + |
| 67 | + final second = |
| 68 | + throwableHandler.wrapIfUnsupportedType(unsupportedThrowable); |
| 69 | + expect(fixture.expando[second], 1); |
| 70 | + fixture.expando[second] = 2.0; |
| 71 | + |
| 72 | + final third = |
| 73 | + throwableHandler.wrapIfUnsupportedType(unsupportedThrowable); |
| 74 | + expect(fixture.expando[third], 2.0); |
| 75 | + }); |
| 76 | + }); |
| 77 | + |
| 78 | + group('supported throwable type', () { |
| 79 | + test('does not wrap exception if it is a supported type', () async { |
| 80 | + final supportedThrowable = Exception('test throwable'); |
| 81 | + final result = fixture.sut.wrapIfUnsupportedType(supportedThrowable); |
| 82 | + |
| 83 | + expect(result, supportedThrowable); |
| 84 | + }); |
| 85 | + }); |
| 86 | +} |
| 87 | + |
| 88 | +class Fixture { |
| 89 | + final expando = Expando(); |
| 90 | + |
| 91 | + UnsupportedThrowablesHandler get sut => UnsupportedThrowablesHandler(); |
| 92 | +} |
0 commit comments