pkg/oauth2 bringing tests into 2014

R=nweiz@google.com

Review URL: https://codereview.chromium.org//187843006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@33357 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/pubspec.yaml b/pubspec.yaml
index 74ee771..c3dad6e 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,14 +1,14 @@
 name: oauth2
-version: 0.9.1
-author: "Dart Team <misc@dartlang.org>"
+version: 0.9.2-dev
+author: Dart Team <misc@dartlang.org>
 homepage: http://www.dartlang.org
 description: >
   A client library for authenticating with a remote service via OAuth2 on
   behalf of a user, and making authorized HTTP requests with the user's
   OAuth2 credentials. Currently only works with dart:io.
-dependencies:
-  http: ">=0.9.2 <0.10.0"
-dev_dependencies:
-  unittest: ">=0.9.0 <0.10.0"
 environment:
-  sdk: ">=0.8.10+6 <2.0.0"
+  sdk: '>=1.0.0 <2.0.0'
+dependencies:
+  http: '>=0.9.2 <0.10.0'
+dev_dependencies:
+  unittest: '>=0.9.0 <0.11.0'
diff --git a/test/authorization_code_grant_test.dart b/test/authorization_code_grant_test.dart
index 85c54e7..2c3265e 100644
--- a/test/authorization_code_grant_test.dart
+++ b/test/authorization_code_grant_test.dart
@@ -29,12 +29,6 @@
       httpClient: client);
 }
 
-void expectFutureThrows(future, predicate) {
-  future.catchError(expectAsync1((error) {
-    expect(predicate(error), isTrue);
-  }));
-}
-
 void main() {
   group('.getAuthorizationUrl', () {
     setUp(createGrant);
@@ -96,46 +90,41 @@
     setUp(createGrant);
 
     test("can't be called before .getAuthorizationUrl", () {
-      expectFutureThrows(grant.handleAuthorizationResponse({}),
-                         (e) => e is StateError);
+      expect(grant.handleAuthorizationResponse({}), throwsStateError);
     });
 
     test("can't be called twice", () {
       grant.getAuthorizationUrl(redirectUrl);
-      expectFutureThrows(
-          grant.handleAuthorizationResponse({'code': 'auth code'}),
-          (e) => e is FormatException);
-      expectFutureThrows(
-          grant.handleAuthorizationResponse({'code': 'auth code'}),
-          (e) => e is StateError);
+      expect(grant.handleAuthorizationResponse({'code': 'auth code'}),
+          throwsFormatException);
+      expect(grant.handleAuthorizationResponse({'code': 'auth code'}),
+          throwsStateError);
     });
 
     test('must have a state parameter if the authorization URL did', () {
       grant.getAuthorizationUrl(redirectUrl, state: 'state');
-      expectFutureThrows(
-          grant.handleAuthorizationResponse({'code': 'auth code'}),
-          (e) => e is FormatException);
+      expect(grant.handleAuthorizationResponse({'code': 'auth code'}),
+          throwsFormatException);
     });
 
     test('must have the same state parameter the authorization URL did', () {
       grant.getAuthorizationUrl(redirectUrl, state: 'state');
-      expectFutureThrows(grant.handleAuthorizationResponse({
+      expect(grant.handleAuthorizationResponse({
         'code': 'auth code',
         'state': 'other state'
-      }), (e) => e is FormatException);
+      }), throwsFormatException);
     });
 
     test('must have a code parameter', () {
       grant.getAuthorizationUrl(redirectUrl);
-      expectFutureThrows(grant.handleAuthorizationResponse({}),
-                         (e) => e is FormatException);
+      expect(grant.handleAuthorizationResponse({}), throwsFormatException);
     });
 
     test('with an error parameter throws an AuthorizationException', () {
       grant.getAuthorizationUrl(redirectUrl);
-      expectFutureThrows(
+      expect(
           grant.handleAuthorizationResponse({'error': 'invalid_request'}),
-          (e) => e is oauth2.AuthorizationException);
+          throwsA((e) => e is oauth2.AuthorizationException));
     });
 
     test('sends an authorization code request', () {
@@ -157,10 +146,9 @@
         }), 200, headers: {'content-type': 'application/json'}));
       });
 
