View Javadoc
1   /*
2    * Copyright (C) 2009-2010, Google Inc. and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  
11  package org.eclipse.jgit.revwalk;
12  
13  import static org.junit.Assert.assertSame;
14  
15  import java.util.Date;
16  
17  import org.eclipse.jgit.dircache.DirCacheEntry;
18  import org.eclipse.jgit.junit.RepositoryTestCase;
19  import org.eclipse.jgit.junit.TestRepository;
20  import org.eclipse.jgit.junit.TestRepository.CommitBuilder;
21  import org.eclipse.jgit.lib.ObjectId;
22  import org.eclipse.jgit.lib.Repository;
23  
24  /** Support for tests of the {@link RevWalk} class. */
25  public abstract class RevWalkTestCase extends RepositoryTestCase {
26  	private TestRepository<Repository> util;
27  
28  	protected RevWalk rw;
29  
30  	@Override
31  	public void setUp() throws Exception {
32  		super.setUp();
33  		util = new TestRepository<>(db, createRevWalk());
34  		rw = util.getRevWalk();
35  	}
36  
37  	protected RevWalk createRevWalk() {
38  		return new RevWalk(db);
39  	}
40  
41  	protected Date getDate() {
42  		return util.getDate();
43  	}
44  
45  	protected void tick(int secDelta) {
46  		util.tick(secDelta);
47  	}
48  
49  	protected RevBlob blob(String content) throws Exception {
50  		return util.blob(content);
51  	}
52  
53  	protected DirCacheEntry file(String path, RevBlob blob)
54  			throws Exception {
55  		return util.file(path, blob);
56  	}
57  
58  	protected RevTree tree(DirCacheEntry... entries) throws Exception {
59  		return util.tree(entries);
60  	}
61  
62  	protected RevObject get(RevTree tree, String path)
63  			throws Exception {
64  		return util.get(tree, path);
65  	}
66  
67  	protected ObjectId unparsedCommit(ObjectId... parents) throws Exception {
68  		return util.unparsedCommit(parents);
69  	}
70  
71  	protected RevCommit commit(RevCommit... parents) throws Exception {
72  		return util.commit(parents);
73  	}
74  
75  	protected RevCommit commit(RevTree tree, RevCommit... parents)
76  			throws Exception {
77  		return util.commit(tree, parents);
78  	}
79  
80  	protected RevCommit commit(int secDelta, RevCommit... parents)
81  			throws Exception {
82  		return util.commit(secDelta, parents);
83  	}
84  
85  	protected RevCommit commit(final int secDelta, final RevTree tree,
86  			final RevCommit... parents) throws Exception {
87  		return util.commit(secDelta, tree, parents);
88  	}
89  
90  	protected RevTag tag(String name, RevObject dst)
91  			throws Exception {
92  		return util.tag(name, dst);
93  	}
94  
95  	protected CommitBuilder commitBuilder()
96  			throws Exception {
97  		return util.commit();
98  	}
99  
100 	protected <T extends RevObject> T parseBody(T t) throws Exception {
101 		return util.parseBody(t);
102 	}
103 
104 	protected void markStart(RevCommit commit) throws Exception {
105 		rw.markStart(commit);
106 	}
107 
108 	protected void markUninteresting(RevCommit commit) throws Exception {
109 		rw.markUninteresting(commit);
110 	}
111 
112 	protected void assertCommit(RevCommit exp, RevCommit act) {
113 		assertSame(exp, act);
114 	}
115 }