aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkTestCase.java
blob: 8fa6a83670b0a46319151fe0b03a9c67440159ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
 * Copyright (C) 2009-2010, Google Inc. and others
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Distribution License v. 1.0 which is available at
 * https://www.eclipse.org/org/documents/edl-v10.php.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

package org.eclipse.jgit.revwalk;

import static org.junit.Assert.assertSame;

import java.time.Instant;
import java.util.Date;

import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.junit.TestRepository.CommitBuilder;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;

/** Support for tests of the {@link RevWalk} class. */
public abstract class RevWalkTestCase extends RepositoryTestCase {
	private TestRepository<Repository> util;

	protected RevWalk rw;

	@Override
	public void setUp() throws Exception {
		super.setUp();
		util = new TestRepository<>(db, createRevWalk());
		rw = util.getRevWalk();
	}

	protected RevWalk createRevWalk() {
		return new RevWalk(db);
	}

	// Use getInstant() instead
	@Deprecated
	protected Date getDate() {
		return Date.from(util.getInstant());
	}

	protected Instant getInstant() {
		return util.getInstant();
	}

	protected void tick(int secDelta) {
		util.tick(secDelta);
	}

	protected RevBlob blob(String content) throws Exception {
		return util.blob(content);
	}

	protected DirCacheEntry file(String path, RevBlob blob)
			throws Exception {
		return util.file(path, blob);
	}

	protected RevTree tree(DirCacheEntry... entries) throws Exception {
		return util.tree(entries);
	}

	protected RevObject get(RevTree tree, String path)
			throws Exception {
		return util.get(tree, path);
	}

	protected ObjectId unparsedCommit(ObjectId... parents) throws Exception {
		return util.unparsedCommit(parents);
	}

	protected RevCommit commit(RevCommit... parents) throws Exception {
		return util.commit(parents);
	}

	protected RevCommit commit(RevTree tree, RevCommit... parents)
			throws Exception {
		return util.commit(tree, parents);
	}

	protected RevCommit commit(int secDelta, RevCommit... parents)
			throws Exception {
		return util.commit(secDelta, parents);
	}

	protected RevCommit commit(final int secDelta, final RevTree tree,
			final RevCommit... parents) throws Exception {
		return util.commit(secDelta, tree, parents);
	}

	protected RevTag tag(String name, RevObject dst)
			throws Exception {
		return util.tag(name, dst);
	}

	protected CommitBuilder commitBuilder()
			throws Exception {
		return util.commit();
	}

	protected <T extends RevObject> T parseBody(T t) throws Exception {
		return util.parseBody(t);
	}

	protected void markStart(RevCommit commit) throws Exception {
		rw.markStart(commit);
	}

	protected void markUninteresting(RevCommit commit) throws Exception {
		rw.markUninteresting(commit);
	}

	protected void assertCommit(RevCommit exp, RevCommit act) {
		assertSame(exp, act);
	}
}