1// Copyright 2011 Aaron Jacobs. All Rights Reserved.
2// Author: aaronjjacobs@gmail.com (Aaron Jacobs)
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//     http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16package oglemock
17
18// Expectation is an expectation for zero or more calls to a mock method with
19// particular arguments or sets of arguments.
20type Expectation interface {
21	// Times expresses that a matching method call should happen exactly N times.
22	// Times must not be called more than once, and must not be called after
23	// WillOnce or WillRepeatedly.
24	//
25	// The full rules for the cardinality of an expectation are as follows:
26	//
27	//  1. If an explicit cardinality is set with Times(N), then anything other
28	//     than exactly N matching calls will cause a test failure.
29	//
30	//  2. Otherwise, if there are any one-time actions set up, then it is
31	//     expected there will be at least that many matching calls. If there is
32	//     not also a fallback action, then it is expected that there will be
33	//     exactly that many.
34	//
35	//  3. Otherwise, if there is a fallback action configured, any number of
36	//     matching calls (including zero) is allowed.
37	//
38	//  4. Otherwise, the implicit cardinality is one.
39	//
40	Times(n uint) Expectation
41
42	// WillOnce configures a "one-time action". WillOnce can be called zero or
43	// more times, but must be called after any call to Times and before any call
44	// to WillRepeatedly.
45	//
46	// When matching method calls are made on the mock object, one-time actions
47	// are invoked one per matching call in the order that they were set up until
48	// they are exhausted. Afterward the fallback action, if any, will be used.
49	WillOnce(a Action) Expectation
50
51	// WillRepeatedly configures a "fallback action". WillRepeatedly can be
52	// called zero or one times, and must not be called before Times or WillOnce.
53	//
54	// Once all one-time actions are exhausted (see above), the fallback action
55	// will be invoked for any further method calls. If WillRepeatedly is not
56	// called, the fallback action is implicitly an action that returns zero
57	// values for the method's return values.
58	WillRepeatedly(a Action) Expectation
59}
60