1616package com .marklogic .client .test ;
1717
1818import static org .junit .Assert .assertEquals ;
19+ import static org .junit .Assert .assertTrue ;
1920
2021import java .io .File ;
22+ import java .io .FileInputStream ;
2123import java .io .IOException ;
2224import java .io .StringReader ;
2325import java .net .URISyntaxException ;
3234import com .marklogic .client .io .InputStreamHandle ;
3335import com .marklogic .client .io .ReaderHandle ;
3436import com .marklogic .client .io .StringHandle ;
37+ import java .io .InputStream ;
3538public class HandleAccessorTest {
39+ public static boolean fileInputStreamWasClosed ;
40+
3641 @ Test
3742 public void testContentAsString () throws URISyntaxException , IOException {
3843 // I'm purposely using a string with a non-ascii character to test
@@ -50,5 +55,16 @@ public void testContentAsString() throws URISyntaxException, IOException {
5055 HandleAccessor .contentAsString (new FileHandle (new File (filePath .toURI ()))));
5156 assertEquals ("InputStream content mismatch" , hola ,
5257 HandleAccessor .contentAsString (new InputStreamHandle (filePath .openStream ())));
58+
59+ InputStream fileInputStream = new FileInputStream (new File (filePath .toURI ())) {
60+ @ Override
61+ public void close () throws IOException {
62+ super .close ();
63+ HandleAccessorTest .fileInputStreamWasClosed = true ;
64+ }
65+ };
66+ assertEquals ("InputStream content mismatch" , hola ,
67+ HandleAccessor .contentAsString (new InputStreamHandle (fileInputStream )));
68+ assertTrue (this .fileInputStreamWasClosed );
5369 }
5470}
0 commit comments