Skip to content

Commit 04e1cc9

Browse files
author
Vladimir Kotal
committed
refactor tests
1 parent 560581e commit 04e1cc9

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

opengrok-indexer/src/test/java/org/opengrok/indexer/history/GitRepositoryTest.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ private void checkCurrentVersion(File root, int timestamp, String commitId, Stri
108108
}
109109

110110
@Test
111-
public void testDetermineCurrentVersion() throws Exception {
112-
// First test with empty repository.
111+
public void testDetermineCurrentVersionWithEmptyRepository() throws Exception {
113112
File emptyGitDir = new File(repository.getSourceRoot(), "gitEmpty");
114113
try (Git git = Git.init().setDirectory(emptyGitDir).call()) {
115114
GitRepository gitrepo = (GitRepository) RepositoryFactory.getRepository(git.getRepository().getWorkTree());
@@ -118,16 +117,25 @@ public void testDetermineCurrentVersion() throws Exception {
118117
assertNull(ver);
119118
FileUtilities.removeDirs(emptyGitDir);
120119
}
120+
}
121121

122-
// Next, check known repository with some commits.
122+
@Test
123+
public void testDetermineCurrentVersionOfKnownRepository() throws Exception {
123124
File root = new File(repository.getSourceRoot(), "git");
124125
GitRepository gitrepo = (GitRepository) RepositoryFactory.getRepository(root);
125126
assertNotNull(gitrepo);
126127
String ver = gitrepo.determineCurrentVersion();
127128
assertNotNull(ver);
128129
Date date = new Date((long) (1485438707) * 1000);
129130
assertEquals(Repository.format(date) + " 84599b3 Kryštof Tulinger renaming directories", ver);
131+
}
130132

133+
@Test
134+
public void testDetermineCurrentVersionAfterChange() throws Exception {
135+
File root = new File(repository.getSourceRoot(), "git");
136+
GitRepository gitrepo = (GitRepository) RepositoryFactory.getRepository(root);
137+
assertNotNull(gitrepo);
138+
String ver;
131139
// Clone under source root to avoid problems with prohibited symlinks.
132140
File localPath = new File(repository.getSourceRoot(), "gitCloneTestCurrentVersion");
133141
String cloneUrl = root.toURI().toString();
@@ -167,17 +175,23 @@ public void testDetermineCurrentVersion() throws Exception {
167175
}
168176

169177
@Test
170-
public void testDetermineBranch() throws Exception {
178+
public void testDetermineBranchBasic() throws Exception {
171179
// First check branch of known repository.
172180
File root = new File(repository.getSourceRoot(), "git");
173181
GitRepository gitrepo = (GitRepository) RepositoryFactory.getRepository(root);
174182
String branch = gitrepo.determineBranch();
175183
Assert.assertNotNull(branch);
176184
assertEquals("master", branch);
185+
}
177186

178-
// Next, clone the repository and create new branch there.
187+
@Test
188+
public void testDetermineBranchAfterChange() throws Exception {
189+
// Clone the test repository and create new branch there.
179190
// Clone under source root to avoid problems with prohibited symlinks.
191+
File root = new File(repository.getSourceRoot(), "git");
180192
File localPath = new File(repository.getSourceRoot(), "gitCloneTestDetermineBranch");
193+
GitRepository gitrepo = (GitRepository) RepositoryFactory.getRepository(root);
194+
String branch;
181195
String cloneUrl = root.toURI().toString();
182196
try (Git gitClone = Git.cloneRepository()
183197
.setURI(cloneUrl)
@@ -198,13 +212,19 @@ public void testDetermineBranch() throws Exception {
198212
}
199213

200214
@Test
201-
public void testDetermineParent() throws Exception {
215+
public void testDetermineParentEmpty() throws Exception {
202216
File root = new File(repository.getSourceRoot(), "git");
203217
GitRepository gitrepo = (GitRepository) RepositoryFactory.getRepository(root);
204218
String parent = gitrepo.determineParent();
205219
Assert.assertNull(parent);
220+
}
206221

207-
// Next, clone the repository and create new origin there.
222+
@Test
223+
public void testDetermineParent() throws Exception {
224+
File root = new File(repository.getSourceRoot(), "git");
225+
GitRepository gitrepo = (GitRepository) RepositoryFactory.getRepository(root);
226+
String parent;
227+
// Clone the repository and create new origin there.
208228
// Clone under source root to avoid problems with prohibited symlinks.
209229
File localPath = new File(repository.getSourceRoot(), "gitCloneTestDetermineParent");
210230
String cloneUrl = root.toURI().toString();

0 commit comments

Comments
 (0)