Fix tests for VM in checked mode.
BUG=
Review URL: https://codereview.chromium.org//11801008
git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@16689 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/test/authorization_code_grant_test.dart b/test/authorization_code_grant_test.dart
index e896dca..7614bcd 100644
--- a/test/authorization_code_grant_test.dart
+++ b/test/authorization_code_grant_test.dart
@@ -4,8 +4,9 @@
library authorization_code_grant_test;
+import 'dart:async';
import 'dart:io';
-import 'dart:json';
+import 'dart:json' as JSON;
import 'dart:uri';
import '../../unittest/lib/unittest.dart';
@@ -89,8 +90,7 @@
test("can't be called twice", () {
grant.getAuthorizationUrl(redirectUrl);
- expectFutureThrows(grant.getAuthorizationUrl(redirectUrl),
- (e) => e is StateError);
+ expect(() => grant.getAuthorizationUrl(redirectUrl), throwsStateError);
});
});
@@ -104,7 +104,9 @@
test("can't be called twice", () {
grant.getAuthorizationUrl(redirectUrl);
- grant.handleAuthorizationResponse({'code': 'auth code'});
+ expectFutureThrows(
+ grant.handleAuthorizationResponse({'code': 'auth code'}),
+ (e) => e is FormatException);
expectFutureThrows(
grant.handleAuthorizationResponse({'code': 'auth code'}),
(e) => e is StateError);
@@ -135,7 +137,7 @@
grant.getAuthorizationUrl(redirectUrl);
expectFutureThrows(
grant.handleAuthorizationResponse({'error': 'invalid_request'}),
- (e) => e is AuthorizationException);
+ (e) => e is oauth2.AuthorizationException);
});
test('sends an authorization code request', () {
@@ -157,11 +159,10 @@
}), 200, headers: {'content-type': 'application/json'}));
});
- expect(grant.handleAuthorizationResponse({'code': 'auth code'}),
- completion(predicate((client) {
+ grant.handleAuthorizationResponse({'code': 'auth code'})
+ .then(expectAsync1((client) {
expect(client.credentials.accessToken, equals('access token'));
- return true;
- })));
+ }));
});
});
@@ -169,12 +170,16 @@
setUp(createGrant);
test("can't be called before .getAuthorizationUrl", () {
- expect(grant.handleAuthorizationCode('auth code'), throwsStateError);
+ expectFutureThrows(
+ grant.handleAuthorizationCode('auth code'),
+ (e) => e is StateError);
});
test("can't be called twice", () {
grant.getAuthorizationUrl(redirectUrl);
- grant.handleAuthorizationCode('auth code');
+ expectFutureThrows(
+ grant.handleAuthorizationCode('auth code'),
+ (e) => e is FormatException);
expectFutureThrows(grant.handleAuthorizationCode('auth code'),
(e) => e is StateError);
});
diff --git a/test/client_test.dart b/test/client_test.dart
index af8e7e4..6ad7e48 100644
--- a/test/client_test.dart
+++ b/test/client_test.dart
@@ -4,8 +4,9 @@
library client_test;
+import 'dart:async';
import 'dart:io';
-import 'dart:json';
+import 'dart:json' as JSON;
import 'dart:uri';
import '../../unittest/lib/unittest.dart';
@@ -23,6 +24,12 @@
httpClient = new ExpectClient();
}
+void expectFutureThrows(future, predicate) {
+ future.catchError(expectAsync1((AsyncError e) {
+ expect(predicate(e.error), isTrue);
+ }));
+}
+
void main() {
group('with expired credentials', () {
setUp(createHttpClient);
@@ -34,7 +41,8 @@
var client = new oauth2.Client('identifier', 'secret', credentials,
httpClient: httpClient);
- expect(client.get(requestUri), throwsExpirationException);
+ expectFutureThrows(client.get(requestUri),
+ (e) => e is oauth2.ExpirationException);
});
test("that can be refreshed refreshes the credentials and sends the "
@@ -114,7 +122,8 @@
var client = new oauth2.Client('identifier', 'secret', credentials,
httpClient: httpClient);
- expect(client.refreshCredentials(), throwsStateError);
+ expectFutureThrows(client.refreshCredentials(),
+ (e) => e is StateError);
});
});
@@ -138,7 +147,8 @@
headers: {'www-authenticate': authenticate}));
});
- expect(client.read(requestUri), throwsAuthorizationException);
+ expectFutureThrows(client.read(requestUri),
+ (e) => e is oauth2.AuthorizationException);
});
test('passes through a 401 response without www-authenticate', () {