示例#1
0
 @Before
 public void createContext() {
   if (ExtensionRegistry.getInstance() == null) {
     myExtensionRegistry = new ExtensionRegistry(null, null);
     myExtensionRegistry.init();
   }
 }
示例#2
0
 @After
 public void checkAndCleanup() {
   if (myExtensionRegistry != null) {
     assert myExtensionRegistry == ExtensionRegistry.getInstance();
     ExtensionRegistry.getInstance().dispose();
     assertNull(ExtensionRegistry.getInstance());
     this.myExtensionRegistry = null;
   }
 }
示例#3
0
 @Test
 public void singleExtension() {
   ExtensionPoint ep1 = mockExtensionPoint("ep1", EP1);
   ExtensionDescriptor ed =
       mockExtensionDescriptor(
           "ed1", new ExtensionPoint[] {ep1}, new Extension[] {mockExtension("e1", EP1)});
   ExtensionRegistry.getInstance().registerExtensionDescriptor(ed);
   assertEquals(ep1, ExtensionRegistry.getInstance().getExtensionPoint(EP1));
   ExtensionRegistry.getInstance().unregisterExtensionDescriptor(ed);
   assertNull(ExtensionRegistry.getInstance().getExtensionPoint(EP1));
 }
示例#4
0
 @Test
 public void reversedExtensions() {
   ExtensionPoint ep1 = mockExtensionPoint("ep1", EP1);
   ExtensionDescriptor ed1 =
       mockExtensionDescriptor("ed1", new ExtensionPoint[] {ep1}, new Extension[] {});
   ExtensionDescriptor ed2 =
       mockExtensionDescriptor(
           "ed2", new ExtensionPoint[] {}, new Extension[] {mockExtension("e1", EP1)});
   ExtensionRegistry.getInstance().registerExtensionDescriptor(ed2);
   ExtensionRegistry.getInstance().registerExtensionDescriptor(ed1);
   ExtensionRegistry.getInstance().unregisterExtensionDescriptor(ed1);
   ExtensionRegistry.getInstance().unregisterExtensionDescriptor(ed2);
 }
示例#5
0
  @Test
  public void allExtensions() {
    ExtensionPoint ep1 = mockExtensionPoint("ep1", EP1);
    ExtensionDescriptor ed1 =
        mockExtensionDescriptor("ed1", new ExtensionPoint[] {ep1}, new Extension[] {});
    ExtensionDescriptor ed2 =
        mockExtensionDescriptor(
            "ed2", new ExtensionPoint[] {}, new Extension[] {mockExtension("e1", EP1)});
    ExtensionDescriptor ed3 =
        mockExtensionDescriptor(
            "ed3", new ExtensionPoint[] {}, new Extension[] {mockExtension("e2", EP1)});
    ExtensionRegistry.getInstance().registerExtensionDescriptor(ed3);
    ExtensionRegistry.getInstance().registerExtensionDescriptor(ed2);
    ExtensionRegistry.getInstance().registerExtensionDescriptor(ed1);

    Iterable<Extension<?>> extensions = ep1.getExtensions();
    List<Extension> extensionList = new ArrayList();
    for (Iterator<Extension> it = ExtensionRegistry.getInstance().getExtensions(ep1).iterator();
        it.hasNext(); ) {
      extensionList.add(it.next());
    }
    assertSame(2, extensionList.size());
    Collections.sort(
        extensionList,
        new Comparator<Extension>() {
          @Override
          public int compare(Extension o1, Extension o2) {
            return String.CASE_INSENSITIVE_ORDER.compare(String.valueOf(o1), String.valueOf(o2));
          }
        });
    assertEquals("[e1, e2]", extensionList.toString());

    ExtensionRegistry.getInstance().unregisterExtensionDescriptor(ed3);
    ExtensionRegistry.getInstance().unregisterExtensionDescriptor(ed2);
    ExtensionRegistry.getInstance().unregisterExtensionDescriptor(ed1);
  }