diff test/org/tmatesoft/hg/test/RepoUtils.java @ 559:6ca3d0c5b4bc

Commit: tests and fixes for defects discovered
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Mon, 25 Feb 2013 19:48:20 +0100
parents 2813a26b8999
children 4e6179bde4fc
line wrap: on
line diff
--- a/test/org/tmatesoft/hg/test/RepoUtils.java	Mon Feb 25 18:41:44 2013 +0100
+++ b/test/org/tmatesoft/hg/test/RepoUtils.java	Mon Feb 25 19:48:20 2013 +0100
@@ -22,6 +22,7 @@
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.util.ArrayList;
 
@@ -60,7 +61,8 @@
 		File testRepoLoc = createEmptyDir(name);
 		ExecHelper eh = new ExecHelper(new OutputParser.Stub(), testRepoLoc.getParentFile());
 		ArrayList<String> cmd = new ArrayList<String>();
-		cmd.add("hg"); cmd.add("clone");
+		cmd.add("hg");
+		cmd.add("clone");
 		if (noupdate) {
 			cmd.add("--noupdate");
 		}
@@ -71,11 +73,33 @@
 		return testRepoLoc;
 	}
 
-	static void modifyFileAppend(File f) throws IOException {
+	static void modifyFileAppend(File f, Object content) throws IOException {
 		assertTrue(f.isFile());
 		FileOutputStream fos = new FileOutputStream(f, true);
-		fos.write("XXX".getBytes());
+		if (content == null) {
+			content = "XXX".getBytes();
+		}
+		if (content instanceof byte[]) {
+			fos.write((byte[]) content);
+		} else {
+			fos.write(String.valueOf(content).getBytes());
+		}
 		fos.close();
 	}
 
+	static void createFile(File f, Object content) throws IOException {
+		if (content == null) {
+			f.createNewFile();
+			return;
+		}
+		if (content instanceof byte[]) {
+			FileOutputStream fos = new FileOutputStream(f);
+			fos.write((byte[]) content);
+			fos.close();
+		} else {
+			FileWriter fw = new FileWriter(f);
+			fw.write(String.valueOf(content));
+			fw.close();
+		}
+	}
 }