tiebin-zhang / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

Nullifying after a try for a finally test #369

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Powermock is great! However, I'm stuck on the following. Take the following 
class

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

public class FileReader{

  private final File input; 
  public FileReader(final String filename) throws FileNotFoundException {
    input = new File(filename);
  }

  public Board read() throws IOException{
    String line;
    boolean didTry = false;
    Scanner scanner = null;

    try {
      scanner = new Scanner(new FileInputStream(input), "UTF-8");

      while (scanner.hasNextLine()) {
        line = scanner.nextLine();
        if (!lineIsOK(line)) {
          throw new IOException("Bad Line");
        }
      }
      didTry = true;

    }finally {
      if(scanner != null){
        System.out.println("Scanner is fine didTry " + didTry);
        scanner.close();
      }else{
        System.out.println("Scanner is null didTry " + didTry);
      }
    }
  }
}

Can I test the line 'Scanner is null didTry true' with powermockito?

Thanks and regards

Amol

Original issue reported on code.google.com by amol.par...@gmail.com on 7 Feb 2012 at 10:19

GoogleCodeExporter commented 9 years ago

Original comment by johan.ha...@gmail.com on 7 Feb 2012 at 10:26