blob: 70a11ff530fd84e8fd2299e0bcdbd86ac38044c5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vdslib.distribution;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
/**
* Helper class to implement unit tests that should produce the same result in different implementations.
*/
public abstract class CrossPlatformTestFactory {
private final String directory;
private final String name;
public CrossPlatformTestFactory(String directory, String name) {
this.directory = directory;
this.name = name;
}
public String getName() { return name; }
public boolean loadTestResults() throws Exception {
File reference = new File(directory, name + ".reference.results");
if (!reference.exists()) {
return false;
}
BufferedReader br = new BufferedReader(new FileReader(reference));
StringBuilder sb = new StringBuilder();
try{
while(true) {
String line = br.readLine();
if (line == null) break;
sb.append(line);
}
parse(sb.toString());
} finally {
br.close();
}
return true;
}
public void recordTestResults() throws Exception {
File results = new File(directory, name + ".java.results");
FileWriter fw = new FileWriter(results);
try{
fw.write(serialize());
} finally {
fw.close();
}
}
public abstract String serialize() throws Exception;
public abstract void parse(String serialized) throws Exception;
}
|