Skip to content

Commit

Permalink
Don't allow duplicate UI Providers for the same class
Browse files Browse the repository at this point in the history
- Downstream plug-ins should not be able to register and replace the in-built UI Providers because there is no guarantee of the order of registration and no guarantee of expected beahviour if several plug-ins do this.
  • Loading branch information
Phillipus committed Sep 13, 2023
1 parent 4b25ec5 commit 7f6f5fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void registerProviders() {
}

void registerProvider(IObjectUIProvider provider) {
if(provider != null && provider.providerFor() != null) {
if(provider != null && provider.providerFor() != null && map.get(provider.providerFor()) == null) {
map.put(provider.providerFor(), provider);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ public void testRegisterProvider() {
assertNotNull(factory.getProviderForClass(eClass));
assertEquals(1, factory.map.size());
}

@Test
public void testNoDuplicateProviders() {
IObjectUIProvider provider1 = mock(IObjectUIProvider.class);
IObjectUIProvider provider2 = mock(IObjectUIProvider.class);

EClass eClass = mock(EClass.class);
when(provider1.providerFor()).thenReturn(eClass);
when(provider2.providerFor()).thenReturn(eClass);

factory.registerProvider(provider1);
assertSame(provider1, factory.getProviderForClass(eClass));

factory.registerProvider(provider2);
assertSame(provider1, factory.getProviderForClass(eClass));
}

@Test
public void testGetProvider_EObject_ArchiMateElement() {
Expand Down

0 comments on commit 7f6f5fc

Please sign in to comment.