Roy Golan has uploaded a new change for review. Change subject: core: create a Junit rule for o.o.e.c.di.Injector ......................................................................
core: create a Junit rule for o.o.e.c.di.Injector add an InjectorRule to use when testing legacy code with static injection. Change-Id: I8276e8514135f466b59fae384678b2a0a54cf854 Signed-off-by: Roy Golan <[email protected]> --- A backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/InjectorRule.java 1 file changed, 31 insertions(+), 0 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/33/40733/1 diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/InjectorRule.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/InjectorRule.java new file mode 100644 index 0000000..55bdc73 --- /dev/null +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/InjectorRule.java @@ -0,0 +1,31 @@ +package org.ovirt.engine.core.bll; + +import org.junit.rules.TestWatcher; +import org.mockito.Mockito; +import org.ovirt.engine.core.di.Injector; + +import java.lang.reflect.Field; + +public class InjectorRule extends TestWatcher{ + + // create a new injector instance + private Injector mockedInjector= Mockito.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) { + Mockito.when(mockedInjector.instanceOf(pureClsType)).thenReturn(instance); + } + + +} -- To view, visit https://gerrit.ovirt.org/40733 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I8276e8514135f466b59fae384678b2a0a54cf854 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Roy Golan <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
