### Question:
GenerationSafePointer { static void write( PageCursor cursor, long generation, long pointer ) { assertGenerationOnWrite( generation ); assertPointerOnWrite( pointer ); writeGSP( cursor, generation, pointer ); } private  GenerationSafePointer(); static boolean isEmpty( long generation, long pointer );  }### Answer:
@Test void shouldWriteAndReadGsp() { int offset = 3; GSP expected = gsp( 10, 110 ); write( cursor, offset, expected ); boolean matches = read( cursor, offset, read ); assertTrue( matches ); assertEquals( expected, read ); }
@Test void shouldDetectInvalidChecksumOnReadDueToChangedGeneration() { int offset = 0; GSP initial = gsp( 123, 456 ); write( cursor, offset, initial ); cursor.putInt( offset, (int) (initial.generation + 5) ); boolean matches = read( cursor, offset, read ); assertFalse( matches ); }
@Test void shouldWriteAndReadGspCloseToGenerationMax() { long generation = GenerationSafePointer.MAX_GENERATION; GSP expected = gsp( generation, 12345 ); write( cursor, 0, expected ); GSP read = new GSP(); boolean matches = read( cursor, 0, read ); assertTrue( matches ); assertEquals( expected, read ); assertEquals( generation, read.generation ); }
@Test void shouldWriteAndReadGspCloseToPointerMax() { long pointer = GenerationSafePointer.MAX_POINTER; GSP expected = gsp( 12345, pointer ); write( cursor, 0, expected ); GSP read = new GSP(); boolean matches = read( cursor, 0, read ); assertTrue( matches ); assertEquals( expected, read ); assertEquals( pointer, read.pointer ); }
@Test void shouldWriteAndReadGspCloseToGenerationAndPointerMax() { long generation = GenerationSafePointer.MAX_GENERATION; long pointer = GenerationSafePointer.MAX_POINTER; GSP expected = gsp( generation, pointer ); write( cursor, 0, expected ); GSP read = new GSP(); boolean matches = read( cursor, 0, read ); assertTrue( matches ); assertEquals( expected, read ); assertEquals( generation, read.generation ); assertEquals( pointer, read.pointer ); }
@Test void shouldThrowIfPointerToLarge() { long generation = GenerationSafePointer.MIN_GENERATION; long pointer = GenerationSafePointer.MAX_POINTER + 1; GSP broken = gsp( generation, pointer ); assertThrows( IllegalArgumentException.class, () -> write( cursor, 0, broken ) ); }
@Test void shouldThrowIfPointerToSmall() { long generation = GenerationSafePointer.MIN_GENERATION; long pointer = GenerationSafePointer.MIN_POINTER - 1; GSP broken = gsp( generation, pointer ); assertThrows( IllegalArgumentException.class, () -> write( cursor, 0, broken ) ); }
@Test void shouldThrowIfGenerationToLarge() { long generation = GenerationSafePointer.MAX_GENERATION + 1; long pointer = GenerationSafePointer.MIN_POINTER; GSP broken = gsp( generation, pointer ); assertThrows( IllegalArgumentException.class, () -> write( cursor, 0, broken ) ); }
@Test void shouldThrowIfGenerationToSmall() { long generation = GenerationSafePointer.MIN_GENERATION - 1; long pointer = GenerationSafePointer.MIN_POINTER; GSP broken = gsp( generation, pointer ); assertThrows( IllegalArgumentException.class, () -> write( cursor, 0, broken ) ); }