comparison 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
comparison
equal deleted inserted replaced
558:154718ae23ed 559:6ca3d0c5b4bc
20 import static org.junit.Assert.assertTrue; 20 import static org.junit.Assert.assertTrue;
21 import static org.tmatesoft.hg.internal.RequiresFile.*; 21 import static org.tmatesoft.hg.internal.RequiresFile.*;
22 22
23 import java.io.File; 23 import java.io.File;
24 import java.io.FileOutputStream; 24 import java.io.FileOutputStream;
25 import java.io.FileWriter;
25 import java.io.IOException; 26 import java.io.IOException;
26 import java.util.ArrayList; 27 import java.util.ArrayList;
27 28
28 import org.tmatesoft.hg.internal.RepoInitializer; 29 import org.tmatesoft.hg.internal.RepoInitializer;
29 import org.tmatesoft.hg.repo.HgRepository; 30 import org.tmatesoft.hg.repo.HgRepository;
58 59
59 static File cloneRepoToTempLocation(HgRepository repo, String name, boolean noupdate) throws IOException, InterruptedException { 60 static File cloneRepoToTempLocation(HgRepository repo, String name, boolean noupdate) throws IOException, InterruptedException {
60 File testRepoLoc = createEmptyDir(name); 61 File testRepoLoc = createEmptyDir(name);
61 ExecHelper eh = new ExecHelper(new OutputParser.Stub(), testRepoLoc.getParentFile()); 62 ExecHelper eh = new ExecHelper(new OutputParser.Stub(), testRepoLoc.getParentFile());
62 ArrayList<String> cmd = new ArrayList<String>(); 63 ArrayList<String> cmd = new ArrayList<String>();
63 cmd.add("hg"); cmd.add("clone"); 64 cmd.add("hg");
65 cmd.add("clone");
64 if (noupdate) { 66 if (noupdate) {
65 cmd.add("--noupdate"); 67 cmd.add("--noupdate");
66 } 68 }
67 cmd.add(repo.getWorkingDir().toString()); 69 cmd.add(repo.getWorkingDir().toString());
68 cmd.add(testRepoLoc.getName()); 70 cmd.add(testRepoLoc.getName());
69 eh.run(cmd.toArray(new String[cmd.size()])); 71 eh.run(cmd.toArray(new String[cmd.size()]));
70 assertEquals("[sanity]", 0, eh.getExitValue()); 72 assertEquals("[sanity]", 0, eh.getExitValue());
71 return testRepoLoc; 73 return testRepoLoc;
72 } 74 }
73 75
74 static void modifyFileAppend(File f) throws IOException { 76 static void modifyFileAppend(File f, Object content) throws IOException {
75 assertTrue(f.isFile()); 77 assertTrue(f.isFile());
76 FileOutputStream fos = new FileOutputStream(f, true); 78 FileOutputStream fos = new FileOutputStream(f, true);
77 fos.write("XXX".getBytes()); 79 if (content == null) {
80 content = "XXX".getBytes();
81 }
82 if (content instanceof byte[]) {
83 fos.write((byte[]) content);
84 } else {
85 fos.write(String.valueOf(content).getBytes());
86 }
78 fos.close(); 87 fos.close();
79 } 88 }
80 89
90 static void createFile(File f, Object content) throws IOException {
91 if (content == null) {
92 f.createNewFile();
93 return;
94 }
95 if (content instanceof byte[]) {
96 FileOutputStream fos = new FileOutputStream(f);
97 fos.write((byte[]) content);
98 fos.close();
99 } else {
100 FileWriter fw = new FileWriter(f);
101 fw.write(String.valueOf(content));
102 fw.close();
103 }
104 }
81 } 105 }