Skip to content

Commit 3bb133b

Browse files
committed
cleans up after itself now, rather than leaving lockfiles
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@140530 13f79535-47bb-0310-9956-ffa450edef68
1 parent 11a51ce commit 3bb133b

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

src/test/org/apache/commons/io/output/LockableFileWriterTest.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020

2121
import java.io.IOException;
22+
import java.io.File;
2223

2324
import junit.framework.TestCase;
2425

@@ -27,33 +28,44 @@
2728
* the locking is tested only on construction.
2829
*
2930
* @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 $
3132
*/
3233

3334
public class LockableFileWriterTest extends TestCase {
3435

36+
private File file;
37+
3538
public LockableFileWriterTest(String name) {
3639
super(name);
3740
}
3841

42+
public void setUp() {
43+
this.file = new File("testlockfile");
44+
}
45+
46+
public void tearDown() {
47+
this.file.delete();
48+
}
49+
3950
public void testFileLocked() throws IOException {
40-
LockableFileWriter lfw = new LockableFileWriter("testlockfile");
51+
LockableFileWriter lfw = new LockableFileWriter(this.file);
4152
try {
42-
LockableFileWriter lfw2 = new LockableFileWriter("testlockfile");
53+
LockableFileWriter lfw2 = new LockableFileWriter(this.file);
4354
fail("Somehow able to open a locked file. ");
4455
} catch(IOException ioe) {
4556
String msg = ioe.getMessage();
4657
assertTrue( "Exception message does not start correctly. ",
4758
msg.startsWith("Can't write file, lock ") );
59+
} finally {
60+
lfw.close();
4861
}
49-
lfw.close();
5062
}
5163

5264
public void testFileNotLocked() throws IOException {
53-
LockableFileWriter lfw = new LockableFileWriter("testnotlockfile");
65+
LockableFileWriter lfw = new LockableFileWriter(this.file);
5466
lfw.close();
5567
try {
56-
LockableFileWriter lfw2 = new LockableFileWriter("testnotlockfile");
68+
LockableFileWriter lfw2 = new LockableFileWriter(this.file);
5769
lfw2.close();
5870
} catch(IOException ioe) {
5971
String msg = ioe.getMessage();

0 commit comments

Comments
 (0)