Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[GEOT-5419] Fix NetCDFImageReaderSpi file dispose
- Loading branch information
Nuno Oliveira
committed
May 16, 2016
1 parent
ec4e4b8
commit fab2c13
Showing
2 changed files
with
61 additions
and
4 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
49 changes: 49 additions & 0 deletions
49
...e-multidim/netcdf/src/test/java/org/geotools/imageio/netcdf/NetCDFImageReaderSpiTest.java
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,49 @@ | ||
/* | ||
* GeoTools - The Open Source Java GIS Toolkit | ||
* http://geotools.org | ||
* | ||
* (C) 2016, Open Source Geospatial Foundation (OSGeo) | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; | ||
* version 2.1 of the License. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
*/ | ||
package org.geotools.imageio.netcdf; | ||
|
||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Random; | ||
import java.util.UUID; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.junit.Assert.*; | ||
|
||
public final class NetCDFImageReaderSpiTest { | ||
|
||
@Test | ||
public void testFileIsProperlyClosed() throws Exception { | ||
// create a temporary file and write some random bytes on it | ||
Path path = Files.createTempFile(UUID.randomUUID().toString(), ".txt"); | ||
byte[] content = new byte[100]; | ||
Random random = new Random(); | ||
random.nextBytes(content); | ||
Files.write(path, content); | ||
// invoking the reader that will not be able to read the file | ||
File file = path.toFile(); | ||
NetCDFImageReaderSpi reader = new NetCDFImageReaderSpi(); | ||
reader.canDecodeInput(file); | ||
// check if the file as some lock on it | ||
assertThat(file.delete(), is(true)); | ||
} | ||
} |