| 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 } | 10 } |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 654 var alice = new Object(); | 654 var alice = new Object(); |
| 655 var bob = new Object(); | 655 var bob = new Object(); |
| 656 var m = new Mock(); | 656 var m = new Mock(); |
| 657 m.when(callsTo("foo", alice)).alwaysReturn(true); | 657 m.when(callsTo("foo", alice)).alwaysReturn(true); |
| 658 m.when(callsTo("foo", bob)).alwaysReturn(false); | 658 m.when(callsTo("foo", bob)).alwaysReturn(false); |
| 659 expect(m.foo(alice), true); | 659 expect(m.foo(alice), true); |
| 660 expect(m.foo(bob), false); | 660 expect(m.foo(bob), false); |
| 661 expect(m.foo(alice), true); | 661 expect(m.foo(alice), true); |
| 662 expect(m.foo(bob), false); | 662 expect(m.foo(bob), false); |
| 663 }); | 663 }); |
| 664 |
| 665 test("Behavior ordering", () { |
| 666 // This is distinct from value ordering, i.e. |
| 667 // |
| 668 // m.when(...).thenReturn(1).thenReturn(2) |
| 669 // |
| 670 // Here we want to test using distinct matchers being |
| 671 // applied in order, so we have a single call that |
| 672 // matches 3 different behaviors, and test that |
| 673 // the behaviors are applied in the order they are |
| 674 // defined. |
| 675 var m = new Mock(); |
| 676 m.when(callsTo("foo")).thenReturn("A"); |
| 677 m.when(callsTo("foo", "bar")).thenReturn("B"); |
| 678 m.when(callsTo("foo", "bar", "mock")).alwaysReturn("C"); |
| 679 expect(m.foo("bar", "mock"), "A"); |
| 680 expect(m.foo("bar", "mock"), "B"); |
| 681 expect(m.foo("bar", "mock"), "C"); |
| 682 expect(m.foo("bar", "mock"), "C"); |
| 683 m.resetBehavior(); |
| 684 |
| 685 m.when(callsTo("foo")).thenReturn("A"); |
| 686 m.when(callsTo("foo", "bar", "mock")).alwaysReturn("C"); |
| 687 m.when(callsTo("foo", "bar")).thenReturn("B"); |
| 688 expect(m.foo("bar", "mock"), "A"); |
| 689 expect(m.foo("bar", "mock"), "C"); |
| 690 expect(m.foo("bar", "mock"), "C"); |
| 691 expect(m.foo("bar", "mock"), "C"); |
| 692 m.resetBehavior(); |
| 693 |
| 694 m.when(callsTo("foo", "bar")).thenReturn("B"); |
| 695 m.when(callsTo("foo")).thenReturn("A"); |
| 696 m.when(callsTo("foo", "bar", "mock")).alwaysReturn("C"); |
| 697 expect(m.foo("bar", "mock"), "B"); |
| 698 expect(m.foo("bar", "mock"), "A"); |
| 699 expect(m.foo("bar", "mock"), "C"); |
| 700 expect(m.foo("bar", "mock"), "C"); |
| 701 m.resetBehavior(); |
| 702 |
| 703 m.when(callsTo("foo", "bar")).thenReturn("B"); |
| 704 m.when(callsTo("foo", "bar", "mock")).alwaysReturn("C"); |
| 705 m.when(callsTo("foo")).thenReturn("A"); |
| 706 expect(m.foo("bar", "mock"), "B"); |
| 707 expect(m.foo("bar", "mock"), "C"); |
| 708 expect(m.foo("bar", "mock"), "C"); |
| 709 expect(m.foo("bar", "mock"), "C"); |
| 710 m.resetBehavior(); |
| 711 |
| 712 m.when(callsTo("foo", "bar", "mock")).alwaysReturn("C"); |
| 713 m.when(callsTo("foo")).thenReturn("A"); |
| 714 m.when(callsTo("foo", "bar")).thenReturn("B"); |
| 715 expect(m.foo("bar", "mock"), "C"); |
| 716 expect(m.foo("bar", "mock"), "C"); |
| 717 expect(m.foo("bar", "mock"), "C"); |
| 718 expect(m.foo("bar", "mock"), "C"); |
| 719 m.resetBehavior(); |
| 720 }); |
| 664 } | 721 } |
| 722 |
| OLD | NEW |