jUnit exceptions

T I
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2013

Hi,

I'm trying to build some jUnit tests for a plugin.

In this plugin there is a method called readExcelFile() that throws FileNotFoundException and IOException.

Any idea how the test should look like to test it for the FileNotFoundException is thrown?

My code:

@Test(expected = FileNotFoundException.class)
	public void testParsedFile(){
    	MyPluginComponent component = new MyPluginComponentImpl(null);
    	component.readExcelFile("C:/Users/abc/Desktop/ClarityExportSample.xlsx");
	}

Line 4 gives me an error that I have to catch the IOException. But I actually want to test if the FileNotFoundException is thrown here.

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Timothy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2013

Well, FileNotFound exception is a sub of IOException. Your component.readExcelFile should throw the right exception.

TAGS
AUG Leaders

Atlassian Community Events