Skip to content

Commit 40f2f01

Browse files
committed
tests
1 parent 87a535f commit 40f2f01

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/org/opensolaris/opengrok/web/PageConfig.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,15 +1193,15 @@ public File findDataFile() {
11931193
path, env.isCompressXref());
11941194
}
11951195

1196-
private String getLatestRevision() {
1197-
if (!env.isHistoryEnabled()) {
1196+
protected String getLatestRevision() {
1197+
if (!getEnv().isHistoryEnabled()) {
11981198
return null;
11991199
}
12001200

12011201
History hist;
12021202
try {
12031203
hist = HistoryGuru.getInstance().
1204-
getHistory(new File(env.getSourceRootFile(), path));
1204+
getHistory(new File(getEnv().getSourceRootFile(), getPath()));
12051205
} catch (HistoryException ex) {
12061206
return null;
12071207
}

test/org/opensolaris/opengrok/web/PageConfigTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,36 @@ public String getParameter(String name) {
241241
}
242242
}
243243

244+
@Test
245+
public void testGetLatestRevisionValid() {
246+
DummyHttpServletRequest req1 = new DummyHttpServletRequest() {
247+
@Override
248+
public String getPathInfo() {
249+
return "/git/main.c";
250+
}
251+
};
252+
253+
PageConfig cfg = PageConfig.get(req1);
254+
String rev = cfg.getLatestRevision();
255+
256+
assertEquals("aa35c258", rev);
257+
}
258+
259+
@Test
260+
public void testGetLatestRevisionNotValid() {
261+
DummyHttpServletRequest req2 = new DummyHttpServletRequest() {
262+
@Override
263+
public String getPathInfo() {
264+
return "/git/nonexistent_file";
265+
}
266+
};
267+
268+
PageConfig cfg = PageConfig.get(req2);
269+
String rev = cfg.getLatestRevision();
270+
271+
assertNull(rev);
272+
}
273+
244274
@Test
245275
public void testGetRequestedRevision() {
246276
final String[] params = {"r", "h", "r", "r", "r"};

0 commit comments

Comments
 (0)