1 19 20 package org.openide.filesystems; 21 22 23 import java.io.FilterOutputStream ; 24 import java.io.IOException ; 25 import java.io.OutputStream ; 26 import org.netbeans.junit.*; 27 28 31 public class FileObject75826Test extends NbTestCase { 32 35 private LocalFileSystem lfs; 36 private FileObject testFo; 37 38 public FileObject75826Test(String name) { 39 super(name); 40 } 41 42 public static void main(String [] args) throws Exception { 43 junit.textui.TestRunner.run(new NbTestSuite(FileObject75826Test.class)); 44 } 45 46 49 protected void setUp() throws Exception { 50 51 TestUtilHid.destroyLocalFileSystem(getName()); 52 lfs = (LocalFileSystem)TestUtilHid.createLocalFileSystem(getName(), new String []{getName() }); 53 lfs = new TestFileSystem(lfs, getName()); 54 testFo = lfs.findResource(getName()); 55 assertNotNull(testFo); 56 } 57 58 public void testOutputStreamFiresIOException() throws IOException { 59 OutputStream os = null; 60 FileLock lock = null; 61 try { 62 os = testFo.getOutputStream(); 63 fail(); 64 } catch (IOException ex) {} 65 try { 66 lock = testFo.lock(); 67 assertNotNull(lock); 68 assertTrue(lock.isValid()); 69 } finally { 70 if (lock != null && lock.isValid()) { 71 lock.releaseLock(); 72 } 73 } 74 } 75 76 public void testCloseStreamFiresIOException() throws IOException { 77 FileLock lock = null; 78 OutputStream os = testFo.getOutputStream(); 79 try { 80 os.close(); 81 fail(); 82 } catch (IOException ex) {} 83 try { 84 lock = testFo.lock(); 85 assertNotNull(lock); 86 assertTrue(lock.isValid()); 87 } finally { 88 if (lock != null && lock.isValid()) { 89 lock.releaseLock(); 90 } 91 } 92 } 93 94 private static final class TestFileSystem extends LocalFileSystem { 95 TestFileSystem(LocalFileSystem lfs, String testName) throws Exception { 96 super(); 97 if ("testOutputStreamFiresIOException".equals(testName)) { 98 this.info = new LocalFileSystem.Impl(this) { 99 public OutputStream outputStream(String name) throws java.io.IOException { 100 throw new IOException (); 101 } 102 }; 103 } else if ("testCloseStreamFiresIOException".equals(testName)) { 104 this.info = new LocalFileSystem.Impl(this) { 105 public OutputStream outputStream(String name) throws java.io.IOException { 106 return new FilterOutputStream (super.outputStream(name)) { 107 public void close() throws IOException { 108 throw new IOException (); 109 } 110 }; 111 } 112 }; 113 } 114 setRootDirectory(lfs.getRootDirectory()); 115 } 116 } 117 } | Popular Tags |