Mockito.when(mockPlatform.getMySandbox()).thenReturn(mockSandbox);
MockComponentRegistry registry = new MockComponentRegistry();
// Set the platform SPI
PlatformAccess platformAccess = new PlatformAccess();
platformAccess.setPlatform(mockPlatform);
// Case #1: test returned collection when adding selectedComponents to the new collection is successful
// Setup
TestBaseComponent collection = Mockito.mock(TestBaseComponent.class);
registry.setDefaultCollection(collection);
List<AbstractComponent> selectedComponents = Collections.singletonList(Mockito.mock(AbstractComponent.class));
registry.setExpectedResultForAddComponents(true);
// The test
AbstractComponent newCollection = registry.newCollection(selectedComponents);
Assert.assertSame(newCollection, collection);
// Case #2: test returned collection when adding selectedComponents to the new collection fails
// Setup
registry.clearRegistry();
registry.setDefaultCollection(collection);
registry.setExpectedResultForAddComponents(true);
// The test
newCollection = registry.newCollection(selectedComponents);
Assert.assertNotNull(newCollection);
// Tear down
platformAccess.setPlatform(null);
}