package org.ovirt.engine.core.bll;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.lang.reflect.Field;

import org.junit.rules.TestWatcher;
import org.ovirt.engine.core.di.Injector;

public class InjectorRule extends TestWatcher {

    // create a new injector instance
    private Injector mockedInjector = mock(Injector.class);

    public InjectorRule() {
        try {
            // set the internal injector
            Field holdingMember = Injector.class.getDeclaredField("injector");
            holdingMember.setAccessible(true);
            holdingMember.set(Injector.class, mockedInjector);
        } catch (Exception e) {
            // if something bad happened the test shouldn't run
            throw new RuntimeException(e);
        }
    }

    public <T> void bind(Class<T> pureClsType, T instance) {
        when(mockedInjector.instanceOf(pureClsType)).thenReturn(instance);
    }

}

@@ -69,16 +69,57 @@
 o.mock;%0A
+import static org.mockito.Mockito.reset;%0A
 import s
@@ -220,16 +220,53 @@
 atcher;%0A
+import org.junit.runner.Description;%0A
 import o
@@ -399,16 +399,22 @@
 private 
+final 
 Injector
@@ -432,31 +432,8 @@
 ctor
- = mock(Injector.class)
 ;%0A%0A 
@@ -455,16 +455,131 @@
 torRule(
+) %7B%0A        mockedInjector = mock(Injector.class);%0A    %7D%0A%0A    private void overrideInjector(Injector mockedInjector
 ) %7B%0A    
@@ -970,24 +970,200 @@
    %7D%0A    %7D%0A%0A
+    @Override%0A    protected void finished(Description description) %7B%0A        super.finished(description);%0A        overrideInjector(null);%0A        reset(mockedInjector);%0A    %7D%0A%0A
     public %3C
@@ -1207,24 +1207,66 @@
 instance) %7B%0A
+        overrideInjector(mockedInjector);%0A
         when

Reset InjectorRule after each test case