-      grant.handleAuthorizationResponse({'code': 'auth code'})
-          .then(expectAsync1((client) {
-            expect(client.credentials.accessToken, equals('access token'));
-          }));
+      expect(grant.handleAuthorizationResponse({'code': 'auth code'})
+            .then((client) => client.credentials.accessToken),
+          completion(equals('access token')));
     });
   });
 
@@ -168,18 +156,13 @@
     setUp(createGrant);
 
     test("can't be called before .getAuthorizationUrl", () {
-      expectFutureThrows(
-          grant.handleAuthorizationCode('auth code'),
-          (e) => e is StateError);
+      expect(grant.handleAuthorizationCode('auth code'), throwsStateError);
     });
 
     test("can't be called twice", () {
       grant.getAuthorizationUrl(redirectUrl);
-      expectFutureThrows(
-          grant.handleAuthorizationCode('auth code'),
-          (e) => e is FormatException);
-      expectFutureThrows(grant.handleAuthorizationCode('auth code'),
-                         (e) => e is StateError);
+      expect(grant.handleAuthorizationCode('auth code'), throwsFormatException);
+      expect(grant.handleAuthorizationCode('auth code'), throwsStateError);
     });
 
     test('sends an authorization code request', () {
diff --git a/test/client_test.dart b/test/client_test.dart
index 56dd789..ad552c0 100644
--- a/test/client_test.dart
+++ b/test/client_test.dart
@@ -81,8 +81,7 @@
       httpClient.expectRequest((request) {
         expect(request.method, equals('GET'));
         expect(request.url.toString(), equals(requestUri.toString()));
-        expect(request.headers['authorization'],
-            equals('Bearer access token'));
+        expect(request.headers['authorization'], equals('Bearer access token'));
 
         return new Future.value(new http.Response('good job', 200));
       });
@@ -130,8 +129,7 @@
       httpClient.expectRequest((request) {
         expect(request.method, equals('GET'));
         expect(request.url.toString(), equals(requestUri.toString()));
-        expect(request.headers['authorization'],
-            equals('Bearer access token'));
+        expect(request.headers['authorization'], equals('Bearer access token'));
 
         var authenticate = 'Bearer error="invalid_token", error_description='
             '"Something is terribly wrong."';
diff --git a/test/credentials_test.dart b/test/credentials_test.dart
index f3e303b..2ce9ec4 100644
--- a/test/credentials_test.dart
+++ b/test/credentials_test.dart
@@ -43,19 +43,17 @@
     var credentials = new oauth2.Credentials(
         'access token', null, tokenEndpoint);
     expect(credentials.canRefresh, false);
-    credentials.refresh('identifier', 'secret', httpClient: httpClient)
-        .catchError(expectAsync1((error) {
-          expect(error is StateError, isTrue);
-        }));
+
+    expect(credentials.refresh('identifier', 'secret', httpClient: httpClient),
+        throwsStateError);
   });
 
   test("can't refresh without a token endpoint", () {
     var credentials = new oauth2.Credentials('access token', 'refresh token');
     expect(credentials.canRefresh, false);
-    credentials.refresh('identifier', 'secret', httpClient: httpClient)
-        .catchError(expectAsync1((error) {
-          expect(error is StateError, isTrue);
-        }));
+
+    expect(credentials.refresh('identifier', 'secret', httpClient: httpClient),
+        throwsStateError);
   });
 
   test("can refresh with a refresh token and a token endpoint", () {
diff --git a/test/handle_access_token_response_test.dart b/test/handle_access_token_response_test.dart
index c362868..d97ef38 100644
--- a/test/handle_access_token_response_test.dart
+++ b/test/handle_access_token_response_test.dart
@@ -38,8 +38,7 @@
     });
 
     test('with an unexpected code causes a FormatException', () {
-      expect(() => handleError(statusCode: 500),
-          throwsFormatException);
+      expect(() => handleError(statusCode: 500), throwsFormatException);
     });
 
     test('with no content-type causes a FormatException', () {
@@ -60,13 +59,11 @@
     });
 
     test('with invalid JSON causes a FormatException', () {
-      expect(() => handleError(body: 'not json'),
-          throwsFormatException);
+      expect(() => handleError(body: 'not json'), throwsFormatException);
     });
 
     test('with a non-string error causes a FormatException', () {
-      expect(() => handleError(body: '{"error": 12}'),
-          throwsFormatException);
+      expect(() => handleError(body: '{"error": 12}'), throwsFormatException);
     });
 
     test('with a non-string error_description causes a FormatException', () {