Upgraded Hibernate from 5.2.4.Final to 5.2.18.Final
[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 import java.util.regex.Pattern;
9
10
11 public class FileComparator
12 {
13   private final File basedir;
14   private BufferedReader expectedReader;
15   private BufferedReader foundReader;
16
17   public FileComparator(File basedir)
18   {
19     this.basedir = basedir;
20   }
21
22   public boolean isEqual(final String expectedFile, final String foundFile)
23     throws
24       FileNotFoundException,
25       IOException
26   {
27     File file;
28     String expected, found;
29
30     file = new File(basedir, expectedFile);
31     expectedReader = new BufferedReader(new FileReader(file));
32
33     file = new File(basedir, foundFile);
34     foundReader = new BufferedReader(new FileReader(file));
35
36
37     while ((expected = expectedReader.readLine()) != null)
38     {
39       found = foundReader.readLine();
40       if (found == null)
41       {
42         System.err.println("Found less content than expected!");
43         System.err.println("First missing line: " + expected);
44         return false;
45       }
46
47       expected = expected.trim();
48       found = found.trim();
49       if (!expected.equals(found))
50       {
51         System.err.println("Mismatch!");
52         System.err.println("Expected: " + expected);
53         System.err.println("Found:    " + found);
54         return false;
55       }
56     }
57
58     if ((found = foundReader.readLine()) != null)
59     {
60       System.err.println("Found more content than expected!");
61       System.err.println("Starting with: " + found);
62       return false;
63     }
64
65     return true;
66   }
67 }