/** * */ package junit.learnnow; import java.io.IOException; import static org.junit.Assert.*; import org.junit.Test; /** * @author Michael Thomas * */ public class MyFileTest { @Test public void testDisplayFile() { MyFile myClassObj1 = new MyFile(); String myInfo = null; //Test: File should NOT exist! try { myInfo = myClassObj1.displayFile("BooBoo.txt"); fail("File was supposed to not exist!"); } catch (IOException e) { // The string should be null because the file should not exit! assertNull(myInfo); } //Test: File should exist! try { myInfo = myClassObj1.displayFile("MyFileTest.txt"); } catch (IOException e) { // The string should be null because the file should not exit! assertNull(myInfo); // Note: If we expected the file to be there then we could test this // way: fail("File should have existed!\n" + e.getMessage()); } } }