0

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 by mike_2000_17: Fixed formatting

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by softswing
0

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;
}
0

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?

0

Tahnks lot Taywin, Now i get the idea for using JUnit for this.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.