1
+ // ignore so the test is easier to read.
2
+ // ignore_for_file: avoid_redundant_argument_values
3
+
1
4
import 'dart:io' ;
2
5
3
6
import 'package:chopper/chopper.dart' ;
@@ -28,7 +31,7 @@ void main() {
28
31
29
32
test ('only refresh on unauthorized and token' , () async {
30
33
// arrange
31
- when (() => mockOAuthChopper.refresh () ).thenAnswer ((_) async => testToken);
34
+ when (mockOAuthChopper.refresh).thenAnswer ((_) async => testToken);
32
35
when (() => mockOAuthChopper.token).thenAnswer ((_) async => testToken);
33
36
final authenticator = OAuthAuthenticator (mockOAuthChopper, null );
34
37
final expected = {'Authorization' : 'Bearer token' };
@@ -38,13 +41,13 @@ void main() {
38
41
await authenticator.authenticate (testRequest, unauthorizedResponse);
39
42
40
43
// assert
41
- verify (() => mockOAuthChopper.refresh () ).called (1 );
44
+ verify (mockOAuthChopper.refresh).called (1 );
42
45
expect (result? .headers, expected);
43
46
});
44
47
45
48
test ("Don't refresh on authorized" , () async {
46
49
// arrange
47
- when (() => mockOAuthChopper.refresh () ).thenAnswer ((_) async => testToken);
50
+ when (mockOAuthChopper.refresh).thenAnswer ((_) async => testToken);
48
51
when (() => mockOAuthChopper.token).thenAnswer ((_) async => testToken);
49
52
final authenticator = OAuthAuthenticator (mockOAuthChopper, null );
50
53
@@ -53,13 +56,13 @@ void main() {
53
56
await authenticator.authenticate (testRequest, authorizedResponse);
54
57
55
58
// assert
56
- verifyNever (() => mockOAuthChopper.refresh () );
59
+ verifyNever (mockOAuthChopper.refresh);
57
60
expect (result, null );
58
61
});
59
62
60
63
test ("Don't refresh on token not available" , () async {
61
64
// arrange
62
- when (() => mockOAuthChopper.refresh () ).thenAnswer ((_) async => testToken);
65
+ when (mockOAuthChopper.refresh).thenAnswer ((_) async => testToken);
63
66
when (() => mockOAuthChopper.token).thenAnswer ((_) async => null );
64
67
final authenticator = OAuthAuthenticator (mockOAuthChopper, null );
65
68
@@ -68,13 +71,13 @@ void main() {
68
71
await authenticator.authenticate (testRequest, unauthorizedResponse);
69
72
70
73
// assert
71
- verifyNever (() => mockOAuthChopper.refresh () );
74
+ verifyNever (mockOAuthChopper.refresh);
72
75
expect (result, null );
73
76
});
74
77
75
78
test ("Don't add headers on failed refresh" , () async {
76
79
// arrange
77
- when (() => mockOAuthChopper.refresh () ).thenAnswer ((_) async => null );
80
+ when (mockOAuthChopper.refresh).thenAnswer ((_) async => null );
78
81
when (() => mockOAuthChopper.token).thenAnswer ((_) async => testToken);
79
82
final authenticator = OAuthAuthenticator (mockOAuthChopper, null );
80
83
@@ -83,31 +86,34 @@ void main() {
83
86
await authenticator.authenticate (testRequest, unauthorizedResponse);
84
87
85
88
// assert
86
- verify (() => mockOAuthChopper.refresh () ).called (1 );
89
+ verify (mockOAuthChopper.refresh).called (1 );
87
90
expect (result, null );
88
91
});
89
92
90
- test (" Exception thrown if onError is null" , () async {
93
+ test (' Exception thrown if onError is null' , () async {
91
94
// arrange
92
- when (() => mockOAuthChopper.refresh ()) .thenThrow (FormatException ('failed' ));
95
+ when (mockOAuthChopper.refresh) .thenThrow (const FormatException ('failed' ));
93
96
when (() => mockOAuthChopper.token).thenAnswer ((_) async => testToken);
94
97
final authenticator = OAuthAuthenticator (mockOAuthChopper, null );
95
98
96
99
// act
97
100
// assert
98
101
expect (
99
- () async =>
100
- await authenticator.authenticate (testRequest, unauthorizedResponse),
101
- throwsFormatException);
102
+ () async =>
103
+ await authenticator.authenticate (testRequest, unauthorizedResponse),
104
+ throwsFormatException,
105
+ );
102
106
});
103
107
104
- test (" Exception not thrown if onError is supplied" , () async {
108
+ test (' Exception not thrown if onError is supplied' , () async {
105
109
// arrange
106
110
FormatException ? result;
107
- when (() => mockOAuthChopper.refresh ()) .thenThrow (FormatException ('failed' ));
111
+ when (mockOAuthChopper.refresh) .thenThrow (const FormatException ('failed' ));
108
112
when (() => mockOAuthChopper.token).thenAnswer ((_) async => testToken);
109
113
final authenticator = OAuthAuthenticator (
110
- mockOAuthChopper, (e, s) => result = e as FormatException );
114
+ mockOAuthChopper,
115
+ (e, s) => result = e as FormatException ,
116
+ );
111
117
112
118
// act
113
119
final responseResult =
0 commit comments