KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > util > LazyFileOutputStreamTest


1 /*
2  * Copyright 2003-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 package org.apache.tools.ant.util;
18
19 import java.io.File JavaDoc;
20 import java.io.IOException JavaDoc;
21 import junit.framework.TestCase;
22
23 /**
24  * @since Ant 1.6
25  */

26 public class LazyFileOutputStreamTest extends TestCase {
27     private LazyFileOutputStream los;
28     private final static File JavaDoc f = new File JavaDoc("test.txt");
29
30     public LazyFileOutputStreamTest(String JavaDoc s) {
31         super(s);
32     }
33
34     public void setUp() {
35         los = new LazyFileOutputStream(f);
36     }
37
38     public void tearDown() throws IOException JavaDoc {
39         try {
40             los.close();
41         } finally {
42             f.delete();
43         }
44     }
45
46     public void testNoFileWithoutWrite() throws IOException JavaDoc {
47         los.close();
48         assertTrue(f + " has not been written.", !f.exists());
49     }
50
51     public void testOpen() throws IOException JavaDoc {
52         los.open();
53         los.close();
54         assertTrue(f + " has been written.", f.exists());
55     }
56
57     public void testSingleByte() throws IOException JavaDoc {
58         los.write(0);
59         los.close();
60         assertTrue(f + " has been written.", f.exists());
61     }
62
63     public void testByteArray() throws IOException JavaDoc {
64         los.write(new byte[] {0});
65         los.close();
66         assertTrue(f + " has been written.", f.exists());
67     }
68 }
69
Popular Tags