@Test
	public void testBlockerCancelled() throws Exception {
		env.showTool();
		loadProgram("notepad_empty");

		TaskMonitor myMonitor = new TaskMonitorAdapter();
		myMonitor.setCancelEnabled(true);

		AutoAnalysisManager mgr = AutoAnalysisManager.getAnalysisManager(program);
		try {
			mgr.scheduleWorker(new AnalysisWorker() {

				@Override
				public String getWorkerName() {
					return "CancelTest";
				}

				@Override
				public boolean analysisWorkerCallback(Program p, Object workerContext,
						TaskMonitor monitor) throws Exception, CancelledException {

					// Click Cancel on modal blocker dialog 
					Window blockerDialog = waitForWindow("CancelTest");
					assertNotNull(blockerDialog);
					pressButtonByText(blockerDialog, "Cancel");

					Window confirmDialog = waitForWindow("Cancel?");
					assertNotNull(confirmDialog);
					pressButtonByText(confirmDialog, "Yes");
					waitForSwing();

					monitor.checkCancelled();

					Assert.fail("CancelledException expected");

					return false;
				}
			}, null, false, myMonitor);
			Assert.fail("CancelledException expected");
		}
		catch (CancelledException e) {
			// expected
		}
		catch (Exception e) {
			failWithException("Unexpected exception", e);
		}

		assertTrue(myMonitor.isCancelled());
	}
Test attempt to run an AnalysisWorker from swing thread
@throws Exception
Ghidra/Features/Base/src/test.slow/java/ghidra/app/plugin/core/AutoAnalysisWorkerTest.java