private static void ensureInit() {
if (!initialized) {
synchronized (MockRegistry.class) {
if (!initialized) {
final TestInstance instance = SystemInstance.get().getComponent(TestInstance.class);
if (instance != null) {
Class<?> current = instance.getTestClass();
while (!current.equals(Object.class)) {
for (Field f : current.getDeclaredFields()) {
for (Annotation annotation : f.getAnnotations()) {
if (annotation.annotationType().getName().startsWith("org.mockito.")) {
final boolean acc = f.isAccessible();
try {
f.setAccessible(true);
final Object mockInstance = f.get(instance.getInstance());
if (Mock.class.equals(annotation.annotationType())) {
final Mock mock = (Mock) annotation;
if (!"".equals(mock.name())) {
mockInstancesByName.put(mock.name(), mockInstance);