Skip to content

Commit 64aaebc

Browse files
committed
test annotations
1 parent 60ceffe commit 64aaebc

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/history/RepositoryFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public static Repository getRepository(File file, CommandTimeoutType cmdType)
168168
* @param file File that might contain a repository
169169
* @param cmdType command timeout type
170170
* @param isNested a value indicating if a nestable {@link Repository} is required
171-
* @return Correct repository for the given file
171+
* @return Correct repository for the given file or {@code null}
172172
* @throws InstantiationException in case we cannot create the repository object
173173
* @throws IllegalAccessException in case no permissions to repository file
174174
* @throws NoSuchMethodException in case we cannot create the repository object

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

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,20 @@
2222
*/
2323
package org.opengrok.indexer.history;
2424

25+
import org.junit.jupiter.api.AfterAll;
26+
import org.junit.jupiter.api.BeforeAll;
2527
import org.junit.jupiter.api.Test;
2628
import org.opengrok.indexer.condition.EnabledForRepository;
29+
import org.opengrok.indexer.util.TestRepository;
2730

2831
import java.io.File;
2932
import java.io.IOException;
33+
import java.net.URISyntaxException;
3034
import java.nio.file.Files;
35+
import java.util.Set;
3136

3237
import static org.junit.jupiter.api.Assertions.assertEquals;
38+
import static org.junit.jupiter.api.Assertions.assertNotNull;
3339
import static org.junit.jupiter.api.Assertions.assertTrue;
3440
import static org.opengrok.indexer.condition.RepositoryInstalled.Type.SCCS;
3541

@@ -40,8 +46,24 @@
4046
@EnabledForRepository(SCCS)
4147
class SCCSRepositoryTest {
4248

49+
private static TestRepository repository;
50+
51+
@BeforeAll
52+
public static void setup() throws IOException, URISyntaxException {
53+
repository = new TestRepository();
54+
repository.create(SCCSRepositoryTest.class.getResource("/repositories"));
55+
}
56+
57+
@AfterAll
58+
public static void tearDown() {
59+
if (repository != null) {
60+
repository.destroy();
61+
repository = null;
62+
}
63+
}
64+
4365
/**
44-
* Test of isRepositoryFor method, of class SCCSRepository.
66+
* Test of {@link SCCSRepository#isRepositoryFor(File)}.
4567
*/
4668
private void testIsRepositoryFor(final String fileName, boolean shouldPass) throws IOException {
4769
File tdir = Files.createTempDirectory("SCCSrepotest" + fileName).toFile();
@@ -72,4 +94,21 @@ void testIsRepositoryForCodemgr3() throws IOException {
7294
void testIsRepositoryForCodemgrNot() throws IOException {
7395
testIsRepositoryFor("NOT", false);
7496
}
97+
98+
/**
99+
* Test of {@link SCCSRepository#annotate(File, String)}.
100+
*/
101+
@Test
102+
void testAnnotation() throws Exception {
103+
File repositoryRoot = new File(repository.getSourceRoot(), "teamware");
104+
assertTrue(repositoryRoot.isDirectory());
105+
SCCSRepository sccsRepository = (SCCSRepository) RepositoryFactory.getRepository(repositoryRoot);
106+
assertNotNull(sccsRepository);
107+
File file = new File(repositoryRoot, "main.c");
108+
assertTrue(file.isFile());
109+
Annotation annotation = sccsRepository.annotate(file, null);
110+
assertNotNull(annotation);
111+
Set<String> revSet = Set.of("1.2", "1.1");
112+
assertEquals(revSet, annotation.getRevisions());
113+
}
75114
}

0 commit comments

Comments
 (0)