Fixed NullPointerException, when dialect is specified in properties-file
[hibernate4-maven-plugin] / src / test / java / de / juplo / test / FileComparator.java
1 package de.juplo.test;
2
3 import java.io.BufferedReader;
4 import java.io.File;
5 import java.io.FileNotFoundException;
6 import java.io.FileReader;
7 import java.io.IOException;
8
9
10 public class FileComparator
11 {
12   private final File basedir;
13   private BufferedReader expectedReader;
14   private BufferedReader foundReader;
15
16   public FileComparator(File basedir)
17   {
18     this.basedir = basedir;
19   }
20
21   public boolean isEqual(final String expectedFile, final String foundFile)
22     throws
23       FileNotFoundException,
24       IOException
25   {
26     File file;
27     String expected, found;
28
29     file = new File(basedir, expectedFile);
30     expectedReader = new BufferedReader(new FileReader(file));
31
32     file = new File(basedir, foundFile);
33     foundReader = new BufferedReader(new FileReader(file));
34
35
36     while ((expected = expectedReader.readLine()) != null)
37     {
38       found = foundReader.readLine();
39       if (!expected.equals(found))
40       {
41         System.err.println("Mismatch!");
42         System.err.println("Expected: " + expected);
43         System.err.println("Found:    " + found);
44         return false;
45       }
46     }
47
48     if ((found = foundReader.readLine()) != null)
49     {
50       System.err.println("Found more content than expected!");
51       System.err.println("Starting with: " + found);
52       return false;
53     }
54
55     return true;
56   }
57 }