Common { public static void cancelMacroSafe(final ContextCommand command, final String reason) { final Context context = command.context(); final LegacyService legacyService = context.getService(LegacyService.class); if (!legacyService.getIJ1Helper().isMacro()) { command.cancel(reason); return; } command.cancel(null); final LogService logService = context.getService(LogService.class); logService.error("Plugin cancelled: " + reason); }  static LUT makeFire(); static ImgPlus<BitType> toBitTypeImgPlus(
		final OpEnvironment ops, final ImgPlus<C> imgPlus); static boolean warnAnisotropy(final ImagePlus image,
		final UIService uiService); static void cancelMacroSafe(final ContextCommand command, final String reason);  }
@Test public void testCancelMacroSafeCancelsNormallyIfNotMacro() { final String reason = "No."; final IJ1Helper ij1Helper = mock(IJ1Helper.class); when(ij1Helper.isMacro()).thenReturn(false); final LegacyService legacyService = mock(LegacyService.class); when(legacyService.getIJ1Helper()).thenReturn(ij1Helper); final Context context = mock(Context.class); when(context.getService(LegacyService.class)).thenReturn(legacyService); final ContextCommand command = mock(ContextCommand.class); when(command.context()).thenReturn(context); Common.cancelMacroSafe(command, reason); verify(command).cancel(reason); }
@Test public void testCancelMacroSafeLogsErrorWhenMacro() { final String reason = "No."; final String expectedError = "Plugin cancelled: " + reason; final IJ1Helper ij1Helper = mock(IJ1Helper.class); when(ij1Helper.isMacro()).thenReturn(true); final LogService logService = mock(LogService.class); final LegacyService legacyService = mock(LegacyService.class); when(legacyService.getIJ1Helper()).thenReturn(ij1Helper); final Context context = mock(Context.class); when(context.getService(LegacyService.class)).thenReturn(legacyService); when(context.getService(LogService.class)).thenReturn(logService); final ContextCommand command = mock(ContextCommand.class); when(command.context()).thenReturn(context); Common.cancelMacroSafe(command, reason); verify(logService).error(expectedError); }
@Test public void testCancelMacroSafeCancelsWithNullWhenMacro() { final String reason = "No."; final IJ1Helper ij1Helper = mock(IJ1Helper.class); when(ij1Helper.isMacro()).thenReturn(true); final LogService logService = mock(LogService.class); final LegacyService legacyService = mock(LegacyService.class); when(legacyService.getIJ1Helper()).thenReturn(ij1Helper); final Context context = mock(Context.class); when(context.getService(LegacyService.class)).thenReturn(legacyService); when(context.getService(LogService.class)).thenReturn(logService); final ContextCommand command = mock(ContextCommand.class); when(command.context()).thenReturn(context); Common.cancelMacroSafe(command, reason); verify(command).cancel(null); }