changeset 706:cd5c87d96315

Merge: tests for mediator notifications
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 16 Aug 2013 14:54:09 +0200
parents b4242b7e7dfe
children 42b88709e41d
files build.xml cmdline/org/tmatesoft/hg/console/Merge.java src/org/tmatesoft/hg/core/HgMergeCommand.java test-data/test-repos.jar test/org/tmatesoft/hg/test/TestMerge.java
diffstat 5 files changed, 112 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/build.xml	Thu Aug 15 18:43:50 2013 +0200
+++ b/build.xml	Fri Aug 16 14:54:09 2013 +0200
@@ -27,7 +27,7 @@
 
 	<property name="junit.jar" value="lib/junit-4.8.2.jar" />
 	<property name="ssh.jar" value="lib/trilead-ssh2-1.0.0-build217.jar" />
-	<property name="ver.qualifier" value="m2" />
+	<property name="ver.qualifier" value="" />
 	<property name="version.lib" value="1.2" />
 	<property name="version.jar" value="${version.lib}${ver.qualifier}" />
 	<property name="compile-with-debug" value="yes"/>
@@ -87,6 +87,8 @@
 			<test name="org.tmatesoft.hg.test.TestConfigFileParser" />
 			<test name="org.tmatesoft.hg.test.TestTransaction" />
 			<test name="org.tmatesoft.hg.test.TestInflaterDataAccess" />
+			<test name="org.tmatesoft.hg.test.TestRevisionSet" />
+			<test name="org.tmatesoft.hg.test.TestRevisionMaps" />
 			<test name="org.tmatesoft.hg.test.TestHistory" />
 			<test name="org.tmatesoft.hg.test.TestManifest" />
 			<test name="org.tmatesoft.hg.test.TestStatus" />
@@ -110,12 +112,11 @@
 			<test name="org.tmatesoft.hg.test.TestRevert" />
 			<test name="org.tmatesoft.hg.test.TestCheckout" />
 			<test name="org.tmatesoft.hg.test.TestAddRemove" />
+			<test name="org.tmatesoft.hg.test.TestMerge" />
 			<test name="org.tmatesoft.hg.test.TestCommit" />
 			<test name="org.tmatesoft.hg.test.TestBlame" />
 			<test name="org.tmatesoft.hg.test.TestDiffHelper" />
 			<test name="org.tmatesoft.hg.test.TestRepositoryLock" />
-			<test name="org.tmatesoft.hg.test.TestRevisionSet" />
-			<test name="org.tmatesoft.hg.test.TestRevisionMaps" />
 			<test name="org.tmatesoft.hg.test.TestPush" />
 			<test name="org.tmatesoft.hg.test.TestPull" />
 			<test name="org.tmatesoft.hg.test.ComplexTest" />
