@@ -0,0 +1,2141 @@
+/*%0A * Copyright 2004 The Apache Software Foundation.%0A * %0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A * %0A *      http://www.apache.org/licenses/LICENSE-2.0%0A * %0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0A%0Apackage org.apache.commons.io.output;%0A%0A%0Aimport java.io.IOException;%0A%0Aimport junit.framework.TestCase;%0A%0A/**%0A * Tests that files really lock, although no writing is done as %0A * the locking is tested only on construction. %0A *%0A * @author Henri Yandell (bayard at apache dot org)%0A * @version $Revision: 1.1 $ $Date: 2004/02/23 05:49:52 $%0A */%0A%0Apublic class LockableFileWriterTest extends TestCase %7B%0A%0A    public LockableFileWriterTest(String name) %7B%0A        super(name);%0A    %7D%0A%0A    public void testFileLocked() throws IOException %7B%0A        LockableFileWriter lfw = new LockableFileWriter(%22testlockfile%22);%0A        try %7B%0A            LockableFileWriter lfw2 = new LockableFileWriter(%22testlockfile%22);%0A            fail(%22Somehow able to open a locked file. %22);%0A        %7D catch(IOException ioe) %7B%0A            String msg = ioe.getMessage();%0A            assertTrue( %22Exception message does not start correctly. %22, %0A                        msg.startsWith(%22Can't write file, lock %22) );%0A        %7D%0A        lfw.close();%0A    %7D%0A%0A    public void testFileNotLocked() throws IOException %7B%0A        LockableFileWriter lfw = new LockableFileWriter(%22testnotlockfile%22);%0A        lfw.close();%0A        try %7B%0A            LockableFileWriter lfw2 = new LockableFileWriter(%22testnotlockfile%22);%0A            lfw2.close();%0A        %7D catch(IOException ioe) %7B%0A            String msg = ioe.getMessage();%0A            if( msg.startsWith(%22Can't write file, lock %22) ) %7B%0A                fail(%22Somehow unable to open a unlocked file. %22);%0A            %7D%0A        %7D%0A    %7D%0A%0A%7D%0A

test for locking files