|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
GoldMasterFile.java | 0% | 0% | 0% | 0% |
|
1 |
package com.diasparsoftware.util.junit;
|
|
2 |
|
|
3 |
import java.io.*;
|
|
4 |
|
|
5 |
import junit.framework.Assert;
|
|
6 |
|
|
7 |
/**
|
|
8 |
* Use a gold master file when verifying content that is
|
|
9 |
* not worth parsing.
|
|
10 |
*
|
|
11 |
*/
|
|
12 |
public class GoldMasterFile extends Assert { |
|
13 |
private File file;
|
|
14 |
|
|
15 | 0 |
public GoldMasterFile(String directory, String file) {
|
16 | 0 |
this(new File(directory, file)); |
17 |
} |
|
18 |
|
|
19 | 0 |
public GoldMasterFile(File file) {
|
20 | 0 |
this.file = file;
|
21 |
} |
|
22 |
|
|
23 |
/**
|
|
24 |
* Create gold master content, writing it to file.
|
|
25 |
*
|
|
26 |
* @param content The gold master content
|
|
27 |
* @throws IOException
|
|
28 |
*/
|
|
29 | 0 |
public void write(String content) throws IOException { |
30 | 0 |
file.getParentFile().mkdirs(); |
31 | 0 |
FileWriter goldMasterWriter = new FileWriter(file);
|
32 | 0 |
goldMasterWriter.write(content); |
33 | 0 |
goldMasterWriter.close(); |
34 |
} |
|
35 |
|
|
36 |
/**
|
|
37 |
* Check content against the gold master.
|
|
38 |
*
|
|
39 |
* @param expectedContent
|
|
40 |
* @throws IOException
|
|
41 |
*/
|
|
42 | 0 |
public void check(String actualContent) |
43 |
throws IOException {
|
|
44 |
|
|
45 | 0 |
assertTrue( |
46 |
"Gold master [" + file.getAbsolutePath() + "] not found.", |
|
47 |
file.exists()); |
|
48 |
|
|
49 | 0 |
StringWriter stringWriter = new StringWriter();
|
50 | 0 |
PrintWriter printWriter = new PrintWriter(stringWriter);
|
51 |
|
|
52 | 0 |
BufferedReader goldMasterReader = |
53 |
new BufferedReader(new FileReader(file)); |
|
54 | 0 |
while (true) { |
55 | 0 |
String line = goldMasterReader.readLine(); |
56 | 0 |
if (line == null) |
57 | 0 |
break;
|
58 | 0 |
printWriter.println(line); |
59 |
} |
|
60 |
|
|
61 | 0 |
assertEquals(stringWriter.toString(), actualContent); |
62 |
} |
|
63 |
} |
|
64 |
|
|