PlaceObjectsInCollectionAction extends ContextAwareAction { @Override public boolean canHandle(ActionContext context) { actionContext = (ActionContextImpl) context; if (DetectGraphicsDevices.getInstance().getNumberGraphicsDevices() > DetectGraphicsDevices.MINIMUM_MONITOR_CHECK) { graphicsDeviceName = actionContext.getTargetHousing().getHostedFrame().getGraphicsConfiguration().getDevice().getIDstring(); graphicsDeviceName = graphicsDeviceName.replace("\\", ""); } selectedManifestations = context.getSelectedManifestations(); if (selectedManifestations.isEmpty()) { return false; } for (View manifestation : selectedManifestations) { if (manifestation.getManifestedComponent() == PlatformAccess.getPlatform().getRootComponent()) { return false; } } return true; } PlaceObjectsInCollectionAction(); @Override void actionPerformed(ActionEvent e); @Override boolean canHandle(ActionContext context); @Override boolean isEnabled();  }
@Test public void testCanHandle() throws Exception { if (DetectGraphicsDevices.getInstance().getNumberGraphicsDevices() == DetectGraphicsDevices.MINIMUM_MONITOR_CHECK) { ActionContextImpl context = new ActionContextImpl(); context.addTargetViewComponent(viewManifestation1); context.addTargetViewComponent(viewManifestation2); context.addTargetViewComponent(viewManifestation3); Assert.assertTrue(action.canHandle(context)); Assert.assertTrue(action.isEnabled()); setResult = true; action.actionPerformed(new ActionEvent(viewManifestation1, 0, "")); final Semaphore s = new Semaphore(1); s.acquire(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { s.release(); } }); s.tryAcquire(5, TimeUnit.SECONDS); Assert.assertEquals(successCt, 1); Assert.assertEquals(failCt, 0); Assert.assertNotNull(sourceComponents); Assert.assertEquals(sourceComponents.size(), 2); Assert.assertTrue(sourceComponents.contains(componentA)); Assert.assertTrue(sourceComponents.contains(componentB)); reset(); setResult = false; action.actionPerformed(new ActionEvent(viewManifestation1, 0, "")); Assert.assertEquals(successCt, 0); Assert.assertEquals(failCt, 1); Assert.assertEquals(sourceComponents.size(), 2); } }
@Test public void testCannotHandle() { if (DetectGraphicsDevices.getInstance().getNumberGraphicsDevices() == DetectGraphicsDevices.MINIMUM_MONITOR_CHECK) { ActionContextImpl failContext = new ActionContextImpl(); failContext.addTargetViewComponent(viewManifestation1); Assert.assertTrue(failAction.canHandle(failContext)); failContext.addTargetViewComponent(viewManifestationRootComponent); Assert.assertFalse(failAction.canHandle(failContext)); } }