IMocksControl.java revision 47d431f63a66505a645f282416659a9758a91f1c
15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/*
25d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Copyright 2001-2009 OFFIS, Tammo Freese
35d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *
45d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Licensed under the Apache License, Version 2.0 (the "License");
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * you may not use this file except in compliance with the License.
65d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * You may obtain a copy of the License at
75d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *
803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) *     http://www.apache.org/licenses/LICENSE-2.0
95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *
1003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) * Unless required by applicable law or agreed to in writing, software
11f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) * distributed under the License is distributed on an "AS IS" BASIS,
125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * See the License for the specific language governing permissions and
145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * limitations under the License.
155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) */
165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)package org.easymock;
1703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)/**
195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * Controls all the mock objects created by it.
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) * For details, see the EasyMock documentation.
2103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles) */
2203b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)public interface IMocksControl {
235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * Creates a mock object that implements the given interface.
255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @param <T> the interface that the mock object should implement.
265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @param toMock the class of the interface that the mock object should implement.
275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @return the mock object.
285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     */
295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    <T> T createMock(Class<T> toMock);
305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * Creates a mock object that implements the given interface.
33f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)     * @param name the name of the mock object .
345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @param toMock the class of the interface that the mock object should implement.
355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @param <T> the interface that the mock object should implement.
365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @return the mock object.
375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @throws IllegalArgumentException if the name is not a valid Java identifier.
385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     */
395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    <T> T createMock(String name, Class<T> toMock);
4003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * Removes all expectations for the mock objects of this control.
435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     */
445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    void reset();
455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * Removes all expectations for the mock objects of this control and turn
485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * them to nice mocks.
49f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)     */
505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    void resetToNice();
515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
5303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)     * Removes all expectations for the mock objects of this control and turn
545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * them to default mocks.
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     */
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    void resetToDefault();
575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * Removes all expectations for the mock objects of this control and turn
605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * them to strict mocks.
615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     */
625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    void resetToStrict();
6303b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)
645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * Switches the control from record mode to replay mode.
665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     */
675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    void replay();
685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
7003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)     * Verifies that all expectations were met.
715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     */
725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    void verify();
735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * Switches order checking on and off.
765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @param state <code>true</code> switches order checking on, <code>false</code> switches it off.
775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     */
785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    void checkOrder(boolean state);
795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * Makes the mock thread safe.
825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     *
835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * @param threadSafe If the mock should be thread safe or not
841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci     */
855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    void makeThreadSafe(boolean threadSafe);
861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    /**
885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     * Check that the mock is called from only one thread
895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     *
901320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci     * @param shouldBeUsedInOneThread
915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     *            If it should be used in one thread only or not
925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)     */
935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    void checkIsUsedInOneThread(boolean shouldBeUsedInOneThread);
945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)