thecoop commented on code in PR #14518:
URL: https://github.com/apache/lucene/pull/14518#discussion_r2055485408


##########
lucene/core/src/test/org/apache/lucene/document/TestDocument.java:
##########
@@ -312,21 +324,21 @@ public void testFieldSetValue() throws Exception {
 
     // ensure that queries return expected results without DateFilter first
     ScoreDoc[] hits = searcher.search(query, 1000).scoreDocs;
-    assertEquals(3, hits.length);
-    int result = 0;
+    assertThat(hits, arrayWithSize(3));
+    Set<String> seen = new HashSet<>();
     StoredFields storedFields = searcher.storedFields();
     for (int i = 0; i < 3; i++) {
       Document doc2 = storedFields.document(hits[i].doc);
       Field f = (Field) doc2.getField("id");
-      if (f.stringValue().equals("id1")) result |= 1;
-      else if (f.stringValue().equals("id2")) result |= 2;
-      else if (f.stringValue().equals("id3")) result |= 4;
-      else fail("unexpected id field");
+      switch (f.stringValue()) {
+        case "id1", "id2", "id3" -> seen.add(f.stringValue());
+        default -> fail("unexpected id field");
+      }
     }
     writer.close();
     reader.close();
     dir.close();
-    assertEquals("did not see all IDs", 7, result);
+    assertThat("did not see all IDs", seen, containsInAnyOrder("id1", "id2", 
"id3"));

Review Comment:
   `containsInAnyOrder` fails if there are any extra items in the collection.
   
   More generally, `assertEquals(..., Set.of())` checks if the value is a 
`Set`, which is not actually important here. The collection could be a `List` 
and the test would still work. So checking for `Set` isn't required here for 
the test to pass, whereas `containsInAnyOrder` doesn't care about the type of 
collection used.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to