147d431f63a66505a645f282416659a9758a91f1cBrett Chabot/* 247d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Copyright 2001-2009 OFFIS, Tammo Freese 347d431f63a66505a645f282416659a9758a91f1cBrett Chabot * 447d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Licensed under the Apache License, Version 2.0 (the "License"); 547d431f63a66505a645f282416659a9758a91f1cBrett Chabot * you may not use this file except in compliance with the License. 647d431f63a66505a645f282416659a9758a91f1cBrett Chabot * You may obtain a copy of the License at 747d431f63a66505a645f282416659a9758a91f1cBrett Chabot * 847d431f63a66505a645f282416659a9758a91f1cBrett Chabot * http://www.apache.org/licenses/LICENSE-2.0 947d431f63a66505a645f282416659a9758a91f1cBrett Chabot * 1047d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Unless required by applicable law or agreed to in writing, software 1147d431f63a66505a645f282416659a9758a91f1cBrett Chabot * distributed under the License is distributed on an "AS IS" BASIS, 1247d431f63a66505a645f282416659a9758a91f1cBrett Chabot * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1347d431f63a66505a645f282416659a9758a91f1cBrett Chabot * See the License for the specific language governing permissions and 1447d431f63a66505a645f282416659a9758a91f1cBrett Chabot * limitations under the License. 1547d431f63a66505a645f282416659a9758a91f1cBrett Chabot */ 1647d431f63a66505a645f282416659a9758a91f1cBrett Chabotpackage org.easymock; 1747d431f63a66505a645f282416659a9758a91f1cBrett Chabot 1847d431f63a66505a645f282416659a9758a91f1cBrett Chabot/** 1947d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Controls all the mock objects created by it. 2047d431f63a66505a645f282416659a9758a91f1cBrett Chabot * For details, see the EasyMock documentation. 2147d431f63a66505a645f282416659a9758a91f1cBrett Chabot */ 2247d431f63a66505a645f282416659a9758a91f1cBrett Chabotpublic interface IMocksControl { 2347d431f63a66505a645f282416659a9758a91f1cBrett Chabot /** 2447d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Creates a mock object that implements the given interface. 2547d431f63a66505a645f282416659a9758a91f1cBrett Chabot * @param <T> the interface that the mock object should implement. 2647d431f63a66505a645f282416659a9758a91f1cBrett Chabot * @param toMock the class of the interface that the mock object should implement. 2747d431f63a66505a645f282416659a9758a91f1cBrett Chabot * @return the mock object. 2847d431f63a66505a645f282416659a9758a91f1cBrett Chabot */ 2947d431f63a66505a645f282416659a9758a91f1cBrett Chabot <T> T createMock(Class<T> toMock); 3047d431f63a66505a645f282416659a9758a91f1cBrett Chabot 3147d431f63a66505a645f282416659a9758a91f1cBrett Chabot /** 3247d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Creates a mock object that implements the given interface. 3347d431f63a66505a645f282416659a9758a91f1cBrett Chabot * @param name the name of the mock object . 3447d431f63a66505a645f282416659a9758a91f1cBrett Chabot * @param toMock the class of the interface that the mock object should implement. 3547d431f63a66505a645f282416659a9758a91f1cBrett Chabot * @param <T> the interface that the mock object should implement. 3647d431f63a66505a645f282416659a9758a91f1cBrett Chabot * @return the mock object. 3747d431f63a66505a645f282416659a9758a91f1cBrett Chabot * @throws IllegalArgumentException if the name is not a valid Java identifier. 3847d431f63a66505a645f282416659a9758a91f1cBrett Chabot */ 3947d431f63a66505a645f282416659a9758a91f1cBrett Chabot <T> T createMock(String name, Class<T> toMock); 4047d431f63a66505a645f282416659a9758a91f1cBrett Chabot 4147d431f63a66505a645f282416659a9758a91f1cBrett Chabot /** 4247d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Removes all expectations for the mock objects of this control. 4347d431f63a66505a645f282416659a9758a91f1cBrett Chabot */ 4447d431f63a66505a645f282416659a9758a91f1cBrett Chabot void reset(); 4547d431f63a66505a645f282416659a9758a91f1cBrett Chabot 4647d431f63a66505a645f282416659a9758a91f1cBrett Chabot /** 4747d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Removes all expectations for the mock objects of this control and turn 4847d431f63a66505a645f282416659a9758a91f1cBrett Chabot * them to nice mocks. 4947d431f63a66505a645f282416659a9758a91f1cBrett Chabot */ 5047d431f63a66505a645f282416659a9758a91f1cBrett Chabot void resetToNice(); 5147d431f63a66505a645f282416659a9758a91f1cBrett Chabot 5247d431f63a66505a645f282416659a9758a91f1cBrett Chabot /** 5347d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Removes all expectations for the mock objects of this control and turn 5447d431f63a66505a645f282416659a9758a91f1cBrett Chabot * them to default mocks. 5547d431f63a66505a645f282416659a9758a91f1cBrett Chabot */ 5647d431f63a66505a645f282416659a9758a91f1cBrett Chabot void resetToDefault(); 5747d431f63a66505a645f282416659a9758a91f1cBrett Chabot 5847d431f63a66505a645f282416659a9758a91f1cBrett Chabot /** 5947d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Removes all expectations for the mock objects of this control and turn 6047d431f63a66505a645f282416659a9758a91f1cBrett Chabot * them to strict mocks. 6147d431f63a66505a645f282416659a9758a91f1cBrett Chabot */ 6247d431f63a66505a645f282416659a9758a91f1cBrett Chabot void resetToStrict(); 6347d431f63a66505a645f282416659a9758a91f1cBrett Chabot 6447d431f63a66505a645f282416659a9758a91f1cBrett Chabot /** 6547d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Switches the control from record mode to replay mode. 6647d431f63a66505a645f282416659a9758a91f1cBrett Chabot */ 6747d431f63a66505a645f282416659a9758a91f1cBrett Chabot void replay(); 6847d431f63a66505a645f282416659a9758a91f1cBrett Chabot 6947d431f63a66505a645f282416659a9758a91f1cBrett Chabot /** 7047d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Verifies that all expectations were met. 7147d431f63a66505a645f282416659a9758a91f1cBrett Chabot */ 7247d431f63a66505a645f282416659a9758a91f1cBrett Chabot void verify(); 7347d431f63a66505a645f282416659a9758a91f1cBrett Chabot 7447d431f63a66505a645f282416659a9758a91f1cBrett Chabot /** 7547d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Switches order checking on and off. 7647d431f63a66505a645f282416659a9758a91f1cBrett Chabot * @param state <code>true</code> switches order checking on, <code>false</code> switches it off. 7747d431f63a66505a645f282416659a9758a91f1cBrett Chabot */ 7847d431f63a66505a645f282416659a9758a91f1cBrett Chabot void checkOrder(boolean state); 7947d431f63a66505a645f282416659a9758a91f1cBrett Chabot 8047d431f63a66505a645f282416659a9758a91f1cBrett Chabot /** 8147d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Makes the mock thread safe. 8247d431f63a66505a645f282416659a9758a91f1cBrett Chabot * 8347d431f63a66505a645f282416659a9758a91f1cBrett Chabot * @param threadSafe If the mock should be thread safe or not 8447d431f63a66505a645f282416659a9758a91f1cBrett Chabot */ 8547d431f63a66505a645f282416659a9758a91f1cBrett Chabot void makeThreadSafe(boolean threadSafe); 8647d431f63a66505a645f282416659a9758a91f1cBrett Chabot 8747d431f63a66505a645f282416659a9758a91f1cBrett Chabot /** 8847d431f63a66505a645f282416659a9758a91f1cBrett Chabot * Check that the mock is called from only one thread 8947d431f63a66505a645f282416659a9758a91f1cBrett Chabot * 9047d431f63a66505a645f282416659a9758a91f1cBrett Chabot * @param shouldBeUsedInOneThread 9147d431f63a66505a645f282416659a9758a91f1cBrett Chabot * If it should be used in one thread only or not 9247d431f63a66505a645f282416659a9758a91f1cBrett Chabot */ 9347d431f63a66505a645f282416659a9758a91f1cBrett Chabot void checkIsUsedInOneThread(boolean shouldBeUsedInOneThread); 9447d431f63a66505a645f282416659a9758a91f1cBrett Chabot} 95