Writing Junit test to cover exception and catch block
<p>I have written Junit test case for following function. When checked JACOCO test coverage. It is showing only try block is covered by test case. I am newbie to writing test cases. How the exceptions and catch block can be covered in test cases  </p>

<p>Here is a method</p>

<pre><code>  public static List&lt;Student&gt; readCsvFile(String fileName)
    {

       BufferedReader fileReader = null;

//logic to read file    
}
catch (Exception e)
{
   System.out.println("Error in CsvFileReader !!!");
   e.printStackTrace();
        } finally
        {
            try
            {
                fileReader.close();
            } catch (IOException e)
            {
                System.out.println("Error while closing fileReader !!!");
                e.printStackTrace();
            }
        }
        return students;
    }
</code></pre>

<p>And TestMethod</p>

<pre><code>@Test
    public void ReadCsvFileTest()
    {
        String fileName = "test.csv";
        List&lt;Student&gt; result = new ArrayList&lt;Student&gt;();
        result = CsvFileReader.readCsvFile(fileName);

        Student student1 = null;

        Iterator&lt;Student&gt; it = result.iterator();
        while (it.hasNext())
        {
            Student s = it.next();
            if ("471908US".equals(s.getId()))
            {
                student1 = s;
                break;
            }
        }

        assertTrue(student1 != null);
    }
</code></pre>