### Question:
PointerChecking { static void checkPointer( long result, boolean allowNoNode ) { GenerationSafePointerPair.assertSuccess( result ); if ( allowNoNode && !TreeNode.isNode( result ) ) { return; } if ( result < IdSpace.MIN_TREE_NODE_ID ) { throw new TreeInconsistencyException( "Pointer to id " + result + " not allowed. Minimum node id allowed is " + IdSpace.MIN_TREE_NODE_ID ); } } private  PointerChecking();   }### Answer:
@Test void checkChildShouldThrowOnNoNode() { assertThrows(TreeInconsistencyException.class, () -> PointerChecking.checkPointer( TreeNode.NO_NODE_FLAG, false ) ); }
@Test void checkChildShouldThrowOnReadFailure() { long result = GenerationSafePointerPair.read( cursor, 0, 1, NO_GENERATION_TARGET ); assertThrows( TreeInconsistencyException.class, () -> PointerChecking.checkPointer( result, false ) ); }
@Test void checkChildShouldThrowOnWriteFailure() { write( cursor, 123, 0, firstGeneration ); cursor.rewind(); write( cursor, 456, firstGeneration, secondGeneration ); cursor.rewind(); long result = write( cursor, 789, 0, thirdGeneration ); assertThrows( TreeInconsistencyException.class, () -> PointerChecking.checkPointer( result, false ) ); }
@Test void checkChildShouldPassOnReadSuccess() { PointerChecking.checkPointer( write( cursor, 123, 0, firstGeneration ), false ); cursor.rewind(); long result = read( cursor, 0, firstGeneration, NO_GENERATION_TARGET ); PointerChecking.checkPointer( result, false ); }
@Test void checkChildShouldPassOnWriteSuccess() { long result = write( cursor, 123, 0, firstGeneration ); PointerChecking.checkPointer( result, false ); }
@Test void checkSiblingShouldPassOnReadSuccessForNoNodePointer() { write( cursor, TreeNode.NO_NODE_FLAG, firstGeneration, secondGeneration ); cursor.rewind(); long result = read( cursor, firstGeneration, secondGeneration, NO_GENERATION_TARGET ); PointerChecking.checkPointer( result, true ); }
@Test void checkSiblingShouldPassOnReadSuccessForNodePointer() { long pointer = 101; write( cursor, pointer, firstGeneration, secondGeneration ); cursor.rewind(); long result = read( cursor, firstGeneration, secondGeneration, NO_GENERATION_TARGET ); PointerChecking.checkPointer( result, true ); }
@Test void checkSiblingShouldThrowOnReadFailure() { long result = read( cursor, firstGeneration, secondGeneration, NO_GENERATION_TARGET ); assertThrows( TreeInconsistencyException.class, () -> PointerChecking.checkPointer( result, true ) ); }
@Test void checkSiblingShouldThrowOnReadIllegalPointer() { long generation = IdSpace.STATE_PAGE_A; long pointer = this.secondGeneration; cursor.putInt( (int) pointer ); put6BLong( cursor, generation ); cursor.putShort( GenerationSafePointer.checksumOf( generation, pointer ) ); cursor.rewind(); long result = read( cursor, firstGeneration, pointer, NO_GENERATION_TARGET ); assertThrows(TreeInconsistencyException.class, () -> PointerChecking.checkPointer( result, true ) ); }