### Question:
EventSerializer { private static boolean isEvent(ByteBuffer buffer, Class<?> eventClass) throws IOException { if (buffer.remaining() < 4) { throw new IOException("Incomplete event"); } final int bufferPos = buffer.position(); final ByteOrder bufferOrder = buffer.order(); buffer.order(ByteOrder.BIG_ENDIAN); try { int type = buffer.getInt(); if (eventClass.equals(EndOfPartitionEvent.class)) { return type == END_OF_PARTITION_EVENT; } else if (eventClass.equals(CheckpointBarrier.class)) { return type == CHECKPOINT_BARRIER_EVENT; } else if (eventClass.equals(EndOfSuperstepEvent.class)) { return type == END_OF_SUPERSTEP_EVENT; } else if (eventClass.equals(CancelCheckpointMarker.class)) { return type == CANCEL_CHECKPOINT_MARKER_EVENT; } else { throw new UnsupportedOperationException("Unsupported eventClass = " + eventClass); } } finally { buffer.order(bufferOrder); buffer.position(bufferPos); } }  static ByteBuffer toSerializedEvent(AbstractEvent event); static AbstractEvent fromSerializedEvent(ByteBuffer buffer, ClassLoader classLoader); static Buffer toBuffer(AbstractEvent event); static BufferConsumer toBufferConsumer(AbstractEvent event); static AbstractEvent fromBuffer(Buffer buffer, ClassLoader classLoader); static boolean isEvent(Buffer buffer, Class<?> eventClass);  }### Answer:
@Test public void testIsEvent() throws Exception { AbstractEvent[] events = { EndOfPartitionEvent.INSTANCE, EndOfSuperstepEvent.INSTANCE, new CheckpointBarrier(1678L, 4623784L, CheckpointOptions.forCheckpointWithDefaultLocation()), new TestTaskEvent(Math.random(), 12361231273L), new CancelCheckpointMarker(287087987329842L) }; Class[] expectedClasses = Arrays.stream(events) .map(AbstractEvent::getClass) .toArray(Class[]::new); for (AbstractEvent evt : events) { for (Class<?> expectedClass: expectedClasses) { if (expectedClass.equals(TestTaskEvent.class)) { try { checkIsEvent(evt, expectedClass); fail("This should fail"); } catch (UnsupportedOperationException ex) { } } else if (evt.getClass().equals(expectedClass)) { assertTrue(checkIsEvent(evt, expectedClass)); } else { assertFalse(checkIsEvent(evt, expectedClass)); } } } }