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