I have an annotation,
@Retention(RetentionPolicy.RUNTIME)
@Target(value={ElementType.METHOD, ElementType.TYPE})
public @interface JobLoggable {
JobType jobType();
JobDomain domain();
JobStatus jobInitialStatus();
}
which I apply to my class
@JobLoggable
public class Process {
public void doSomething() {
Annotation[] annotations = this.getClass().getAnnotations();
Assert.assert(annotations.length == 1);
}
}
In my test, I spy on it (not mock it, though it shouldn't matter):
public class Test {
@Test
public void test() {
Process process = Mockito.spy(Process.class);
//spy on some internal methods, capture their return values
process.doSomething();
}
}
Sadly there are no annotations returned by this.getClass().getAnnotations(). When I look at what class the instance is, it is: Process$$EnhancerByMockitoWithCGLIB$$3db5579b
It isn't a true Process class. I suppose this is why it fails to retrieve the annotations.
Maybe there is some trick around this. Any ideas? Thanks guys.
I already tried to mock getClass() on the process instance but it is final, so it cannot be mocked.