FitEllipsoidWrapper extends BoneJCommand { @Override public void run() { if (!initPointROIs()) { cancelMacroSafe(this, "Please populate ROI Manager with at least " + MIN_DATA + " point ROIs"); return; } statusService.showStatus("Fit ellipsoid: solving ellipsoid equation"); statusService.showProgress(0, 2); final Matrix4dc quadric = (Matrix4dc) opService.run(Quadric.class, points); statusService.showStatus("Fit ellipsoid: determining ellipsoid parameters"); statusService.showProgress(1, 2); @SuppressWarnings("unchecked") final Optional<Ellipsoid> result = (Optional<Ellipsoid>) opService.run( QuadricToEllipsoid.class, quadric); if (!result.isPresent()) { cancelMacroSafe(this, "Can't fit ellipsoid to points.\n" + "Try adding more point ROIs to the ROI Manager and try again."); return; } addResults(result.get()); resultsTable = SharedTable.getTable(); reportUsage(); }  @Override void run();  }
@Test public void testNullROIManagerCancelsPlugin() throws Exception { final ImagePlus imagePlus = NewImage.createImage("", 5, 5, 5, 8, 1); final CommandModule module = command().run( FitEllipsoidWrapper.class, true, "inputImage", imagePlus).get(); assertTrue("No ROI Manager should have cancelled the plugin", module .isCanceled()); assertTrue("Cancel reason is incorrect", module.getCancelReason() .startsWith("Please populate ROI Manager with at least " + Quadric.MIN_DATA)); verify(MOCK_UI, timeout(1000)).dialogPrompt(anyString(), anyString(), any(), any()); }