Skip to content

Commit 24a3d81

Browse files
committed
address review comments
1 parent cf0c35f commit 24a3d81

File tree

3 files changed

+37
-44
lines changed

3 files changed

+37
-44
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.logging.Level;
3737
import java.util.logging.Logger;
3838

39+
import org.jetbrains.annotations.VisibleForTesting;
3940
import org.opengrok.indexer.configuration.CommandTimeoutType;
4041
import org.opengrok.indexer.configuration.RuntimeEnvironment;
4142
import org.opengrok.indexer.logger.LoggerFactory;
@@ -58,6 +59,7 @@ public class SCCSRepository extends Repository {
5859
*/
5960
public static final String CMD_FALLBACK = "sccs";
6061

62+
@VisibleForTesting
6163
static final String CODEMGR_WSDATA = "Codemgr_wsdata";
6264

6365
public SCCSRepository() {

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
*/
2323
package org.opengrok.indexer.history;
2424

25-
import org.apache.commons.compress.utils.IOUtils;
2625
import org.junit.jupiter.api.AfterAll;
2726
import org.junit.jupiter.api.BeforeAll;
2827
import org.junit.jupiter.api.Test;
@@ -99,7 +98,7 @@ private void testIsRepositoryFor(final String fileName, boolean shouldPass) thro
9998

10099
@Test
101100
void testIsRepositoryForCodemgr1() throws IOException {
102-
testIsRepositoryFor("Codemgr_wsdata", true);
101+
testIsRepositoryFor(SCCSRepository.CODEMGR_WSDATA, true);
103102
}
104103

105104
@Test
@@ -222,8 +221,7 @@ void testGetHistoryGet(final GetHistoryTestParams testParams) throws Exception {
222221
try (InputStream inputStream = sccsRepository.getHistoryGet(repositoryRoot.toString(),
223222
"main.c", testParams.revision)) {
224223
assertNotNull(inputStream);
225-
byte[] buffer = new byte[1024];
226-
IOUtils.readFully(inputStream, buffer);
224+
byte[] buffer = inputStream.readAllBytes();
227225
String fileContents = new String(buffer);
228226
final String castedPrintf = "(void)printf";
229227
if (testParams.shouldContain) {

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

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -47,44 +47,36 @@
4747
@EnabledForRepository(SCCS)
4848
class SCCSgetTest {
4949

50-
private File sccs_file;
51-
private File sccs_dir;
50+
private File sccsFile;
51+
private File sccsDir;
5252

5353
@BeforeEach
5454
public void setUp() throws IOException {
55-
try {
56-
sccs_dir = File.createTempFile("s.test", "sccs");
57-
assertTrue(sccs_dir.delete());
58-
assertTrue(sccs_dir.mkdirs(), "Failed to set up the test-directory");
59-
sccs_file = new File(sccs_dir, "s.note.txt");
60-
try (InputStream in = getClass().getResourceAsStream("/history/s.note.txt");
61-
FileOutputStream out = new FileOutputStream(sccs_file)) {
62-
63-
byte[] buffer = new byte[8192];
64-
int nr;
65-
66-
while ((nr = in.read(buffer, 0, buffer.length)) != -1) {
67-
out.write(buffer, 0, nr);
68-
}
69-
out.flush();
55+
sccsDir = File.createTempFile("s.test", "sccs");
56+
assertTrue(sccsDir.delete());
57+
assertTrue(sccsDir.mkdirs(), "Failed to set up the test-directory");
58+
sccsFile = new File(sccsDir, "s.note.txt");
59+
try (InputStream in = getClass().getResourceAsStream("/history/s.note.txt");
60+
FileOutputStream out = new FileOutputStream(sccsFile)) {
61+
62+
byte[] buffer = new byte[8192];
63+
int nr;
64+
65+
while ((nr = in.read(buffer, 0, buffer.length)) != -1) {
66+
out.write(buffer, 0, nr);
7067
}
71-
} catch (IOException ex) {
72-
if (sccs_file != null) {
73-
sccs_file.delete();
74-
sccs_dir.delete();
75-
}
76-
throw ex;
68+
out.flush();
7769
}
7870
}
7971

8072
@AfterEach
8173
public void tearDown() {
82-
if (sccs_file != null) {
83-
sccs_file.delete();
74+
if (sccsFile != null) {
75+
sccsFile.delete();
8476
}
8577

86-
if (sccs_dir != null) {
87-
sccs_dir.delete();
78+
if (sccsDir != null) {
79+
sccsDir.delete();
8880
}
8981
}
9082

@@ -107,19 +99,20 @@ private String readInput(InputStream in) throws IOException {
10799
*/
108100
@Test
109101
void getRevision() throws Exception {
110-
InputStream inputStream = getClass().getResourceAsStream("/history/sccs-revisions.zip");
111-
assertNotNull(inputStream);
112-
ZipInputStream zstream = new ZipInputStream(inputStream);
113-
ZipEntry entry;
114-
115-
while ((entry = zstream.getNextEntry()) != null) {
116-
String expected = readInput(zstream);
117-
InputStream sccs = SCCSget.getRevision("sccs", sccs_file, entry.getName());
118-
String got = readInput(sccs);
119-
sccs.close();
120-
zstream.closeEntry();
121-
assertEquals(expected, got);
102+
try (InputStream inputStream = getClass().getResourceAsStream("/history/sccs-revisions.zip")) {
103+
assertNotNull(inputStream);
104+
ZipInputStream zstream = new ZipInputStream(inputStream);
105+
ZipEntry entry;
106+
107+
while ((entry = zstream.getNextEntry()) != null) {
108+
String expected = readInput(zstream);
109+
InputStream sccs = SCCSget.getRevision("sccs", sccsFile, entry.getName());
110+
String got = readInput(sccs);
111+
sccs.close();
112+
zstream.closeEntry();
113+
assertEquals(expected, got);
114+
}
115+
zstream.close();
122116
}
123-
zstream.close();
124117
}
125118
}

0 commit comments

Comments
 (0)