All Downloads are FREE. Search and download functionalities are using the official Maven repository.

automated.process.io.validations.ValidateFile Maven / Gradle / Ivy

package automated.process.io.validations;

import automated.reporting.TestReporter;

import java.io.File;

/**
 * Created by Ismail on 12/26/2017.
 * This class contains all related methods to validate if file status
 * is correct and checking validity of the file
 */
public class ValidateFile {

    /*************** Class Methods Section ***************/
    // This method to validate if file exist then return true
    private static Boolean verifyFileExist(String filePath) {
        return new File(filePath).exists();
    }

    // This method validate if Provided File is file or directory
    private static Boolean verifyFileIsFolder(String filePath) {
        return new File(filePath).isDirectory();// If file then return true
    }

    // This method validate if Provided File contains Data or Empty
    private static Boolean verifyFileContainsData(String filePath) {
        return new File(filePath).length() != 0;
    }

    // This method validate File status overall
    // If File Path exist, not a directory and contains data
    // This method depends on all current private methods in this class
    public static void verifyFileStatus(String filePath) {
        if (!verifyFileExist(filePath)) {
            TestReporter.error("File isn't exist, Please check File Path: " + filePath, true);
        }

        if (verifyFileIsFolder(filePath)) {
            TestReporter.error("The Provided a folder not a file, Please check Folder Path: " + filePath, true);
        }

        if (!verifyFileContainsData(filePath)) {
            TestReporter.error("The Provided an Empty File, Please check file Path: " + filePath, true);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy