~ubuntu-branches/ubuntu/trusty/commons-io/trusty

« back to all changes in this revision

Viewing changes to src/test/org/apache/commons/io/FileDeleteStrategyTestCase.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2007-04-13 08:20:49 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070413082049-2hd3s5ixtxsgvnvm
Tags: 1.3.1.dfsg.1-1
* New upstream (closes: #418973)
* java-gcj-compat-dev and cdbs transition
* Removed junit at the moment (closes: #397567)
* No javadoc at the moment

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
 
3
 * contributor license agreements.  See the NOTICE file distributed with
 
4
 * this work for additional information regarding copyright ownership.
 
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
 
6
 * (the "License"); you may not use this file except in compliance with
 
7
 * the License.  You may obtain a copy of the License at
 
8
 * 
 
9
 *      http://www.apache.org/licenses/LICENSE-2.0
 
10
 * 
 
11
 * Unless required by applicable law or agreed to in writing, software
 
12
 * distributed under the License is distributed on an "AS IS" BASIS,
 
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
14
 * See the License for the specific language governing permissions and
 
15
 * limitations under the License.
 
16
 */
 
17
package org.apache.commons.io;
 
18
 
 
19
import java.io.File;
 
20
import java.io.IOException;
 
21
 
 
22
import junit.framework.Test;
 
23
import junit.framework.TestSuite;
 
24
 
 
25
import org.apache.commons.io.testtools.FileBasedTestCase;
 
26
 
 
27
/**
 
28
 * Test for FileDeleteStrategy.
 
29
 *
 
30
 * @version $Id: FileDeleteStrategyTestCase.java 453906 2006-10-07 13:53:09Z scolebourne $
 
31
 * @see FileDeleteStrategy
 
32
 */
 
33
public class FileDeleteStrategyTestCase extends FileBasedTestCase {
 
34
 
 
35
    public static Test suite() {
 
36
        return new TestSuite(FileDeleteStrategyTestCase.class);
 
37
    }
 
38
 
 
39
    public FileDeleteStrategyTestCase(String name) {
 
40
        super(name);
 
41
    }
 
42
 
 
43
    protected void setUp() throws Exception {
 
44
        super.setUp();
 
45
    }
 
46
 
 
47
    protected void tearDown() throws Exception {
 
48
        super.tearDown();
 
49
    }
 
50
 
 
51
    //-----------------------------------------------------------------------
 
52
    public void testDeleteNormal() throws Exception {
 
53
        File baseDir = getTestDirectory();
 
54
        File subDir = new File(baseDir, "test");
 
55
        assertEquals(true, subDir.mkdir());
 
56
        File subFile = new File(subDir, "a.txt");
 
57
        createFile(subFile, 16);
 
58
        
 
59
        assertEquals(true, subDir.exists());
 
60
        assertEquals(true, subFile.exists());
 
61
        // delete dir
 
62
        try {
 
63
            FileDeleteStrategy.NORMAL.delete(subDir);
 
64
            fail();
 
65
        } catch (IOException ex) {
 
66
            // expected
 
67
        }
 
68
        assertEquals(true, subDir.exists());
 
69
        assertEquals(true, subFile.exists());
 
70
        // delete file
 
71
        FileDeleteStrategy.NORMAL.delete(subFile);
 
72
        assertEquals(true, subDir.exists());
 
73
        assertEquals(false, subFile.exists());
 
74
        // delete dir
 
75
        FileDeleteStrategy.NORMAL.delete(subDir);
 
76
        assertEquals(false, subDir.exists());
 
77
        // delete dir
 
78
        FileDeleteStrategy.NORMAL.delete(subDir);  // no error
 
79
        assertEquals(false, subDir.exists());
 
80
    }
 
81
 
 
82
    public void testDeleteQuietlyNormal() throws Exception {
 
83
        File baseDir = getTestDirectory();
 
84
        File subDir = new File(baseDir, "test");
 
85
        assertEquals(true, subDir.mkdir());
 
86
        File subFile = new File(subDir, "a.txt");
 
87
        createFile(subFile, 16);
 
88
        
 
89
        assertEquals(true, subDir.exists());
 
90
        assertEquals(true, subFile.exists());
 
91
        // delete dir
 
92
        assertEquals(false, FileDeleteStrategy.NORMAL.deleteQuietly(subDir));
 
93
        assertEquals(true, subDir.exists());
 
94
        assertEquals(true, subFile.exists());
 
95
        // delete file
 
96
        assertEquals(true, FileDeleteStrategy.NORMAL.deleteQuietly(subFile));
 
97
        assertEquals(true, subDir.exists());
 
98
        assertEquals(false, subFile.exists());
 
99
        // delete dir
 
100
        assertEquals(true, FileDeleteStrategy.NORMAL.deleteQuietly(subDir));
 
101
        assertEquals(false, subDir.exists());
 
102
        // delete dir
 
103
        assertEquals(true, FileDeleteStrategy.NORMAL.deleteQuietly(subDir));  // no error
 
104
        assertEquals(false, subDir.exists());
 
105
    }
 
106
 
 
107
    public void testDeleteForce() throws Exception {
 
108
        File baseDir = getTestDirectory();
 
109
        File subDir = new File(baseDir, "test");
 
110
        assertEquals(true, subDir.mkdir());
 
111
        File subFile = new File(subDir, "a.txt");
 
112
        createFile(subFile, 16);
 
113
        
 
114
        assertEquals(true, subDir.exists());
 
115
        assertEquals(true, subFile.exists());
 
116
        // delete dir
 
117
        FileDeleteStrategy.FORCE.delete(subDir);
 
118
        assertEquals(false, subDir.exists());
 
119
        assertEquals(false, subFile.exists());
 
120
        // delete dir
 
121
        FileDeleteStrategy.FORCE.delete(subDir);  // no error
 
122
        assertEquals(false, subDir.exists());
 
123
    }
 
124
 
 
125
    public void testDeleteNull() throws Exception {
 
126
        try {
 
127
            FileDeleteStrategy.NORMAL.delete((File) null);
 
128
            fail();
 
129
        } catch (NullPointerException ex) {
 
130
            // expected
 
131
        }
 
132
        assertEquals(true, FileDeleteStrategy.NORMAL.deleteQuietly((File) null));
 
133
    }
 
134
 
 
135
    public void testToString() {
 
136
        assertEquals("FileDeleteStrategy[Normal]", FileDeleteStrategy.NORMAL.toString());
 
137
        assertEquals("FileDeleteStrategy[Force]", FileDeleteStrategy.FORCE.toString());
 
138
    }
 
139
 
 
140
}