3232import java .util .TreeSet ;
3333
3434import org .junit .jupiter .api .AfterAll ;
35+ import org .junit .jupiter .api .Assertions ;
3536import org .junit .jupiter .api .BeforeAll ;
3637import org .junit .jupiter .api .Test ;
3738import 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() {
0 commit comments