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 mock.behavior; | 5 library mock.behavior; |
6 | 6 |
7 import 'action.dart'; | 7 import 'action.dart'; |
8 import 'call_matcher.dart'; | 8 import 'call_matcher.dart'; |
9 import 'responder.dart'; | 9 import 'responder.dart'; |
10 | 10 |
11 /** | 11 /** |
12 * A [Behavior] represents how a [Mock] will respond to one particular | 12 * A [Behavior] represents how a [Mock] will respond to one particular |
13 * type of method call. | 13 * type of method call. |
14 */ | 14 */ |
15 class Behavior { | 15 class Behavior { |
16 CallMatcher matcher; // The method call matcher. | 16 CallMatcher matcher; // The method call matcher. |
17 List<Responder> actions; // The values to return/throw or proxies to call. | 17 List<Responder> actions; // The values to return/throw or proxies to call. |
18 bool logging = true; | 18 bool logging = true; |
19 | 19 |
20 Behavior (this.matcher) { | 20 Behavior(this.matcher) { |
21 actions = new List<Responder>(); | 21 actions = new List<Responder>(); |
22 } | 22 } |
23 | 23 |
24 /** | 24 /** |
25 * Adds a [Responder] that returns a [value] for [count] calls | 25 * Adds a [Responder] that returns a [value] for [count] calls |
26 * (1 by default). | 26 * (1 by default). |
27 */ | 27 */ |
28 Behavior thenReturn(value, [count = 1]) { | 28 Behavior thenReturn(value, [count = 1]) { |
29 actions.add(new Responder(value, count, Action.RETURN)); | 29 actions.add(new Responder(value, count, Action.RETURN)); |
30 return this; // For chaining calls. | 30 return this; // For chaining calls. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 Behavior alwaysCall(value) { | 74 Behavior alwaysCall(value) { |
75 return thenCall(value, 0); | 75 return thenCall(value, 0); |
76 } | 76 } |
77 | 77 |
78 /** Returns true if a method call matches the [Behavior]. */ | 78 /** Returns true if a method call matches the [Behavior]. */ |
79 bool matches(String method, List args) => matcher.matches(method, args); | 79 bool matches(String method, List args) => matcher.matches(method, args); |
80 | 80 |
81 /** Returns the [matcher]'s representation. */ | 81 /** Returns the [matcher]'s representation. */ |
82 String toString() => matcher.toString(); | 82 String toString() => matcher.toString(); |
83 } | 83 } |
OLD | NEW |