Mercurial > hg4j
comparison hg4j/src/test/java/org/tmatesoft/hg/test/TestManifest.java @ 213:6ec4af642ba8 gradle
Project uses Gradle for build - actual changes
author | Alexander Kitaev <kitaev@gmail.com> |
---|---|
date | Tue, 10 May 2011 10:52:53 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
212:edb2e2829352 | 213:6ec4af642ba8 |
---|---|
1 /* | |
2 * Copyright (c) 2011 TMate Software Ltd | |
3 * | |
4 * This program is free software; you can redistribute it and/or modify | |
5 * it under the terms of the GNU General Public License as published by | |
6 * the Free Software Foundation; version 2 of the License. | |
7 * | |
8 * This program is distributed in the hope that it will be useful, | |
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
11 * GNU General Public License for more details. | |
12 * | |
13 * For information on how to redistribute this software under | |
14 * the terms of a license other than GNU General Public License | |
15 * contact TMate Software at support@hg4j.com | |
16 */ | |
17 package org.tmatesoft.hg.test; | |
18 | |
19 import static org.hamcrest.CoreMatchers.equalTo; | |
20 import static org.hamcrest.CoreMatchers.notNullValue; | |
21 import static org.junit.Assert.assertTrue; | |
22 import static org.tmatesoft.hg.repo.HgRepository.TIP; | |
23 | |
24 import java.util.Collections; | |
25 import java.util.LinkedHashMap; | |
26 import java.util.LinkedList; | |
27 import java.util.Map; | |
28 | |
29 import org.junit.Rule; | |
30 import org.junit.Test; | |
31 import org.tmatesoft.hg.core.HgLogCommand.FileRevision; | |
32 import org.tmatesoft.hg.core.HgManifestCommand; | |
33 import org.tmatesoft.hg.core.Nodeid; | |
34 import org.tmatesoft.hg.repo.HgLookup; | |
35 import org.tmatesoft.hg.repo.HgRepository; | |
36 import org.tmatesoft.hg.util.Path; | |
37 | |
38 | |
39 /** | |
40 * | |
41 * @author Artem Tikhomirov | |
42 * @author TMate Software Ltd. | |
43 */ | |
44 public class TestManifest { | |
45 | |
46 @Rule | |
47 public ErrorCollectorExt errorCollector = new ErrorCollectorExt(); | |
48 | |
49 private final HgRepository repo; | |
50 private ManifestOutputParser manifestParser; | |
51 private ExecHelper eh; | |
52 final LinkedList<FileRevision> revisions = new LinkedList<FileRevision>(); | |
53 private HgManifestCommand.Handler handler = new HgManifestCommand.Handler() { | |
54 | |
55 public void file(FileRevision fileRevision) { | |
56 revisions.add(fileRevision); | |
57 } | |
58 | |
59 public void end(Nodeid manifestRevision) {} | |
60 public void dir(Path p) {} | |
61 public void begin(Nodeid manifestRevision) {} | |
62 }; | |
63 | |
64 public static void main(String[] args) throws Throwable { | |
65 TestManifest tm = new TestManifest(); | |
66 tm.testTip(); | |
67 tm.testFirstRevision(); | |
68 tm.testRevisionInTheMiddle(); | |
69 tm.errorCollector.verify(); | |
70 } | |
71 | |
72 public TestManifest() throws Exception { | |
73 this(new HgLookup().detectFromWorkingDir()); | |
74 } | |
75 | |
76 private TestManifest(HgRepository hgRepo) { | |
77 repo = hgRepo; | |
78 assertTrue(!repo.isInvalid()); | |
79 eh = new ExecHelper(manifestParser = new ManifestOutputParser(), null); | |
80 } | |
81 | |
82 @Test | |
83 public void testTip() throws Exception { | |
84 testRevision(TIP); | |
85 } | |
86 | |
87 @Test | |
88 public void testFirstRevision() throws Exception { | |
89 testRevision(0); | |
90 } | |
91 | |
92 @Test | |
93 public void testRevisionInTheMiddle() throws Exception { | |
94 int rev = repo.getManifest().getRevisionCount() / 2; | |
95 if (rev == 0) { | |
96 throw new IllegalStateException("Need manifest with few revisions"); | |
97 } | |
98 testRevision(rev); | |
99 } | |
100 | |
101 private void testRevision(int rev) throws Exception { | |
102 manifestParser.reset(); | |
103 eh.run("hg", "manifest", "--debug", "--rev", String.valueOf(rev == TIP ? -1 : rev)); | |
104 revisions.clear(); | |
105 new HgManifestCommand(repo).revision(rev).execute(handler); | |
106 report("manifest " + (rev == TIP ? "TIP:" : "--rev " + rev)); | |
107 } | |
108 | |
109 private void report(String what) throws Exception { | |
110 final Map<Path, Nodeid> cmdLineResult = new LinkedHashMap<Path, Nodeid>(manifestParser.getResult()); | |
111 for (FileRevision fr : revisions) { | |
112 Nodeid nid = cmdLineResult.remove(fr.getPath()); | |
113 errorCollector.checkThat("Extra " + fr.getPath() + " in Java result", nid, notNullValue()); | |
114 if (nid != null) { | |
115 errorCollector.checkThat("Non-matching nodeid:" + nid, nid, equalTo(fr.getRevision())); | |
116 } | |
117 } | |
118 errorCollector.checkThat("Non-matched entries from command line:", cmdLineResult, equalTo(Collections.<Path,Nodeid>emptyMap())); | |
119 } | |
120 } |