Skip to content

Commit

Permalink
Fix "Found incompatible ImageJ class" exception
Browse files Browse the repository at this point in the history
Closes #1139.
  • Loading branch information
ctrueden committed May 17, 2024
1 parent 2413fba commit 1906113
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/test/java/org/embl/mobie/lib/create/ImagesCreatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,11 @@ void assertionsForDataset(File imageLocation) throws IOException {
assertTrue( validate( datasetJsonPath, JSONValidator.datasetSchemaURL ) );
}

void assertionsForImage(File imageLocation, ImagePlus image)
void assertionsForImage(File imageLocation, Object imageObject)
{
// NB: Avoid recursive class loading of ij.* classes.
ImagePlus image = (ImagePlus) imageObject;

// File exists
assertTrue( imageLocation.exists() );

Expand All @@ -136,7 +139,10 @@ void assertionsForImage(File imageLocation, ImagePlus image)
});
}

void assertionsForImageAdded(ImagePlus image) throws IOException {
void assertionsForImageAdded(Object imageObject) throws IOException {
// NB: Avoid recursive class loading of ij.* classes.
ImagePlus image = (ImagePlus) imageObject;

File imageLocation = new File(
IOHelper.combinePath(
projectCreator.getProjectLocation().getAbsolutePath(),
Expand All @@ -148,9 +154,9 @@ void assertionsForImageAdded(ImagePlus image) throws IOException {
assertionsForImageAdded(imageLocation, image);
}

void assertionsForImageAdded(File imageLocation, ImagePlus image) throws IOException {
void assertionsForImageAdded(File imageLocation, Object imageObject) throws IOException {
assertionsForDataset(imageLocation);
assertionsForImage(imageLocation, image);
assertionsForImage(imageLocation, imageObject);
}

void assertionsForTableAdded( ) throws IOException {
Expand All @@ -163,25 +169,26 @@ void assertionsForTableAdded( ) throws IOException {
assertTrue( segmentationData.tableData.containsKey(TableDataFormat.TSV ) );
}

ImagePlus writeImageOutsideProject(boolean is2D ) {
Object writeImageOutsideProject(boolean is2D ) {
// add example image
ImagePlus image = createImage( imageName, is2D );
OMEZarrWriter.write( image, imageOutsideProject.getAbsolutePath(),
OMEZarrWriter.ImageType.Intensities, false );
return image;
}

ImagePlus addImageToDataset(boolean is2D, String datasetName, String imageName ) {
Object addImageToDataset(boolean is2D, String datasetName, String imageName ) {
ImagePlus image = createImage( imageName, is2D );
imagesCreator.addImage( image, imageName, datasetName,
ProjectCreator.ImageType.Image, sourceTransform,
uiSelectionGroup, false, false );
return image;
}

ImagePlus copyImageIntoDataset(boolean is2D ) {
Object copyImageIntoDataset(boolean is2D ) {
// save example image
ImagePlus image = writeImageOutsideProject( is2D );
// NB: Avoid recursive class loading of ij.* classes.
ImagePlus image = (ImagePlus) writeImageOutsideProject( is2D );

imagesCreator.addOMEZarrImage(
imageOutsideProject.getAbsolutePath(), imageName, datasetName,
Expand All @@ -193,7 +200,8 @@ ImagePlus copyImageIntoDataset(boolean is2D ) {
@ParameterizedTest
@ValueSource(booleans = { false, true })
void addImageTo3DDataset(boolean is2D) throws IOException {
ImagePlus image = addImageToDataset( is2D, datasetName, imageName );
// NB: Avoid recursive class loading of ij.* classes.
ImagePlus image = (ImagePlus) addImageToDataset( is2D, datasetName, imageName );
assertionsForImageAdded(image);
}

Expand Down Expand Up @@ -227,7 +235,8 @@ void linkImageInsideProject() throws IOException {
String otherDatasetName = "other-dataset";
String otherImageName = "other-image";
projectCreator.getDatasetsCreator().addDataset(otherDatasetName, false);
ImagePlus image = addImageToDataset(false, otherDatasetName, otherImageName);
// NB: Avoid recursive class loading of ij.* classes.
ImagePlus image = (ImagePlus) addImageToDataset(false, otherDatasetName, otherImageName);
String filePath = IOHelper.combinePath(
projectCreator.getProjectLocation().getAbsolutePath(),
otherDatasetName,
Expand All @@ -253,7 +262,8 @@ void linkImageInsideProject() throws IOException {
@Test
void linkImageOutsideProject() throws IOException {
// save example image
ImagePlus image = writeImageOutsideProject( false );
// NB: Avoid recursive class loading of ij.* classes.
ImagePlus image = (ImagePlus) writeImageOutsideProject( false );
imagesCreator.addOMEZarrImage( imageOutsideProject.getAbsolutePath(), imageName, datasetName,
ProjectCreator.ImageType.Image, ProjectCreator.AddMethod.Link,
uiSelectionGroup, false, false );
Expand All @@ -271,7 +281,8 @@ void linkImageOutsideProject() throws IOException {
@ParameterizedTest
@ValueSource(booleans = { false, true })
void copyImageTo3DDataset(boolean is2D) throws IOException {
ImagePlus image = copyImageIntoDataset( is2D );
// NB: Avoid recursive class loading of ij.* classes.
ImagePlus image = (ImagePlus) copyImageIntoDataset( is2D );
assertionsForImageAdded(image);
}

Expand Down

0 comments on commit 1906113

Please sign in to comment.