### Question:
ComponentScriptService implements ScriptService { public <T> T getInstance(Type roleType) { T result = null; ComponentManager cm = getContextComponentManager(); if (cm != null) { try { result = cm.getInstance(roleType); } catch (ComponentLookupException e) { setError(e); } } return result; }  @Deprecated ComponentManager getComponentManager(); ComponentManager getContextComponentManager(); ComponentManager getRootComponentManager(); ComponentManager getComponentManager(String namespace); T getInstance(Type roleType); T getInstance(Type roleType, String roleHint); Exception getLastError();  }### Answer:
@Test public void getComponentInstanceWithNoHintWhenNoProgrammingRights() throws Exception { when(this.dab.hasProgrammingRights()).thenReturn(false); assertNull(this.mocker.getComponentUnderTest().getInstance(SomeRole.class)); verify(this.contextComponentManager, never()).getInstance(SomeRole.class); }
@Test public void getComponentInstanceWithNoHintWhenProgrammingRights() throws Exception { when(this.dab.hasProgrammingRights()).thenReturn(true); SomeRole instance = mock(SomeRole.class); when(this.contextComponentManager.getInstance(SomeRole.class)).thenReturn(instance); assertSame(instance, this.mocker.getComponentUnderTest().getInstance(SomeRole.class)); }
@Test public void getComponentInstanceWithHintWhenNoProgrammingRights() throws Exception { when(this.dab.hasProgrammingRights()).thenReturn(false); assertNull(this.mocker.getComponentUnderTest().getInstance(SomeRole.class, "hint")); verify(this.contextComponentManager, never()).getInstance(SomeRole.class, "hint"); }
@Test public void getComponentInstanceWithHintWhenProgrammingRights() throws Exception { when(this.dab.hasProgrammingRights()).thenReturn(true); SomeRole instance = mock(SomeRole.class); when(this.contextComponentManager.getInstance(SomeRole.class, "hint")).thenReturn(instance); assertSame(instance, this.mocker.getComponentUnderTest().getInstance(SomeRole.class, "hint")); }