| 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({Map<String, dynamic> props}) => | 12 AnalyticsImplMock createMock({bool setOptIn: true}) => |
| 13 new AnalyticsImplMock('UA-0', props: props); | 13 new AnalyticsImplMock('UA-0', setOptIn: setOptIn); |
| 14 | 14 |
| 15 was(Map m, String type) => expect(m['t'], type); | 15 void was(Map m, String type) => expect(m['t'], type); |
| 16 has(Map m, String key) => expect(m[key], isNotNull); | 16 void has(Map m, String key) => expect(m[key], isNotNull); |
| 17 hasnt(Map m, String key) => expect(m[key], isNull); | 17 void 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, {Map<String, dynamic> props}) | 23 AnalyticsImplMock(String trackingId, {bool setOptIn: true}) : |
| 24 : super(trackingId, new MockProperties(props), new MockPostHandler(), | 24 super(trackingId, new MockProperties(), new MockPostHandler(), |
| 25 applicationName: 'Test App', applicationVersion: '0.1'); | 25 applicationName: 'Test App', applicationVersion: '0.1') { |
| 26 if (setOptIn) optIn = true; |
| 27 } |
| 26 | 28 |
| 27 Map<String, dynamic> get last => mockPostHandler.last; | 29 Map<String, dynamic> get last => mockPostHandler.last; |
| 28 } | 30 } |
| 29 | 31 |
| 30 class MockProperties extends PersistentProperties { | 32 class MockProperties extends PersistentProperties { |
| 31 Map<String, dynamic> props = {}; | 33 Map<String, dynamic> props = {}; |
| 32 | 34 |
| 33 MockProperties([Map<String, dynamic> props]) : super('mock') { | 35 MockProperties() : super('mock'); |
| 34 if (props != null) this.props.addAll(props); | |
| 35 } | |
| 36 | 36 |
| 37 @override | 37 dynamic operator[](String key) => props[key]; |
| 38 dynamic operator [](String key) => props[key]; | |
| 39 | 38 |
| 40 @override | 39 void operator[]=(String key, dynamic value) { |
| 41 void operator []=(String key, dynamic value) { | |
| 42 props[key] = value; | 40 props[key] = value; |
| 43 } | 41 } |
| 44 | |
| 45 @override | |
| 46 void syncSettings() {} | |
| 47 } | 42 } |
| 48 | 43 |
| 49 class MockPostHandler extends PostHandler { | 44 class MockPostHandler extends PostHandler { |
| 50 List<Map<String, dynamic>> sentValues = []; | 45 List<Map<String, dynamic>> sentValues = []; |
| 51 | 46 |
| 52 @override | |
| 53 Future sendPost(String url, Map<String, dynamic> parameters) { | 47 Future sendPost(String url, Map<String, dynamic> parameters) { |
| 54 sentValues.add(parameters); | 48 sentValues.add(parameters); |
| 55 | 49 |
| 56 return new Future.value(); | 50 return new Future.value(); |
| 57 } | 51 } |
| 58 | 52 |
| 59 Map<String, dynamic> get last => sentValues.last; | 53 Map<String, dynamic> get last => sentValues.last; |
| 60 | |
| 61 @override | |
| 62 void close() {} | |
| 63 } | 54 } |
| OLD | NEW |