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?

5 comments
Comment actions Permalink

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:

I wish to use com.google.gct.idea.git.testDailogManager for a unit test. However in 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?

>

---
Original message URL: https://devnet.jetbrains.com/message/5559967#5559967

>

0
Comment actions Permalink

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?
0
Comment actions Permalink

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);

0
Comment actions Permalink

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:

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);

>

---
Original message URL: https://devnet.jetbrains.com/message/5560419#5560419

>

0
Comment actions Permalink

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:

com.google.gct.idea.git.GcpHttpAuthProviderTest > testForGcpPrompt STANDARD_ERROR
    java.lang.NullPointerException
         at com.intellij.testFramework.PlatformTestCase.cleanupApplicationCaches(PlatformTestCase.java:354)
         at com.intellij.testFramework.LightPlatformTestCase$9.run(LightPlatformTestCase.java:708)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:216)
         at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:678)
         at java.awt.EventQueue.access$400(EventQueue.java:96)
         at java.awt.EventQueue$2.run(EventQueue.java:639)


Possibly something in my mucking with static state cuases the cleanup to fail.

0

Please sign in to leave a comment.