@Test
	public void testReplaceRefSource() throws Exception {
		mtf.initialize("NotepadMergeListingTest", new ProgramModifierListener() {
			@Override
			public void modifyLatest(ProgramDB program) {
				// P1 program
				try {
					ReferenceManager refMgr = program.getReferenceManager();
					refMgr.addMemoryReference(addr(program, "0x01001e81"),
						addr(program, "0x01001ea0"), RefType.DATA, SourceType.USER_DEFINED, 0);
					refMgr.addMemoryReference(addr(program, "0x01001ea0"),
						addr(program, "0x01001eba"), RefType.DATA, SourceType.IMPORTED, 0);
				}
				catch (Exception e) {
					Assert.fail(e.getMessage());
				}
			}

			@Override
			public void modifyPrivate(ProgramDB program) {
				// P2 program
				try {
					ReferenceManager refMgr = program.getReferenceManager();
					refMgr.addMemoryReference(addr(program, "0x01001e81"),
						addr(program, "0x01001ea0"), RefType.DATA, SourceType.IMPORTED, 0);
					refMgr.addMemoryReference(addr(program, "0x01001ea0"),
						addr(program, "0x01001eba"), RefType.DATA, SourceType.ANALYSIS, 0);
				}
				catch (Exception e) {
					Assert.fail(e.getMessage());
				}
			}
		});

		p1 = mtf.getResultProgram();
		p2 = mtf.getPrivateProgram();

		int txId = p1.startTransaction("Merge into Program 1");
		boolean commit = false;
		try {
			programMerge = new ProgramMergeManager(p1, p2);

			programMerge.setDiffFilter(new ProgramDiffFilter(ProgramDiffFilter.REFERENCE_DIFFS));
			programMerge.setMergeFilter(
				new ProgramMergeFilter(ProgramMergeFilter.REFERENCES, ProgramMergeFilter.REPLACE));
			AddressSet expectedDiffs = new AddressSet();
// For now we no longer want to detect source type differences since they can't be changed anyway.
//			expectedDiffs.addRange(addr(p1, "0x01001e81"), addr(p1, "0x01001e82"));
//			expectedDiffs.addRange(addr(p1, "0x01001ea0"), addr(p1, "0x01001ea1"));
			assertEquals(expectedDiffs, programMerge.getFilteredDifferences());

			AddressSet mergeSet = new AddressSet();
			mergeSet.addRange(addr(p1, "0x01001e4f"), addr(p1, "0x01001efc"));
			programMerge.merge(mergeSet, TaskMonitor.DUMMY);

			AddressSet newDiffs = new AddressSet();
			assertEquals(newDiffs, programMerge.getFilteredDifferences());

			ReferenceManager rm = p1.getReferenceManager();
			Reference[] refs;
			refs = rm.getReferencesFrom(addr(p1, "0x01001e81"));
			assertEquals(1, refs.length);
			assertEquals(SourceType.USER_DEFINED, refs[0].getSource());

			refs = rm.getReferencesFrom(addr(p1, "0x01001ea0"));
			assertEquals(1, refs.length);
			assertEquals(SourceType.IMPORTED, refs[0].getSource());
			commit = true;
		}
		finally {
			p1.endTransaction(txId, commit);
		}

		ProgramDiff latestProgramDiff = new ProgramDiff(p1, mtf.getLatestProgram());
		AddressSet latestAddrSet = new AddressSet();
// For now we no longer want to detect source type differences since they can't be changed anyway.
//		latestAddrSet.addRange(addr(p1, "0x01001e81"), addr(p1, "0x01001e82"));
//		latestAddrSet.addRange(addr(p1, "0x01001ea0"), addr(p1, "0x01001ea1"));
		latestProgramDiff.setFilter(new ProgramDiffFilter(ProgramDiffFilter.ALL_DIFFS));
		assertEquals(latestAddrSet,
			latestProgramDiff.getDifferences(latestProgramDiff.getFilter(), null));

		ProgramDiff myProgramDiff = new ProgramDiff(p1, mtf.getPrivateProgram());
		AddressSet myAddrSet = new AddressSet();
		myProgramDiff.setFilter(new ProgramDiffFilter(ProgramDiffFilter.ALL_DIFFS));
		assertEquals(myAddrSet, myProgramDiff.getDifferences(myProgramDiff.getFilter(), null));

	}
<CODE>ProgramMerge2Test</CODE> tests the <CODE>ProgramMerge</CODE> class
to verify it correctly merges various types of program differences.
The tests modify copies of the same program to cause differences
between these two programs, which can then be merged.
Ghidra/Features/Base/src/test.slow/java/ghidra/program/util/ProgramMerge2Test.java