-
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from jamesmudd/coverage-improvements
Coverage improvements
- Loading branch information
Showing
8 changed files
with
121 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* This file is part of jHDF. A pure Java library for accessing HDF5 files. | ||
* | ||
* http://jhdf.io | ||
* | ||
* Copyright (c) 2020 James Mudd | ||
* | ||
* MIT License see 'LICENSE' file | ||
*/ | ||
package io.jhdf; | ||
|
||
import io.jhdf.dataset.CompoundDatasetReader; | ||
import io.jhdf.dataset.DatasetLoader; | ||
import io.jhdf.dataset.DatasetReader; | ||
import io.jhdf.dataset.EnumDatasetReader; | ||
import io.jhdf.dataset.VariableLengthDatasetReader; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.powermock.reflect.Whitebox.invokeConstructor; | ||
|
||
class NoInstancesTest { | ||
|
||
static Stream<Arguments> noInstances() { | ||
return Stream.of( | ||
Arguments.of(DatasetLoader.class), | ||
Arguments.of(DatasetReader.class), | ||
Arguments.of(CompoundDatasetReader.class), | ||
Arguments.of(EnumDatasetReader.class), | ||
Arguments.of(VariableLengthDatasetReader.class), | ||
Arguments.of(Constants.class), | ||
Arguments.of(Utils.class) | ||
); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource | ||
void noInstances(Class<?> clazz) { | ||
assertThrows(AssertionError.class, () -> invokeConstructor(clazz)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* This file is part of jHDF. A pure Java library for accessing HDF5 files. | ||
* | ||
* http://jhdf.io | ||
* | ||
* Copyright (c) 2020 James Mudd | ||
* | ||
* MIT License see 'LICENSE' file | ||
*/ | ||
package io.jhdf.dataset; | ||
|
||
import io.jhdf.HdfFileChannel; | ||
import io.jhdf.ObjectHeader; | ||
import io.jhdf.api.Group; | ||
import io.jhdf.exceptions.HdfException; | ||
import io.jhdf.object.message.DataLayout; | ||
import io.jhdf.object.message.DataLayoutMessage; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.util.BitSet; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
import static org.powermock.reflect.Whitebox.invokeConstructor; | ||
|
||
class DatasetLoaderTest { | ||
|
||
@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)); | ||
} | ||
|
||
private static class UnknownDataLayoutMessage extends DataLayoutMessage { | ||
|
||
public UnknownDataLayoutMessage(BitSet flags) { | ||
super(flags); | ||
} | ||
|
||
@Override | ||
public DataLayout getDataLayout() { | ||
return null; | ||
} | ||
} | ||
} |