@Test
	public void testEditModeHex2() throws Exception {
		// verify that the byte being edited cannot be in an instruction

		env.showTool();

		Address addr = getAddr(0x01002000);
		ToggleDockingAction action =
			(ToggleDockingAction) getAction(plugin, "Enable/Disable Byteviewer Editing");
		FieldLocation loc = getFieldLocation(addr);
		byte b = memory.getByte(addr);
		assertEquals((byte) 0x50, b);
		assertEquals(256, loc.getIndex().intValue());
		assertEquals(0, loc.getFieldNum());

		runSwing(() -> {
			ByteViewerComponent c = panel.getCurrentComponent();
			c.setCursorPosition(loc.getIndex(), loc.getFieldNum(), 0, 0);
			action.setSelected(true);
			action.actionPerformed(new DefaultActionContext());
		});
		assertTrue(action.isSelected());
		ByteViewerComponent c = panel.getCurrentComponent();
		assertEquals(ByteViewerComponentProvider.CHANGED_VALUE_COLOR, c.getFocusedCursorColor());

		runSwing(() -> {
			KeyEvent ev = new KeyEvent(c, 0, new Date().getTime(), 0, KeyEvent.VK_A, 'a');
			c.keyPressed(ev, loc.getIndex(), loc.getFieldNum(), loc.getRow(), loc.getCol(),
				c.getCurrentField());
		});

		program.flushEvents();
		waitForSwing();
		assertEquals(b, program.getMemory().getByte(addr));
		Color fg = ((ByteField) c.getCurrentField()).getForeground();
		if (fg != null) {
			assertEquals(ByteViewerComponentProvider.CURSOR_ACTIVE_COLOR, fg);
		}
		Window w = windowForComponent(plugin.getProvider().getComponent());
		String str = findLabelStr(w, "Tool Status");
		assertEquals("Editing not allowed: Instruction exists at address 01002000", str);
	}
Test editing in the Byte Viewer.
Ghidra/Features/ByteViewer/src/test.slow/java/ghidra/app/plugin/core/byteviewer/ByteViewerPlugin2Test.java