SurfaceAreaWrapper extends BoneJCommand { @Override public void run() { statusService.showStatus("Surface area: initialising"); subspaces = find3DSubspaces(inputImage); matchOps(subspaces.get(0).interval); prepareResults(); final Map<String, Mesh> meshes = createMeshes(subspaces); if (exportSTL) { if (!getFileName()) { return; } saveMeshes(meshes); } calculateAreas(meshes); resultsTable = SharedTable.getTable(); reportUsage(); }  @Override void run();  }
@Test public void testMismatchingCalibrationsShowsWarningDialog() throws Exception { final String unit = "mm"; final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, unit, 0.5); final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, unit, 0.6); final DefaultLinearAxis zAxis = new DefaultLinearAxis(Axes.Z, unit, 0.6); final DefaultLinearAxis tAxis = new DefaultLinearAxis(Axes.TIME); final Img<BitType> img = ArrayImgs.bits(1, 1, 1, 1); final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis, yAxis, zAxis, tAxis); final SwingDialogPrompt mockPrompt = mock(SwingDialogPrompt.class); when(MOCK_UI.dialogPrompt(eq(SurfaceAreaWrapper.BAD_SCALING), anyString(), eq( WARNING_MESSAGE), any())).thenReturn(mockPrompt); command().run(SurfaceAreaWrapper.class, true, "inputImage", imgPlus, "exportSTL", false).get(); verify(MOCK_UI, timeout(1000).times(1)).dialogPrompt(eq( SurfaceAreaWrapper.BAD_SCALING), anyString(), eq(WARNING_MESSAGE), any()); }
@Test public void testResults() throws Exception { final double scale = 0.1; final String unit = "mm"; final int width = 3; final int height = 3; final int depth = 3; final double expectedArea = ((width - 1) * (height - 1) * 2 + (width - 1) * (depth - 1) * 2 + (height - 1) * (depth - 1) * 2) * (scale * scale); final String[] expectedHeaders = { ("Surface area (" + unit + "²)") }; final double[] expectedValues = { 0, expectedArea, expectedArea, 0 }; final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, unit, scale); final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, unit, scale); final DefaultLinearAxis zAxis = new DefaultLinearAxis(Axes.Z, unit, scale); final DefaultLinearAxis cAxis = new DefaultLinearAxis(Axes.CHANNEL); final DefaultLinearAxis tAxis = new DefaultLinearAxis(Axes.TIME); final Img<BitType> img = ArrayImgs.bits(width + 2, height + 2, depth + 2, 2, 2); final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis, yAxis, zAxis, cAxis, tAxis); final RandomAccess<BitType> access = imgPlus.randomAccess(); for (int z = 1; z <= depth; z++) { for (int y = 1; y <= height; y++) { for (int x = 1; x <= width; x++) { access.setPosition(new long[] { x, y, z, 1, 0 }); access.get().setOne(); access.setPosition(new long[] { x, y, z, 0, 1 }); access.get().setOne(); } } } final CommandModule module = command().run(SurfaceAreaWrapper.class, true, "inputImage", imgPlus, "exportSTL", false).get(); @SuppressWarnings("unchecked") final List<DefaultColumn<Double>> table = (List<DefaultColumn<Double>>) module.getOutput("resultsTable"); assertNotNull(table); assertEquals("Wrong number of columns", 1, table.size()); for (int i = 0; i < 1; i++) { final DefaultColumn<Double> column = table.get(i); assertEquals("A column has wrong number of rows", 4, column.size()); assertEquals("A column has an incorrect header", expectedHeaders[i], column.getHeader()); for (int j = 0; j < column.size(); j++) { assertEquals("Column has an incorrect value", expectedValues[j], column.get(j), 1e-12); } } }
@Test public void testFileWritingExceptionsShowErrorDialog() throws Exception { final File exceptionsThrowingFile = mock(File.class); when(exceptionsThrowingFile.getAbsolutePath()).thenReturn("/.stl/"); final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, "mm"); final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, "mm"); final DefaultLinearAxis zAxis = new DefaultLinearAxis(Axes.Z, "mm"); final Img<BitType> img = ArrayImgs.bits(1, 1, 1); final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis, yAxis, zAxis); final SwingDialogPrompt mockPrompt = mock(SwingDialogPrompt.class); when(MOCK_UI.chooseFile(any(File.class), anyString())).thenReturn( exceptionsThrowingFile); when(MOCK_UI.dialogPrompt(startsWith(STL_WRITE_ERROR), anyString(), eq( ERROR_MESSAGE), any())).thenReturn(mockPrompt); command().run(SurfaceAreaWrapper.class, true, "inputImage", imgPlus, "exportSTL", true).get(); verify(MOCK_UI, timeout(1000).times(1)).dialogPrompt(startsWith( STL_WRITE_ERROR), anyString(), eq(ERROR_MESSAGE), any()); }