@@ -141,17 +141,31 @@ public void testEqualityAndHashCode() throws IOException {
141141 };
142142
143143 final EqualsHashCodeTestUtils .MutateFunction <Page > mutatePageFunction = page -> {
144- assert page .getPositionCount () > 0 ;
145- Block [] blocks = new Block [page .getBlockCount ()];
146- int positions = randomInt (page .getPositionCount () - 1 );
147- for (int blockIndex = 0 ; blockIndex < blocks .length ; blockIndex ++) {
148- Block block = page .getBlock (blockIndex );
149- blocks [blockIndex ] = block .elementType ()
150- .newBlockBuilder (positions , TestBlockFactory .getNonBreakingInstance ())
151- .copyFrom (block , 0 , positions )
152- .build ();
144+ if (page .getPositionCount () > 0 ) {
145+ Block [] blocks = new Block [page .getBlockCount ()];
146+ int positions = randomInt (page .getPositionCount () - 1 );
147+ for (int blockIndex = 0 ; blockIndex < blocks .length ; blockIndex ++) {
148+ Block block = page .getBlock (blockIndex );
149+ blocks [blockIndex ] = block .elementType ()
150+ .newBlockBuilder (positions , TestBlockFactory .getNonBreakingInstance ())
151+ .copyFrom (block , 0 , positions )
152+ .build ();
153+ }
154+ return new Page (positions , blocks );
155+ } else {
156+ Block [] blocks = new Block [page .getBlockCount () + 1 ];
157+ for (int blockIndex = 0 ; blockIndex < page .getBlockCount (); blockIndex ++) {
158+ blocks [blockIndex ] = page .getBlock (blockIndex );
159+ }
160+
161+ ElementType newBlockType = randomValueOtherThanMany (
162+ x -> x == ElementType .DOC || x == ElementType .COMPOSITE || x == ElementType .UNKNOWN ,
163+ () -> randomFrom (ElementType .values ())
164+ );
165+
166+ blocks [blocks .length - 1 ] = newBlockType .newBlockBuilder (0 , TestBlockFactory .getNonBreakingInstance ()).build ();
167+ return new Page (0 , blocks );
153168 }
154- return new Page (positions , blocks );
155169 };
156170
157171 int positions = randomIntBetween (0 , 512 );
0 commit comments