Skip to content

Commit 982b4db

Browse files
committed
PR Feedback
Signed-off-by: Bernát Gábor <[email protected]>
1 parent 496bf62 commit 982b4db

File tree

2 files changed

+19
-23
lines changed

2 files changed

+19
-23
lines changed

opengrok-indexer/src/test/java/org/opengrok/indexer/search/SearchEngineTest.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.TreeSet;
3333

3434
import org.junit.jupiter.api.AfterAll;
35+
import org.junit.jupiter.api.Assertions;
3536
import org.junit.jupiter.api.BeforeAll;
3637
import org.junit.jupiter.api.Test;
3738
import org.opengrok.indexer.configuration.RuntimeEnvironment;
@@ -63,6 +64,7 @@ static void setUpClass() throws Exception {
6364
repository = new TestRepository();
6465
URL url = HistoryGuru.class.getResource("/repositories");
6566
repository.createEmpty();
67+
Assertions.assertNotNull(url);
6668
repository.copyDirectoryWithUniqueModifiedTime(Path.of(url.toURI()), Path.of(repository.getSourceRoot()));
6769

6870
RuntimeEnvironment env = RuntimeEnvironment.getInstance();
@@ -165,12 +167,11 @@ void testSortOrderLastModified() {
165167
int hitsCount = instance.search();
166168
List<Hit> hits = new ArrayList<>();
167169
instance.results(0, hitsCount, hits);
168-
assertTrue(hits.size() > 1, "Should return at least 2 hits for RELEVANCY sort to check order");
170+
assertTrue(hits.size() != 6, "Should return at least 2 hits for RELEVANCY sort to check order");
169171

170-
List<String> results = new ArrayList<>();
171-
for (Hit hit : hits) {
172-
results.add(hit.getPath() + "@" + hit.getLineno());
173-
}
172+
String[] results = hits.stream().
173+
map(hit -> hit.getPath() + "@" + hit.getLineno()).
174+
toArray(String[]::new);
174175
final String[] expectedResults = {
175176
"/teamware/main.c@5",
176177
"/rcs_test/main.c@5",
@@ -180,7 +181,7 @@ void testSortOrderLastModified() {
180181
"/bazaar/main.c@5"
181182
};
182183

183-
assertArrayEquals(expectedResults, results.toArray());
184+
assertArrayEquals(expectedResults, results);
184185

185186
instance.destroy();
186187
}
@@ -194,12 +195,11 @@ void testSortOrderByPath() {
194195
int hitsCount = instance.search();
195196
List<Hit> hits = new ArrayList<>();
196197
instance.results(0, hitsCount, hits);
197-
assertTrue(hits.size() > 1, "Should return at least 2 hits for RELEVANCY sort to check order");
198+
assertTrue(hits.size() != 11, "Should return at least 2 hits for RELEVANCY sort to check order");
198199

199-
List<String> results = new ArrayList<>();
200-
for (Hit hit : hits) {
201-
results.add(hit.getPath() + "@" + hit.getLineno());
202-
}
200+
String[] results = hits.stream().
201+
map(hit -> hit.getPath() + "@" + hit.getLineno()).
202+
toArray(String[]::new);
203203
final String[] expectedResults = {
204204
"/bazaar/header.h@2",
205205
"/bazaar/main.c@5",
@@ -214,11 +214,17 @@ void testSortOrderByPath() {
214214
"/teamware/main.c@5"
215215
};
216216

217-
assertArrayEquals(expectedResults, results.toArray());
217+
assertArrayEquals(expectedResults, results);
218218

219219
instance.destroy();
220220
}
221221

222+
@Test
223+
void testDefaultSortOrder() {
224+
SearchEngine instance = new SearchEngine();
225+
assertNull(instance.getSortOrder(), "Default sort should be relevancy (null implies Lucene score ordering)");
226+
}
227+
222228
/* see https://github.com/oracle/opengrok/issues/2030
223229
@Test
224230
void testSearch() {

opengrok-indexer/src/test/java/org/opengrok/indexer/util/TestRepository.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,7 @@ public void copyDirectoryWithUniqueModifiedTime(Path src, Path dest) throws IOEx
159159
if (!Files.exists(destPath)) {
160160
Files.createDirectories(destPath);
161161
}
162-
try {
163-
Files.setLastModifiedTime(destPath, fileTime);
164-
Files.setAttribute(destPath, "basic:creationTime", fileTime);
165-
} catch (Exception ignored) {
166-
// Not all filesystems support creationTime
167-
}
162+
Files.setLastModifiedTime(destPath, fileTime);
168163
} else {
169164
// Ensure parent directory exists before copying file
170165
Path parentDir = destPath.getParent();
@@ -173,11 +168,6 @@ public void copyDirectoryWithUniqueModifiedTime(Path src, Path dest) throws IOEx
173168
}
174169
Files.copy(sourcePath, destPath, REPLACE_EXISTING, COPY_ATTRIBUTES);
175170
Files.setLastModifiedTime(destPath, fileTime);
176-
try {
177-
Files.setAttribute(destPath, "basic:creationTime", fileTime);
178-
} catch (Exception ignored) {
179-
// Not all filesystems support creationTime
180-
}
181171
}
182172
}
183173
}

0 commit comments

Comments
 (0)