@Test
public void testSetDimensions_VaryingDimensionLengths() throws IOException {

    List<Dimension>[] dimensionLists = new ArrayList[2];
    List<Variable>[] variableLists = new ArrayList[2];
    final File inputFile1 = new File(targetDirectory, "input_1.nc");
    final NFileWriteable inputWriteable1 = NWritableFactory.create(inputFile1.getAbsolutePath(), "netcdf4");
    inputWriteable1.addDimension("rows", 5);
    inputWriteable1.addDimension("columns", 7);
    inputWriteable1.addDimension("the_twilight_zone", 12);
    final NVariable abVariable1 = inputWriteable1.addVariable("ab", DataType.BYTE, true, null, "rows columns");
    final NVariable cdVariable1 = inputWriteable1.addVariable("cd", DataType.LONG, false, null, "columns the_twilight_zone");
    inputWriteable1.create();
    abVariable1.writeFully(new ArrayByte(new int[]{5, 7}, false));
    cdVariable1.writeFully(new ArrayLong(new int[]{7, 12}, false));
    inputWriteable1.close();
    final NetcdfFile inputnc1 = NetcdfFileOpener.open(inputFile1);
    assertNotNull(inputnc1);
    dimensionLists[0] = inputnc1.getDimensions();
    variableLists[0] = inputnc1.getVariables();
    inputnc1.close();
    final File inputFile2 = new File(targetDirectory, "input_2.nc");
    final NFileWriteable inputWriteable2 = NWritableFactory.create(inputFile2.getAbsolutePath(), "netcdf4");
    inputWriteable2.addDimension("rows", 5);
    inputWriteable2.addDimension("columns", 7);
    inputWriteable2.addDimension("the_twilight_zone", 25);
    final NVariable abVariable2 = inputWriteable2.addVariable("ab", DataType.BYTE, true, null, "rows columns");
    final NVariable cdVariable2 = inputWriteable2.addVariable("ef", DataType.LONG, false, null, "columns the_twilight_zone");
    inputWriteable2.create();
    abVariable2.writeFully(new ArrayByte(new int[]{5, 7}, false));
    cdVariable2.writeFully(new ArrayLong(new int[]{7, 25}, false));
    inputWriteable2.close();
    final NetcdfFile inputnc2 = NetcdfFileOpener.open(inputFile2);
    assertNotNull(inputnc2);
    dimensionLists[1] = inputnc2.getDimensions();
    variableLists[1] = inputnc2.getVariables();
    inputnc2.close();
    final File file = new File(targetDirectory, "something.nc");
    SlstrNFileWritable netcdfWriteable = new SlstrNFileWritable(file.getAbsolutePath());
    ImageSize targetImageSize = new ImageSize("id", 10, 20, 10, 20);
    try {
        NcFileStitcher.setDimensions(netcdfWriteable, dimensionLists, targetImageSize, variableLists);
        fail("Exception expected");
    } catch (Exception e) {
        assertEquals("Dimension the_twilight_zone has different lengths across input files", e.getMessage());
    } finally {
        netcdfWriteable.create();
        netcdfWriteable.close();
    }
}