--- a/cmdline/org/tmatesoft/hg/console/Merge.java	Thu Aug 15 18:43:50 2013 +0200
+++ b/cmdline/org/tmatesoft/hg/console/Merge.java	Fri Aug 16 14:54:09 2013 +0200
@@ -57,12 +57,11 @@
 	static class Dump implements HgMergeCommand.Mediator {
 
 		public void same(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
-			System.out.printf("Unchanged %s:%s", rev.getPath(), rev.getRevision().shortNotation());
+			System.out.printf("Unchanged %s:%s\n", rev.getPath(), rev.getRevision().shortNotation());
 		}
 
 		public void onlyA(HgFileRevision base, HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
-			System.out.printf("Left in first trunk only %s:%s", rev.getPath(), rev.getRevision().shortNotation());
-			
+			System.out.printf("Left in first trunk only %s:%s\n", rev.getPath(), rev.getRevision().shortNotation());
 		}
 
 		public void onlyB(HgFileRevision base, HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
--- a/src/org/tmatesoft/hg/core/HgMergeCommand.java	Thu Aug 15 18:43:50 2013 +0200
+++ b/src/org/tmatesoft/hg/core/HgMergeCommand.java	Fri Aug 16 14:54:09 2013 +0200
@@ -362,9 +362,7 @@
 				} else {
 					dirstateBuilder.recordMerged(file, fw.fmode(), fw.mtime(), fw.bytesWritten());
 				}
-			} else {
-				assert false;
-			}
+			} // else no resolution was chosen, fine with that
 		}
 
 		public void use(HgFileRevision rev) {
Binary file test-data/test-repos.jar has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/org/tmatesoft/hg/test/TestMerge.java	Fri Aug 16 14:54:09 2013 +0200
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2013 TMate Software Ltd
+ *  
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * For information on how to redistribute this software under
+ * the terms of a license other than GNU General Public License
+ * contact TMate Software at support@hg4j.com
+ */
+package org.tmatesoft.hg.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.tmatesoft.hg.core.HgCallbackTargetException;
+import org.tmatesoft.hg.core.HgFileRevision;
+import org.tmatesoft.hg.core.HgMergeCommand;
+import org.tmatesoft.hg.core.HgMergeCommand.Resolver;
+import org.tmatesoft.hg.repo.HgRepository;
+
+/**
+ * 
+ * @author Artem Tikhomirov
+ * @author TMate Software Ltd.
+ */
+public class TestMerge {
+
+	@Rule
+	public ErrorCollectorExt errorCollector = new ErrorCollectorExt();
+	
+	@Test
+	public void testMediator() throws Exception {
+		HgRepository repo = Configuration.get().find("merge-1");
+		HgMergeCommand cmd = new HgMergeCommand(repo);
+
+		MergeNotificationCollector c;
+		// (fastForward(file1, file2, file3) changes, newInB(file5), same(file4))
+		cmd.changeset(2).execute(c = new MergeNotificationCollector());
+		errorCollector.assertTrue("file1", c.fastForwardA.contains("file1"));
+		errorCollector.assertTrue("file2", c.fastForwardB.contains("file2"));
+		errorCollector.assertTrue("file3", c.fastForwardA.contains("file3"));
+		errorCollector.assertTrue("file4", c.same.contains("file4"));
+		errorCollector.assertTrue("file5", c.newInB.contains("file5"));
+		// (conflict(file1), onlyInA(file3), same(file4))
+		cmd.changeset(3).execute(c = new MergeNotificationCollector());
+		errorCollector.assertTrue("file1", c.conflict.contains("file1"));
+		errorCollector.assertTrue("file2", c.same.contains("file2"));
+		errorCollector.assertTrue("file3", c.onlyA.contains("file3"));
+		errorCollector.assertTrue("file4", c.same.contains("file4"));
+	}
+
+	private static class MergeNotificationCollector implements HgMergeCommand.Mediator {
+		public final List<String> same = new ArrayList<String>(); 
+		public final List<String> onlyA = new ArrayList<String>();
+		public final List<String> onlyB = new ArrayList<String>();
+		public final List<String> newInA = new ArrayList<String>();
+		public final List<String> newInB = new ArrayList<String>();
+		public final List<String> fastForwardA = new ArrayList<String>();
+		public final List<String> fastForwardB = new ArrayList<String>();
+		public final List<String> conflict = new ArrayList<String>();
+
+		
+		public void same(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
+			assert resolver != null;
+			same.add(rev.getPath().toString());
+		}
+		public void onlyA(HgFileRevision base, HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
+			assert resolver != null;
+			onlyA.add(rev.getPath().toString());
+		}
+		public void onlyB(HgFileRevision base, HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
+			assert resolver != null;
+			onlyB.add(rev.getPath().toString());
+		}
+		public void newInA(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
+			assert resolver != null;
+			newInA.add(rev.getPath().toString());
+		}
+		public void newInB(HgFileRevision rev, Resolver resolver) throws HgCallbackTargetException {
+			assert resolver != null;
+			newInB.add(rev.getPath().toString());
+		}
+		public void fastForwardA(HgFileRevision base, HgFileRevision first, Resolver resolver) throws HgCallbackTargetException {
+			assert resolver != null;
+			fastForwardA.add(first.getPath().toString());
+		}
+		public void fastForwardB(HgFileRevision base, HgFileRevision second, Resolver resolver) throws HgCallbackTargetException {
+			assert resolver != null;
+			fastForwardB.add(second.getPath().toString());
+		}
+		public void resolve(HgFileRevision base, HgFileRevision first, HgFileRevision second, Resolver resolver) throws HgCallbackTargetException {
+			assert resolver != null;
+			conflict.add(first.getPath().toString());
+		}
+	}
+}