|
19 | 19 |
|
20 | 20 |
|
21 | 21 | import java.io.IOException; |
| 22 | +import java.io.File; |
22 | 23 |
|
23 | 24 | import junit.framework.TestCase; |
24 | 25 |
|
|
27 | 28 | * the locking is tested only on construction. |
28 | 29 | * |
29 | 30 | * @author Henri Yandell (bayard at apache dot org) |
30 | | - * @version $Revision: 1.1 $ $Date: 2004/02/23 05:49:52 $ |
| 31 | + * @version $Revision: 1.2 $ $Date: 2004/02/29 21:07:14 $ |
31 | 32 | */ |
32 | 33 |
|
33 | 34 | public class LockableFileWriterTest extends TestCase { |
34 | 35 |
|
| 36 | + private File file; |
| 37 | + |
35 | 38 | public LockableFileWriterTest(String name) { |
36 | 39 | super(name); |
37 | 40 | } |
38 | 41 |
|
| 42 | + public void setUp() { |
| 43 | + this.file = new File("testlockfile"); |
| 44 | + } |
| 45 | + |
| 46 | + public void tearDown() { |
| 47 | + this.file.delete(); |
| 48 | + } |
| 49 | + |
39 | 50 | public void testFileLocked() throws IOException { |
40 | | - LockableFileWriter lfw = new LockableFileWriter("testlockfile"); |
| 51 | + LockableFileWriter lfw = new LockableFileWriter(this.file); |
41 | 52 | try { |
42 | | - LockableFileWriter lfw2 = new LockableFileWriter("testlockfile"); |
| 53 | + LockableFileWriter lfw2 = new LockableFileWriter(this.file); |
43 | 54 | fail("Somehow able to open a locked file. "); |
44 | 55 | } catch(IOException ioe) { |
45 | 56 | String msg = ioe.getMessage(); |
46 | 57 | assertTrue( "Exception message does not start correctly. ", |
47 | 58 | msg.startsWith("Can't write file, lock ") ); |
| 59 | + } finally { |
| 60 | + lfw.close(); |
48 | 61 | } |
49 | | - lfw.close(); |
50 | 62 | } |
51 | 63 |
|
52 | 64 | public void testFileNotLocked() throws IOException { |
53 | | - LockableFileWriter lfw = new LockableFileWriter("testnotlockfile"); |
| 65 | + LockableFileWriter lfw = new LockableFileWriter(this.file); |
54 | 66 | lfw.close(); |
55 | 67 | try { |
56 | | - LockableFileWriter lfw2 = new LockableFileWriter("testnotlockfile"); |
| 68 | + LockableFileWriter lfw2 = new LockableFileWriter(this.file); |
57 | 69 | lfw2.close(); |
58 | 70 | } catch(IOException ioe) { |
59 | 71 | String msg = ioe.getMessage(); |
|
0 commit comments