@@ -2,16 +2,14 @@ import 'dart:io';
22
33import 'package:chopper/chopper.dart' ;
44import 'package:http/http.dart' as http;
5- import 'package:mockito/annotations.dart' ;
6- import 'package:mockito/mockito.dart' ;
5+ import 'package:mocktail/mocktail.dart' ;
76import 'package:oauth2/oauth2.dart' ;
87import 'package:oauth_chopper/src/oauth_authenticator.dart' ;
98import 'package:oauth_chopper/src/oauth_chopper.dart' ;
109import 'package:oauth_chopper/src/oauth_token.dart' ;
1110import 'package:test/test.dart' ;
1211
13- @GenerateMocks ([OAuthChopper ])
14- import 'oauth_authenticator_test.mocks.dart' ;
12+ class MockOAuthChopper extends Mock implements OAuthChopper {}
1513
1614void main () {
1715 final mockOAuthChopper = MockOAuthChopper ();
@@ -22,16 +20,16 @@ void main() {
2220 expiration: DateTime (2022 , 9 , 1 ),
2321 ),
2422 );
25- final testRequest = Request ('GET' , Uri (host : 'test' ), Uri (host : 'test' ));
23+ final testRequest = Request ('GET' , Uri . parse ( 'test' ), Uri . parse ( 'test' ));
2624 final unauthorizedResponse =
2725 Response (http.Response ('body' , HttpStatus .unauthorized), 'body' );
2826 final authorizedResponse =
2927 Response (http.Response ('body' , HttpStatus .accepted), 'body' );
3028
3129 test ('only refresh on unauthorized and token' , () async {
3230 // arrange
33- when (mockOAuthChopper.refresh ()).thenAnswer ((_) async => testToken);
34- when (mockOAuthChopper.token).thenAnswer ((_) async => testToken);
31+ when (() => mockOAuthChopper.refresh ()).thenAnswer ((_) async => testToken);
32+ when (() => mockOAuthChopper.token).thenAnswer ((_) async => testToken);
3533 final authenticator = OAuthAuthenticator (mockOAuthChopper, null );
3634 final expected = {'Authorization' : 'Bearer token' };
3735
@@ -40,59 +38,59 @@ void main() {
4038 await authenticator.authenticate (testRequest, unauthorizedResponse);
4139
4240 // assert
43- verify (mockOAuthChopper.refresh ()).called (1 );
41+ verify (() => mockOAuthChopper.refresh ()).called (1 );
4442 expect (result? .headers, expected);
4543 });
4644
4745 test ("Don't refresh on authorized" , () async {
4846 // arrange
49- when (mockOAuthChopper.refresh ()).thenAnswer ((_) async => testToken);
50- when (mockOAuthChopper.token).thenAnswer ((_) async => testToken);
47+ when (() => mockOAuthChopper.refresh ()).thenAnswer ((_) async => testToken);
48+ when (() => mockOAuthChopper.token).thenAnswer ((_) async => testToken);
5149 final authenticator = OAuthAuthenticator (mockOAuthChopper, null );
5250
5351 // act
5452 final result =
5553 await authenticator.authenticate (testRequest, authorizedResponse);
5654
5755 // assert
58- verifyNever (mockOAuthChopper.refresh ());
56+ verifyNever (() => mockOAuthChopper.refresh ());
5957 expect (result, null );
6058 });
6159
6260 test ("Don't refresh on token not available" , () async {
6361 // arrange
64- when (mockOAuthChopper.refresh ()).thenAnswer ((_) async => testToken);
65- when (mockOAuthChopper.token).thenAnswer ((_) async => null );
62+ when (() => mockOAuthChopper.refresh ()).thenAnswer ((_) async => testToken);
63+ when (() => mockOAuthChopper.token).thenAnswer ((_) async => null );
6664 final authenticator = OAuthAuthenticator (mockOAuthChopper, null );
6765
6866 // act
6967 final result =
7068 await authenticator.authenticate (testRequest, unauthorizedResponse);
7169
7270 // assert
73- verifyNever (mockOAuthChopper.refresh ());
71+ verifyNever (() => mockOAuthChopper.refresh ());
7472 expect (result, null );
7573 });
7674
7775 test ("Don't add headers on failed refresh" , () async {
7876 // arrange
79- when (mockOAuthChopper.refresh ()).thenAnswer ((_) async => null );
80- when (mockOAuthChopper.token).thenAnswer ((_) async => testToken);
77+ when (() => mockOAuthChopper.refresh ()).thenAnswer ((_) async => null );
78+ when (() => mockOAuthChopper.token).thenAnswer ((_) async => testToken);
8179 final authenticator = OAuthAuthenticator (mockOAuthChopper, null );
8280
8381 // act
8482 final result =
8583 await authenticator.authenticate (testRequest, unauthorizedResponse);
8684
8785 // assert
88- verify (mockOAuthChopper.refresh ()).called (1 );
86+ verify (() => mockOAuthChopper.refresh ()).called (1 );
8987 expect (result, null );
9088 });
9189
9290 test ("Exception thrown if onError is null" , () async {
9391 // arrange
94- when (mockOAuthChopper.refresh ()).thenThrow (FormatException ('failed' ));
95- when (mockOAuthChopper.token).thenAnswer ((_) async => testToken);
92+ when (() => mockOAuthChopper.refresh ()).thenThrow (FormatException ('failed' ));
93+ when (() => mockOAuthChopper.token).thenAnswer ((_) async => testToken);
9694 final authenticator = OAuthAuthenticator (mockOAuthChopper, null );
9795
9896 // act
@@ -106,8 +104,8 @@ void main() {
106104 test ("Exception not thrown if onError is supplied" , () async {
107105 // arrange
108106 FormatException ? result;
109- when (mockOAuthChopper.refresh ()).thenThrow (FormatException ('failed' ));
110- when (mockOAuthChopper.token).thenAnswer ((_) async => testToken);
107+ when (() => mockOAuthChopper.refresh ()).thenThrow (FormatException ('failed' ));
108+ when (() => mockOAuthChopper.token).thenAnswer ((_) async => testToken);
111109 final authenticator = OAuthAuthenticator (
112110 mockOAuthChopper, (e, s) => result = e as FormatException );
113111
0 commit comments