DatasetLoader { public static Dataset createDataset(HdfFileChannel hdfFc, ObjectHeader oh, String name, Group parent) { final long address = oh.getAddress(); try { final DataLayoutMessage dlm = oh.getMessageOfType(DataLayoutMessage.class); if (dlm instanceof CompactDataLayoutMessage) { return new CompactDataset(hdfFc, address, name, parent, oh); } else if (dlm instanceof ContiguousDataLayoutMessage) { return new ContiguousDatasetImpl(hdfFc, address, name, parent, oh); } else if (dlm instanceof ChunkedDataLayoutMessage) { return new ChunkedDatasetV3(hdfFc, address, name, parent, oh); } else if (dlm instanceof ChunkedDataLayoutMessageV4) { return new ChunkedDatasetV4(hdfFc, address, name, parent, oh); } else { throw new HdfException("Unrecognized Dataset layout type: " + dlm.getClass().getCanonicalName()); } } catch (Exception e) { throw new HdfException("Failed to read dataset '" + name + "' at address '" + address + "'", e); } } private  DatasetLoader(); static Dataset createDataset(HdfFileChannel hdfFc, ObjectHeader oh, String name,
			Group parent);  }
@Test void testUnrecognisedDataLayoutMessage() { HdfFileChannel hdfFileChannel = mock(HdfFileChannel.class); ObjectHeader objectHeader = mock(ObjectHeader.class); String name = "test"; Group group = mock(Group.class); when(objectHeader.getMessageOfType(DataLayoutMessage.class)) .thenReturn(new UnknownDataLayoutMessage(new BitSet())); assertThrows(HdfException.class, () -> DatasetLoader.createDataset(hdfFileChannel, objectHeader, name, group)); }
@Test void testFailureToReadDataset() { HdfFileChannel hdfFileChannel = mock(HdfFileChannel.class); ObjectHeader objectHeader = mock(ObjectHeader.class); String name = "test"; Group group = mock(Group.class); when(objectHeader.getMessageOfType(DataLayoutMessage.class)) .thenThrow(RuntimeException.class); assertThrows(HdfException.class, () -> DatasetLoader.createDataset(hdfFileChannel, objectHeader, name, group)); }