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

Side by Side Diff: pkg/unittest/test/mock_test.dart

Issue 134963002: pkg/unittest: add @proxy to Mock (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 11 months 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 | Annotate | Revision Log
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 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 } 11 }
11 12
12 class Foo { 13 class Foo {
13 sum(a, b, c) => a + b + c; 14 sum(a, b, c) => a + b + c;
14 } 15 }
15 16
16 class FooSpy extends Mock implements Foo { 17 class FooSpy extends Mock implements Foo {
17 Foo real; 18 Foo real;
18 FooSpy() { 19 FooSpy() {
19 real = new Foo(); 20 real = new Foo();
20 this.when(callsTo('sum')).alwaysCall(real.sum); 21 this.when(callsTo('sum')).alwaysCall(real.sum);
21 } 22 }
23
24 dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation);
22 } 25 }
23 26
24 makeTestLogEntry(String methodName, List args, int time, 27 makeTestLogEntry(String methodName, List args, int time,
25 [String mockName]) { 28 [String mockName]) {
26 LogEntry e = new LogEntry(mockName, methodName, args, Action.IGNORE); 29 LogEntry e = new LogEntry(mockName, methodName, args, Action.IGNORE);
27 e.time = new DateTime.fromMillisecondsSinceEpoch(time, isUtc: true); 30 e.time = new DateTime.fromMillisecondsSinceEpoch(time, isUtc: true);
28 return e; 31 return e;
29 } 32 }
30 33
31 makeTestLog() { 34 makeTestLog() {
(...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 expect(m.foo(alice), true); 662 expect(m.foo(alice), true);
660 expect(m.foo(bob), false); 663 expect(m.foo(bob), false);
661 expect(m.foo(alice), true); 664 expect(m.foo(alice), true);
662 expect(m.foo(bob), false); 665 expect(m.foo(bob), false);
663 }); 666 });
664 667
665 test("Behavior ordering", () { 668 test("Behavior ordering", () {
666 // This is distinct from value ordering, i.e. 669 // This is distinct from value ordering, i.e.
667 // 670 //
668 // m.when(...).thenReturn(1).thenReturn(2) 671 // m.when(...).thenReturn(1).thenReturn(2)
669 // 672 //
670 // Here we want to test using distinct matchers being 673 // Here we want to test using distinct matchers being
671 // applied in order, so we have a single call that 674 // applied in order, so we have a single call that
672 // matches 3 different behaviors, and test that 675 // matches 3 different behaviors, and test that
673 // the behaviors are applied in the order they are 676 // the behaviors are applied in the order they are
674 // defined. 677 // defined.
675 var m = new Mock(); 678 var m = new Mock();
676 m.when(callsTo("foo")).thenReturn("A"); 679 m.when(callsTo("foo")).thenReturn("A");
677 m.when(callsTo("foo", "bar")).thenReturn("B"); 680 m.when(callsTo("foo", "bar")).thenReturn("B");
678 m.when(callsTo("foo", "bar", "mock")).alwaysReturn("C"); 681 m.when(callsTo("foo", "bar", "mock")).alwaysReturn("C");
679 expect(m.foo("bar", "mock"), "A"); 682 expect(m.foo("bar", "mock"), "A");
680 expect(m.foo("bar", "mock"), "B"); 683 expect(m.foo("bar", "mock"), "B");
681 expect(m.foo("bar", "mock"), "C"); 684 expect(m.foo("bar", "mock"), "C");
682 expect(m.foo("bar", "mock"), "C"); 685 expect(m.foo("bar", "mock"), "C");
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 var real = new Foo(); 726 var real = new Foo();
724 var spy = new Mock.spy(real); 727 var spy = new Mock.spy(real);
725 var sum = spy.sum(1, 2, 3); 728 var sum = spy.sum(1, 2, 3);
726 expect(sum, 6); 729 expect(sum, 6);
727 expect(() => spy.total(1, 2, 3), throwsNoSuchMethodError); 730 expect(() => spy.total(1, 2, 3), throwsNoSuchMethodError);
728 spy.getLogs(callsTo('sum')).verify(happenedExactly(1)); 731 spy.getLogs(callsTo('sum')).verify(happenedExactly(1));
729 spy.getLogs(callsTo('total')).verify(happenedExactly(1)); 732 spy.getLogs(callsTo('total')).verify(happenedExactly(1));
730 }); 733 });
731 } 734 }
732 735
OLDNEW
« pkg/unittest/test/matchers_test.dart ('K') | « pkg/unittest/test/matchers_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698