Skip to content

Commit 9a592c4

Browse files
committed
test for locking files
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@140528 13f79535-47bb-0310-9956-ffa450edef68
1 parent 023d871 commit 9a592c4

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2004 The Apache Software Foundation.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
18+
package org.apache.commons.io.output;
19+
20+
21+
import java.io.IOException;
22+
23+
import junit.framework.TestCase;
24+
25+
/**
26+
* Tests that files really lock, although no writing is done as
27+
* the locking is tested only on construction.
28+
*
29+
* @author Henri Yandell (bayard at apache dot org)
30+
* @version $Revision: 1.1 $ $Date: 2004/02/23 05:49:52 $
31+
*/
32+
33+
public class LockableFileWriterTest extends TestCase {
34+
35+
public LockableFileWriterTest(String name) {
36+
super(name);
37+
}
38+
39+
public void testFileLocked() throws IOException {
40+
LockableFileWriter lfw = new LockableFileWriter("testlockfile");
41+
try {
42+
LockableFileWriter lfw2 = new LockableFileWriter("testlockfile");
43+
fail("Somehow able to open a locked file. ");
44+
} catch(IOException ioe) {
45+
String msg = ioe.getMessage();
46+
assertTrue( "Exception message does not start correctly. ",
47+
msg.startsWith("Can't write file, lock ") );
48+
}
49+
lfw.close();
50+
}
51+
52+
public void testFileNotLocked() throws IOException {
53+
LockableFileWriter lfw = new LockableFileWriter("testnotlockfile");
54+
lfw.close();
55+
try {
56+
LockableFileWriter lfw2 = new LockableFileWriter("testnotlockfile");
57+
lfw2.close();
58+
} catch(IOException ioe) {
59+
String msg = ioe.getMessage();
60+
if( msg.startsWith("Can't write file, lock ") ) {
61+
fail("Somehow unable to open a unlocked file. ");
62+
}
63+
}
64+
}
65+
66+
}

0 commit comments

Comments
 (0)