CoreComponentProvider extends AbstractComponentProvider implements DefaultComponentProvider { @Override public AbstractComponent createDropbox(String userId) { Platform platform = PlatformAccess.getPlatform(); AbstractComponent dropbox = platform.getComponentRegistry().newInstance(TelemetryUserDropBoxComponent.class.getName()); ComponentInitializer dropboxCapability = dropbox.getCapability(ComponentInitializer.class); dropboxCapability.setCreator(userId); dropboxCapability.setOwner("*"); dropbox.setDisplayName(userId + resource.getString("user_drop_box")); return dropbox; }  @Override Collection<ComponentTypeInfo> getComponentTypes(); @Override Collection<ViewInfo> getViews(String componentTypeId); @Override Collection<PolicyInfo> getPolicyInfos(); @Override Class<? extends AbstractComponent> getBrokenComponent(); @Override AbstractComponent createDropbox(String userId); @Override AbstractComponent createSandbox(String userId); @Override void createDefaultComponents(); @Override ProviderDelegate getProviderDelegate(); @Override T getAsset(TypeInfo<?> typeInfo, Class<T> assetClass);  }
@Test public void testCreateDropBox() { String id = "someTestUser"; CoreComponentRegistry mockRegistry = Mockito.mock(CoreComponentRegistry.class); Mockito.when(mockPlatform.getComponentRegistry()).thenReturn(mockRegistry); Mockito.when(mockRegistry.newInstance(Mockito.anyString())) .thenAnswer(new Answer<AbstractComponent>() { @Override public AbstractComponent answer(InvocationOnMock invocation) throws Throwable { return AbstractComponent.class.cast( Class.forName(invocation.getArguments()[0].toString()).newInstance() ); } }); AbstractComponent comp = provider.createDropbox(id); Assert.assertEquals(comp.getClass(), TelemetryUserDropBoxComponent.class); Assert.assertEquals(comp.getOwner(), "*"); Assert.assertEquals(comp.getCreator(), id); User mockUser = Mockito.mock(User.class); Mockito.when(mockPlatform.getCurrentUser()).thenReturn(mockUser); Mockito.when(mockUser.getUserId()).thenReturn(id); PolicyContext context = new PolicyContext(); AbstractComponent mockChild = Mockito.mock(AbstractComponent.class); context.setProperty(PolicyContext.PropertyName.TARGET_COMPONENT.getName(), comp); context.setProperty(PolicyContext.PropertyName.SOURCE_COMPONENTS.getName(), Collections.singleton(mockChild)); Assert.assertTrue(new CanRemoveComponentPolicy().execute(context).getStatus()); }