org.springframework.mock.staticmock.AnnotationDrivenStaticEntityMockingControl.aj Maven / Gradle / Ivy
package org.springframework.mock.staticmock;
import javax.persistence.Entity;
/**
* Annotation-based aspect to use in test build to enable mocking static methods
* on Entity classes, as used by Roo for finders.
*
* Mocking will occur in the call stack of any method in a class (typically a test class)
* that is annotated with the @MockStaticEntityMethods annotation.
*
* Also provides static methods to simplify the programming model for
* entering playback mode and setting expected return values.
*
* Usage:
* - Annotate a test class with @MockStaticEntityMethods.
*
- In each test method, AnnotationDrivenStaticEntityMockingControl will begin in recording mode.
* Invoke static methods on Entity classes, with each recording-mode invocation
* being followed by an invocation to the static expectReturn() or expectThrow()
* method on AnnotationDrivenStaticEntityMockingControl.
*
- Invoke the static AnnotationDrivenStaticEntityMockingControl() method.
*
- Call the code you wish to test that uses the static methods. Verification will
* occur automatically.
*
*
* @see MockStaticEntityMethods
*
* @author Rod Johnson
* @author Ramnivas Laddad
*
*/
public aspect AnnotationDrivenStaticEntityMockingControl extends AbstractMethodMockingControl {
/**
* Stop recording mock calls and enter playback state
*/
public static void playback() {
AnnotationDrivenStaticEntityMockingControl.aspectOf().playbackInternal();
}
public static void expectReturn(Object retVal) {
AnnotationDrivenStaticEntityMockingControl.aspectOf().expectReturnInternal(retVal);
}
public static void expectThrow(Throwable throwable) {
AnnotationDrivenStaticEntityMockingControl.aspectOf().expectThrowInternal(throwable);
}
// Only matches directly annotated @Test methods, to allow methods in
// @MockStatics classes to invoke each other without resetting the mocking environment
protected pointcut mockStaticsTestMethod() : execution(public * (@MockStaticEntityMethods *).*(..));
protected pointcut methodToMock() : execution(public static * (@Entity *).*(..));
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy