Hai friends, please tell me how to write Junit for the below method,

public static FileInputStream  readAsFileInputStream(String fileName,String fileLocation) throws IOException
    {
        FileInputStream fileinputstream = null;
        File file = null;
        try
        {
            file = new File(fileLocation,fileName);
            fileinputstream = new FileInputStream(file);
        }
        catch(IOException ex)
        {
            ex.printStackTrace();
        }
        finally
        {
            fileinputstream.close();
        }
        return fileinputstream;
    }

Please help me in this problem,
Thanks.

Edited 3 Years Ago by mike_2000_17: Fixed formatting

First use code Tags.

public static FileInputStream readAsFileInputStream(String fileName,String fileLocation) throws IOException
{
FileInputStream fileinputstream = null;
File file = null;
try
{
file = new File(fileLocation,fileName);
fileinputstream = new FileInputStream(file);
}
catch(IOException ex)
{
ex.printStackTrace();
}
finally
{
fileinputstream.close();
}
return fileinputstream;
}

It is a static method. You just need to implement a test method for JUnit using the method. What you want is to check whether it throws exception properly if something goes wrong. Also, you need to check if it can return what you want. That's all. Do you know how to use JUnit by the way?

This question has already been answered. Start a new discussion instead.