Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: test/credentials_test.dart

Issue 1531083002: Fix the toJson/fromJson test. (Closed) Base URL: git@github.com:dart-lang/oauth2.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:convert'; 6 import 'dart:convert';
7 7
8 import 'package:http/http.dart' as http; 8 import 'package:http/http.dart' as http;
9 import 'package:oauth2/oauth2.dart' as oauth2; 9 import 'package:oauth2/oauth2.dart' as oauth2;
10 import 'package:test/test.dart'; 10 import 'package:test/test.dart';
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 httpClient: httpClient); 224 httpClient: httpClient);
225 expect(credentials.accessToken, equals('new access token')); 225 expect(credentials.accessToken, equals('new access token'));
226 expect(credentials.refreshToken, equals('new refresh token')); 226 expect(credentials.refreshToken, equals('new refresh token'));
227 }); 227 });
228 228
229 group("fromJson", () { 229 group("fromJson", () {
230 oauth2.Credentials fromMap(Map map) => 230 oauth2.Credentials fromMap(Map map) =>
231 new oauth2.Credentials.fromJson(JSON.encode(map)); 231 new oauth2.Credentials.fromJson(JSON.encode(map));
232 232
233 test("should load the same credentials from toJson", () { 233 test("should load the same credentials from toJson", () {
234 // Round the expiration down to milliseconds since epoch, since that's
235 // what the credentials file stores. Otherwise sub-millisecond time gets
236 // in the way.
234 var expiration = new DateTime.now().subtract(new Duration(hours: 1)); 237 var expiration = new DateTime.now().subtract(new Duration(hours: 1));
238 expiration = new DateTime.fromMillisecondsSinceEpoch(
239 expiration.millisecondsSinceEpoch);
240
235 var credentials = new oauth2.Credentials( 241 var credentials = new oauth2.Credentials(
236 'access token', 242 'access token',
237 refreshToken: 'refresh token', 243 refreshToken: 'refresh token',
238 tokenEndpoint: tokenEndpoint, 244 tokenEndpoint: tokenEndpoint,
239 scopes: ['scope1', 'scope2'], 245 scopes: ['scope1', 'scope2'],
240 expiration: expiration); 246 expiration: expiration);
241 var reloaded = new oauth2.Credentials.fromJson(credentials.toJson()); 247 var reloaded = new oauth2.Credentials.fromJson(credentials.toJson());
242 248
243 expect(reloaded.accessToken, equals(credentials.accessToken)); 249 expect(reloaded.accessToken, equals(credentials.accessToken));
244 expect(reloaded.refreshToken, equals(credentials.refreshToken)); 250 expect(reloaded.refreshToken, equals(credentials.refreshToken));
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 expect(() => fromMap({"accessToken": "foo", "scopes": 12}), 286 expect(() => fromMap({"accessToken": "foo", "scopes": 12}),
281 throwsFormatException); 287 throwsFormatException);
282 }); 288 });
283 289
284 test("should throw a FormatException if expiration is not an int", () { 290 test("should throw a FormatException if expiration is not an int", () {
285 expect(() => fromMap({"accessToken": "foo", "expiration": "12"}), 291 expect(() => fromMap({"accessToken": "foo", "expiration": "12"}),
286 throwsFormatException); 292 throwsFormatException);
287 }); 293 });
288 }); 294 });
289 } 295 }
OLDNEW
« no previous file with comments | « pubspec.yaml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698