| OLD | NEW |
| 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 library mock_test; | 5 library mock_test; |
| 6 import 'package:unittest/unittest.dart'; | 6 import 'package:unittest/unittest.dart'; |
| 7 import 'package:unittest/mock.dart'; | 7 import 'package:unittest/mock.dart'; |
| 8 | 8 |
| 9 class MockList extends Mock implements List { | 9 class MockList extends Mock implements List { |
| 10 dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); | 10 dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 }); | 186 }); |
| 187 | 187 |
| 188 test('Mocking: RegExp CallMatcher good', () { | 188 test('Mocking: RegExp CallMatcher good', () { |
| 189 var m = new Mock(); | 189 var m = new Mock(); |
| 190 m.when(callsTo(matches('^[A-Z]'))). | 190 m.when(callsTo(matches('^[A-Z]'))). |
| 191 alwaysThrow('Method names must start with lower case.'); | 191 alwaysThrow('Method names must start with lower case.'); |
| 192 m.test(); | 192 m.test(); |
| 193 }); | 193 }); |
| 194 | 194 |
| 195 test('Mocking: No logging', () { | 195 test('Mocking: No logging', () { |
| 196 var m = new Mock.custom(enableLogging:false); | 196 var m = new Mock.custom(enableLogging: false); |
| 197 m.Test(); | 197 m.Test(); |
| 198 expect(() => m.getLogs(callsTo('Test')), throwsA((e) => e.toString() == | 198 expect(() => m.getLogs(callsTo('Test')), throwsA((e) => e.toString() == |
| 199 "Exception: Can't retrieve logs when logging was never enabled.")); | 199 "Exception: Can't retrieve logs when logging was never enabled.")); |
| 200 }); | 200 }); |
| 201 | 201 |
| 202 test('Mocking: Find logList entry', () { | 202 test('Mocking: Find logList entry', () { |
| 203 LogEntryList logList = makeTestLog(); | 203 LogEntryList logList = makeTestLog(); |
| 204 // Basic behavior, with call matcher. | 204 // Basic behavior, with call matcher. |
| 205 expect(logList.findLogEntry(callsTo('a')), 0); | 205 expect(logList.findLogEntry(callsTo('a')), 0); |
| 206 expect(logList.findLogEntry(callsTo('b')), 1); | 206 expect(logList.findLogEntry(callsTo('b')), 1); |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 var real = new Foo(); | 726 var real = new Foo(); |
| 727 var spy = new Mock.spy(real); | 727 var spy = new Mock.spy(real); |
| 728 var sum = spy.sum(1, 2, 3); | 728 var sum = spy.sum(1, 2, 3); |
| 729 expect(sum, 6); | 729 expect(sum, 6); |
| 730 expect(() => spy.total(1, 2, 3), throwsNoSuchMethodError); | 730 expect(() => spy.total(1, 2, 3), throwsNoSuchMethodError); |
| 731 spy.getLogs(callsTo('sum')).verify(happenedExactly(1)); | 731 spy.getLogs(callsTo('sum')).verify(happenedExactly(1)); |
| 732 spy.getLogs(callsTo('total')).verify(happenedExactly(1)); | 732 spy.getLogs(callsTo('total')).verify(happenedExactly(1)); |
| 733 }); | 733 }); |
| 734 } | 734 } |
| 735 | 735 |
| OLD | NEW |