|
19 | 19 | import static org.apache.commons.vfs2.VfsTestUtils.getTestDirectoryFile; |
20 | 20 |
|
21 | 21 | import java.io.File; |
| 22 | +import java.io.InputStream; |
22 | 23 | import java.io.PrintWriter; |
23 | 24 | import java.net.URL; |
24 | 25 | import java.net.URLConnection; |
@@ -196,11 +197,21 @@ public void testLoadClass() throws Exception { |
196 | 197 | public void testLoadResource() throws Exception { |
197 | 198 | final VFSClassLoader loader = createClassLoader(); |
198 | 199 |
|
199 | | - final URL resource = loader.getResource("read-tests/file1.txt"); |
| 200 | + final URL resource1 = loader.getResource("read-tests/file1.txt"); |
| 201 | + assertNotNull(resource1); |
| 202 | + final URLConnection urlCon1 = resource1.openConnection(); |
| 203 | + final InputStream instr1 = urlCon1.getInputStream(); |
200 | 204 |
|
201 | | - assertNotNull(resource); |
202 | | - final URLConnection urlCon = resource.openConnection(); |
203 | | - assertSameURLContent(FILE1_CONTENT, urlCon); |
| 205 | + // VFS-834: testing that getting the resource again does not close out the previous input stream. |
| 206 | + final URL resource2 = loader.getResource("read-tests/file1.txt"); |
| 207 | + |
| 208 | + assertSameURLContent(FILE1_CONTENT, instr1, urlCon1); |
| 209 | + |
| 210 | + assertNotNull(resource2); |
| 211 | + final URLConnection urlCon2 = resource2.openConnection(); |
| 212 | + final InputStream instr2 = urlCon1.getInputStream(); |
| 213 | + |
| 214 | + assertSameURLContent(FILE1_CONTENT, instr2, urlCon2); |
204 | 215 | } |
205 | 216 |
|
206 | 217 | /** |
|
0 commit comments