T
- specifies the type to be faked; if a type variable is used, then all implementation classes extending or implementing that
base type are also faked; if the type argument itself is a parameterized type, then only its raw type is consideredpublic class MockUp<T> extends Object
public final class FakeSystem extends MockUp<System> { @Mock public static long nanoTime() { return 123L; } }One or more fake methods annotated as such must be defined in the concrete subclass. Each @Mock method should have a matching method or constructor in the faked class. At runtime, the execution of a faked method/constructor will get redirected to the corresponding fake method. When the type to be faked is specified indirectly through a type variable, then that type is taken as a base type whose concrete implementation classes should also get faked. Example:
@Test public <BC extends SomeBaseClass> void someTest() { new MockUp<BC>() { @Mock int someMethod(int i) { return i + 1; } }; int i = new AConcreteSubclass().someMethod(1); assertEquals(2, i); }
MockUp()
,
MockUp(Class)
,
onTearDown()
,
targetType
,
TutorialModifier and Type | Field and Description |
---|---|
protected Type |
targetType
Holds the class or generic type targeted by this fake instance.
|
Modifier | Constructor and Description |
---|---|
protected |
MockUp()
Applies the fake methods defined in the concrete subclass to the class specified through the type parameter.
|
protected |
MockUp(Class<?> targetClass)
Applies the fake methods defined in the fake class to the given class.
|
Modifier and Type | Method and Description |
---|---|
protected void |
onTearDown()
An empty method that can be overridden in a fake class that wants to be notified whenever the fake is automatically torn down.
|
protected MockUp()
protected MockUp(@Nonnull Class<?> targetClass)
protected void onTearDown()
fakes
" system property.
By default, this method does nothing.Copyright © 2006–2019. All rights reserved.