1 16 17 18 package org.apache.commons.io.output; 19 20 21 import java.io.IOException ; 22 import java.io.File ; 23 24 import junit.framework.TestCase; 25 26 33 34 public class LockableFileWriterTest extends TestCase { 35 36 private File file; 37 38 public LockableFileWriterTest(String name) { 39 super(name); 40 } 41 42 public void setUp() { 43 this.file = new File ("testlockfile"); 44 } 45 46 public void tearDown() { 47 this.file.delete(); 48 } 49 50 public void testFileLocked() throws IOException { 51 LockableFileWriter lfw = new LockableFileWriter(this.file); 52 try { 53 LockableFileWriter lfw2 = new LockableFileWriter(this.file); 54 fail("Somehow able to open a locked file. "); 55 } catch(IOException ioe) { 56 String msg = ioe.getMessage(); 57 assertTrue( "Exception message does not start correctly. ", 58 msg.startsWith("Can't write file, lock ") ); 59 } finally { 60 lfw.close(); 61 } 62 } 63 64 public void testFileNotLocked() throws IOException { 65 LockableFileWriter lfw = new LockableFileWriter(this.file); 66 lfw.close(); 67 try { 68 LockableFileWriter lfw2 = new LockableFileWriter(this.file); 69 lfw2.close(); 70 } catch(IOException ioe) { 71 String msg = ioe.getMessage(); 72 if( msg.startsWith("Can't write file, lock ") ) { 73 fail("Somehow unable to open a unlocked file. "); 74 } 75 } 76 } 77 78 } 79 | Popular Tags |