All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mockit.Mock Maven / Gradle / Ivy

Go to download

JMockit is a Java toolkit for automated developer testing. It contains mocking/faking APIs and a code coverage tool, supporting both JUnit and TestNG. The mocking APIs allow all kinds of Java code, without testability restrictions, to be tested in isolation from selected dependencies.

There is a newer version: 1.49
Show newest version
/*
 * Copyright (c) 2006-2015 Rogério Liesenfeld
 * This file is subject to the terms of the MIT license (see LICENSE.txt).
 */
package mockit;

import java.lang.annotation.*;

/**
 * Used inside a {@linkplain MockUp mock-up} class to indicate a mock method whose implementation will
 * temporarily replace the implementation of a matching "real" method.
 * 

* The mock method must have the same name and the same parameters as the matching real method, except for an optional * first parameter of type {@link Invocation}; if this extra parameter is present, the remaining ones must match the * parameters in the real method. * The mock method must also have the same return type as the matching real method. *

* Method modifiers (public, {@code final}, {@code static}, etc.) between mock and mocked * methods don't have to be the same. * It's perfectly fine to have a non-static mock method for a {@code static} mocked method (or vice-versa), * for example. * Checked exceptions in the {@code throws} clause (if any) can also differ between the two matching methods. *

* A mock method can also target a constructor, in which case the previous considerations still apply, * except for the name of the mock method which must be "$init". *

* Another special mock method, "void $clinit()", will target the {@code static} * initializers of the mocked class, if present in the mock-up class. *

* Yet another special mock method is "Object $advice(Invocation)", which if defined will * match every method in the mocked class hierarchy. *

* A mock method can specify constraints on the number of invocations it should receive while in effect * (ie, from the time a real method/constructor is mocked to the time it is restored to its original definition). * * @see #invocations invocations * @see #minInvocations minInvocations * @see #maxInvocations maxInvocations * @see Tutorial */ @Inherited @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Mock { /** * Number of expected invocations of the mock method. * If 0 (zero), no invocations will be expected. * A negative value (the default) means there is no expectation on the number of invocations; * that is, the mock can be called any number of times or not at all during any test which uses it. *

* A non-negative value is equivalent to setting {@link #minInvocations minInvocations} and * {@link #maxInvocations maxInvocations} to that same value. * * @see Tutorial */ int invocations() default -1; /** * Minimum number of expected invocations of the mock method, starting from 0 (zero, which is the default). * * @see #invocations invocations * @see #maxInvocations maxInvocations * @see Tutorial */ int minInvocations() default 0; /** * Maximum number of expected invocations of the mock method, if positive. * If zero the mock is not expected to be called at all. * A negative value (the default) means there is no expectation on the maximum number of invocations. * * @see #invocations invocations * @see #minInvocations minInvocations * @see Tutorial */ int maxInvocations() default -1; }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy