OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library usage.common_test; |
| 6 |
| 7 import 'dart:async'; |
| 8 |
| 9 import 'package:unittest/unittest.dart'; |
| 10 import 'package:usage/src/usage_impl.dart'; |
| 11 |
| 12 AnalyticsImplMock createMock({bool setOptIn: true}) => |
| 13 new AnalyticsImplMock('UA-0', setOptIn: setOptIn); |
| 14 |
| 15 void was(Map m, String type) => expect(m['t'], type); |
| 16 void has(Map m, String key) => expect(m[key], isNotNull); |
| 17 void hasnt(Map m, String key) => expect(m[key], isNull); |
| 18 |
| 19 class AnalyticsImplMock extends AnalyticsImpl { |
| 20 MockProperties get mockProperties => properties; |
| 21 MockPostHandler get mockPostHandler => postHandler; |
| 22 |
| 23 AnalyticsImplMock(String trackingId, {bool setOptIn: true}) : |
| 24 super(trackingId, new MockProperties(), new MockPostHandler(), |
| 25 applicationName: 'Test App', applicationVersion: '0.1') { |
| 26 if (setOptIn) optIn = true; |
| 27 } |
| 28 |
| 29 Map<String, dynamic> get last => mockPostHandler.last; |
| 30 } |
| 31 |
| 32 class MockProperties extends PersistentProperties { |
| 33 Map<String, dynamic> props = {}; |
| 34 |
| 35 MockProperties() : super('mock'); |
| 36 |
| 37 dynamic operator[](String key) => props[key]; |
| 38 |
| 39 void operator[]=(String key, dynamic value) { |
| 40 props[key] = value; |
| 41 } |
| 42 } |
| 43 |
| 44 class MockPostHandler extends PostHandler { |
| 45 List<Map> sentValues = []; |
| 46 |
| 47 Future sendPost(String url, Map<String, String> parameters) { |
| 48 sentValues.add(parameters); |
| 49 |
| 50 return new Future.value(); |
| 51 } |
| 52 |
| 53 Map<String, dynamic> get last => sentValues.last; |
| 54 } |
OLD | NEW |