Install TestDialogManager
I wish to use com.google.gct.idea.git.TestDialogManager in a unit test. My test which starts like this:
public class MyTest extends LightIdeaTestCase {
private TestDialogManager myDialogManager;
@Override
protected final void setUp() throws Exception {
super.setUp();
myDialogManager = (TestDialogManager) ServiceManager.getService(DialogManager.class);
ServiceManager.getService(DialogManager.class) returns an instance of the superclass git4idea.DialogManager rather than the TestDialogManager. How can I tell ServiceManager to use a TestDialogManager in the context of the unit test?
Please sign in to leave a comment.
Have you tried to do explicit registration calls, i.g.
MockComponentManager.registerService(DialogManager.class,
TestDialogManager.class) ?
On 10/5/2015 8:50 PM, Elliotte Harold wrote:
>
>
>
>
>
>
>
>
>
This still does not work:
Disposable disposable = new SimpleDisposable();
MockComponentManager componentManager = new MockComponentManager(null, disposable);
componentManager.registerService(DialogManager.class, TestDialogManager.class);
myDialogManager = (TestDialogManager) ServiceManager.getService(DialogManager.class);'
Same error as before. There may be further registration and setup steps I'm missing. Is this documented anywhere?
This also doesn't seem to work:
myProject = new MockProject(new DefaultPicoContainer(), disposable);
myProject.registerService(DialogManager.class, TestDialogManager.class);
myDialogManager = (TestDialogManager) ServiceManager.getService(DialogManager.class);
MockComponentManager.registerService is implemented like following:
public serviceImplementation) {
myPicoContainer.unregisterComponent(serviceInterface.getName());
myPicoContainer.registerComponentImplementation(serviceInterface.getName(),
serviceImplementation);
}
so you need to take PicoContainer out of Application instance, cast it
to MutablePicoContainer and do the registration as code above
On 10/12/2015 5:01 PM, Elliotte Harold wrote:
>
>
>
Thanks. That seems to have done it. I also needed to make sure to reset the original dialog manager class in the tearDown method.
Everything now passes locally, though for as yet unknown reasons I'm now seeing NullPointerExceptions in IdeaTestUtil.getMockJdk17() when I run the tests on Travis.
This may be a consequence of this earlier exception:
Possibly something in my mucking with static state cuases the cleanup to fail.