Skip to content

Commit 7b87377

Browse files
author
Vladimir Kotal
committed
test non-working repository code path in RepositoryFactory.getRepository()
1 parent 7dc359f commit 7b87377

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
/*
21+
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
22+
*/
23+
package org.opensolaris.opengrok.history;
24+
25+
import java.io.File;
26+
import java.lang.reflect.InvocationTargetException;
27+
import org.junit.AfterClass;
28+
import static org.junit.Assert.assertFalse;
29+
import org.junit.BeforeClass;
30+
import org.junit.Test;
31+
import org.opensolaris.opengrok.util.TestRepository;
32+
33+
/**
34+
* Test RepositoryFactory
35+
*
36+
* @author Vladimir Kotal
37+
*/
38+
public class RepositoryFactoryTest {
39+
private static TestRepository repository;
40+
41+
@BeforeClass
42+
public static void setUpClass() throws Exception {
43+
repository = new TestRepository();
44+
repository.create(RepositoryFactory.class.getResourceAsStream("repositories.zip"));
45+
}
46+
47+
@AfterClass
48+
public static void tearDown() {
49+
if (repository != null) {
50+
repository.destroy();
51+
repository = null;
52+
}
53+
}
54+
55+
/*
56+
* There is no conditonal run based on whether Mercurial is installed because
57+
* this test is not supposed to have working Mercurial anyway.
58+
*/
59+
@Test
60+
public void testNotWorkingRepository() throws InstantiationException, IllegalAccessException,
61+
NoSuchMethodException, InvocationTargetException {
62+
63+
String propName = MercurialRepository.CMD_PROPERTY_KEY;
64+
System.setProperty(propName, "/foo/bar/nonexistent");
65+
File root = new File(repository.getSourceRoot(), "mercurial");
66+
Repository repo = RepositoryFactory.getRepository(root);
67+
assertFalse(repo.isWorking());
68+
}
69+
}

0 commit comments

Comments
 (0)