Skip to content

Commit 3e68cc6

Browse files
committed
add negative test
also remove public modifier from pre-existing tests
1 parent e533564 commit 3e68cc6

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public History getHistoryUI(File file) throws HistoryException {
229229
return getHistory(file, true, true);
230230
}
231231

232-
private boolean isRepoHistoryEligible(Repository repo, File file, boolean ui) {
232+
boolean isRepoHistoryEligible(Repository repo, File file, boolean ui) {
233233
RemoteSCM rscm = env.getRemoteScmSupported();
234234
boolean doRemote = (ui && (rscm == RemoteSCM.UIONLY))
235235
|| (rscm == RemoteSCM.ON)
@@ -775,7 +775,7 @@ private List<Repository> getReposFromString(Collection<String> repositories) {
775775
return repos;
776776
}
777777

778-
private Repository getRepository(File file) {
778+
Repository getRepository(File file) {
779779
return repositoryLookup.getRepository(file.toPath(), repositoryRoots.keySet(), repositories,
780780
PathUtils::getRelativeToCanonical);
781781
}

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

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2008, 2021, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2008, 2022, Oracle and/or its affiliates. All rights reserved.
2222
* Portions Copyright (c) 2019, 2020, Chris Fraire <[email protected]>.
2323
*/
2424
package org.opengrok.indexer.history;
@@ -107,7 +107,7 @@ public void tearDown() {
107107
}
108108

109109
@Test
110-
public void testGetRevision() throws HistoryException, IOException {
110+
void testGetRevision() throws HistoryException, IOException {
111111
HistoryGuru instance = HistoryGuru.getInstance();
112112

113113
for (File f : FILES) {
@@ -127,7 +127,7 @@ public void testGetRevision() throws HistoryException, IOException {
127127

128128
@Test
129129
@EnabledForRepository(SUBVERSION)
130-
public void testBug16465() throws HistoryException, IOException {
130+
void testBug16465() throws HistoryException, IOException {
131131
HistoryGuru instance = HistoryGuru.getInstance();
132132
for (File f : FILES) {
133133
if (f.getName().equals("bugreport16465@")) {
@@ -138,7 +138,7 @@ public void testBug16465() throws HistoryException, IOException {
138138
}
139139

140140
@Test
141-
public void annotation() throws Exception {
141+
void annotation() throws Exception {
142142
HistoryGuru instance = HistoryGuru.getInstance();
143143
for (File f : FILES) {
144144
if (instance.hasAnnotation(f)) {
@@ -148,14 +148,14 @@ public void annotation() throws Exception {
148148
}
149149

150150
@Test
151-
public void getCacheInfo() throws HistoryException {
151+
void getCacheInfo() throws HistoryException {
152152
// FileHistoryCache is used by default
153153
assertEquals("FileHistoryCache",
154154
HistoryGuru.getInstance().getCacheInfo());
155155
}
156156

157157
@Test
158-
public void testAddRemoveRepositories() {
158+
void testAddRemoveRepositories() {
159159
HistoryGuru instance = HistoryGuru.getInstance();
160160
final int numReposOrig = instance.getRepositories().size();
161161

@@ -180,7 +180,7 @@ public void testAddRemoveRepositories() {
180180

181181
@Test
182182
@EnabledForRepository(CVS)
183-
public void testAddSubRepositoryNotNestable() {
183+
void testAddSubRepositoryNotNestable() {
184184
HistoryGuru instance = HistoryGuru.getInstance();
185185

186186
// Check out CVS underneath a Git repository.
@@ -201,7 +201,7 @@ public void testAddSubRepositoryNotNestable() {
201201

202202
@Test
203203
@EnabledForRepository(MERCURIAL)
204-
public void testAddSubRepository() {
204+
void testAddSubRepository() {
205205
HistoryGuru instance = HistoryGuru.getInstance();
206206

207207
// Clone a Mercurial repository underneath a Mercurial repository.
@@ -218,7 +218,7 @@ public void testAddSubRepository() {
218218
}
219219

220220
@Test
221-
public void testNestingMaximum() throws IOException {
221+
void testNestingMaximum() throws IOException {
222222
// Just fake a nesting of Repo -> Git -> Git.
223223
File repoRoot = new File(repository.getSourceRoot(), "repoRoot");
224224
certainlyMkdirs(repoRoot);
@@ -253,7 +253,7 @@ private static void certainlyMkdirs(File file) throws IOException {
253253
}
254254

255255
@Test
256-
public void testScanningDepth() throws IOException {
256+
void testScanningDepth() throws IOException {
257257
String topLevelDirName = "scanDepthTest";
258258
File repoRoot = new File(repository.getSourceRoot(), topLevelDirName);
259259
certainlyMkdirs(repoRoot);
@@ -293,7 +293,7 @@ void testGetLastHistoryEntryNonexistent() throws HistoryException {
293293

294294
@ParameterizedTest
295295
@ValueSource(booleans = {true, false})
296-
void testGetLastHistoryEntry(boolean isIndexerParam) throws HistoryException {
296+
void testGetLastHistoryEntryVsIndexer(boolean isIndexerParam) throws HistoryException {
297297
boolean isIndexer = env.isIndexer();
298298
env.setIndexer(isIndexerParam);
299299
boolean isTagsEnabled = env.isTagsEnabled();
@@ -309,4 +309,16 @@ void testGetLastHistoryEntry(boolean isIndexerParam) throws HistoryException {
309309
env.setIndexer(isIndexer);
310310
env.setTagsEnabled(isTagsEnabled);
311311
}
312+
313+
@Test
314+
void testGetLastHistoryEntryRepoHistoryDisabled() throws HistoryException {
315+
File file = new File(repository.getSourceRoot(), "git");
316+
assertTrue(file.exists());
317+
HistoryGuru instance = HistoryGuru.getInstance();
318+
Repository repository = instance.getRepository(file);
319+
assertNotNull(repository);
320+
repository.setHistoryEnabled(false);
321+
assertNull(instance.getLastHistoryEntry(file, false));
322+
repository.setHistoryEnabled(true);
323+
}
312324
}

0 commit comments

Comments
 (0)