diff --git a/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java b/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java
index e61224cf717..857e2dc954e 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/search/AssertingWeight.java
@@ -33,6 +33,15 @@ class AssertingWeight extends FilterWeight {
     this.scoreMode = scoreMode;
   }
 
+  @Override
+  public int count(LeafReaderContext context) throws IOException {
+    final int count = in.count(context);
+    if (count < -1 || count > context.reader().numDocs()) {
+      throw new AssertionError("count=" + count + ", numDocs=" + context.reader().numDocs());
+    }
+    return count;
+  }
+
   @Override
   public Matches matches(LeafReaderContext context, int doc) throws IOException {
     Matches matches = in.matches(context, doc);