title: Junit: How to test a method that read properties from a property file
body: <p>Hi I have a class <code>ReadProperty</code> which has a method <code>ReadPropertyFile</code> of return type <code>Myclass</code> which read the parameter values from a property file and return <code>Myclass</code> object. I need help to test the <code>ReadPropertyFile</code> method with <code>JUnit</code>, if possible with mock files and mock object. </p>
  
  <p>Here is my code.</p>
  
  <pre><code>import java.io.FileInputStream;
  import java.util.Properties;
  
  public class ReadProperty {
  
      public Myclass ReadPropertyFile(String fileName) {
          Myclass myclass = null;
          String testparam = null;
  
          FileInputStream fis = null;
  
  
  
          Properties prop = new Properties();
          try {
              fis = new FileInputStream(fileName);
              try {
                  prop.load(fis);
                  System.out.println("Load Property file : Success !");
              } catch (Exception ex) {
                  System.out.println("Load Property file : Exception : " + ex.toString());
              }
              /*
               * loading the properties
               */
              try {
                  testparam = prop.getProperty("testparam");
                  System.out.println("testparam Type : " + testparam);
              } catch (Exception ex) {
                  System.out.println("testparam Type : " + ex.toString());
              }
  
          } catch (Exception ex) {
              ex.printStackTrace();
              System.out.println("Property file read fail : " + ex.toString());
              System.exit(1);
          }
          Myclass = new Myclass(testparam);
          return Myclass;
      } }
  </code></pre>