EMMA Coverage Report (generated Fri Jun 19 09:16:10 CEST 2009)
[all classes][org.ktc.rbutils.api.file]

COVERAGE SUMMARY FOR SOURCE FILE [ValidateFile.java]

nameclass, %method, %block, %line, %
ValidateFile.java100% (1/1)75%  (3/4)92%  (72/78)89%  (17/19)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ValidateFile100% (1/1)75%  (3/4)92%  (72/78)89%  (17/19)
ValidateFile (): void 0%   (0/1)0%   (0/6)0%   (0/2)
isDirectory (File): void 100% (1/1)100% (32/32)100% (7/7)
isFile (File): void 100% (1/1)100% (32/32)100% (7/7)
notNull (File): void 100% (1/1)100% (8/8)100% (3/3)

1/*
2 * Copyright  2005-2006 The RbUtils Project
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// $Id: ValidateFile.java,v 1.2 2006/09/16 14:39:46 redfish Exp $
19 
20package org.ktc.rbutils.api.file;
21 
22import java.io.File;
23import java.io.FileNotFoundException;
24import org.apache.commons.lang.NullArgumentException;
25import org.apache.commons.lang.Validate;
26 
27/**
28 * Assists in validating <code>File</code> arguments.
29 * @see org.apache.commons.lang.Validate
30 * @since RbUtils 0.7.2
31 * @version $Revision: 1.2 $
32 * @author redfish
33 */
34public class ValidateFile extends Validate {
35 
36    /** Part of the displayed message when a <code>File</code> does not exist. */
37    private static final String NOT_EXIST_MSG = " does not exist";
38    /** TODO Javadoc. */
39    private static final String FILE_MSG = "file";
40 
41    /** Dummy constructor. This <b>MUST NOT</b> be instanciated. */
42    protected ValidateFile() {
43        // prevents calls from subclass
44        throw new UnsupportedOperationException();
45    }
46 
47    /**
48     * Validate an argument, throwing <code>Exception</code> if the <code>File</code> argument
49     * is not a directory.
50     * @param directory the object to check if not a directory.
51     * @throws NullArgumentException if <code>directory</code> is <code>null</code>.
52     * @throws FileNotFoundException if <code>directory</code> does not exist.
53     * @throws NotDirectoryException if <code>directory</code> is not a directory.
54     */
55    public static void isDirectory(final File directory) throws FileNotFoundException {
56        if (directory == null) {
57            throw new NullArgumentException("directory");
58        }
59        else if (!directory.exists()) {
60            throw new FileNotFoundException(directory.getAbsolutePath() + NOT_EXIST_MSG);
61        }
62        else if (!directory.isDirectory()) {
63            throw new NotDirectoryException(directory);
64        }
65    }
66 
67//    /**
68//     * Validate an argument, throwing <code>Exception</code> if the <code>File</code> argument
69//     * is not an existing directory.
70//     * @param directory the object to check if not an existing directory
71//     * @throws NullArgumentException if <code>directory</code> is <code>null</code>
72//     * @throws FileNotFoundException if <code>directory</code> does not exist
73//     * @throws NotDirectoryException if <code>directory</code> is not a directory
74//     */
75//    public static void directoryExists(final File directory) throws FileNotFoundException {
76//        isDirectory(directory);
77//        if (!directory.exists()) {
78//            throw new FileNotFoundException(directory.getAbsolutePath() + NOT_EXIST_MSG);
79//        }
80//    }
81 
82    /**
83     * Validate an argument, throwing <code>Exception</code> if the <code>File</code> argument
84     * does not exist ant is not a file (file as in a file system).
85     * @param file the object to check if not a file.
86     * @throws NullArgumentException if <code>file</code> is <code>null</code>.
87     * @throws FileNotFoundException if <code>file</code> does not exist.
88     * @throws NotFileException if <code>file</code> is not a file.
89     */
90    public static void isFile(final File file) throws FileNotFoundException {
91        if (file == null) {
92            throw new NullArgumentException(FILE_MSG);
93        }
94        else if (!file.exists()) {
95            throw new FileNotFoundException(file.getAbsolutePath() + NOT_EXIST_MSG);
96        }
97        else if (!file.isFile()) {
98            throw new NotFileException(file);
99        }
100    }
101 
102    /**
103     * Validate an argument, throwing <code>NullArgumentException</code> if the <code>File</code>
104     * is <code>null</code>.
105     * @param file the file to check if <code>null</code>
106     * @throws NullArgumentException if <code>file</code> is <code>null</code>
107     */
108    public static void notNull(final File file) {
109        if (file == null) {
110            throw new NullArgumentException(FILE_MSG);
111        }
112    }
113 
114// /**
115//     * Validate an argument, throwing <code>Exception</code> if the <code>File</code> argument
116//     * is not is not an existing file (file as in a file system).
117//     * @param file the object to check if not a file
118//     * @throws NullArgumentException if <code>file</code> is <code>null</code>
119//     * @throws NotDirectoryException if <code>file</code> is not a file
120//     * @throws FileNotFoundException if <code>file</code> does not exist
121//     */
122//    public static void fileExists(final File file) throws FileNotFoundException {
123//        isFile(file);
124//        if (!file.exists()) {
125//            throw new FileNotFoundException(file.getAbsolutePath() + NOT_EXIST_MSG);
126//        }
127//    }
128 
129}

[all classes][org.ktc.rbutils.api.file]
EMMA 2.0.5312 (C) Vladimir Roubtsov