-
Notifications
You must be signed in to change notification settings - Fork 397
Expand file tree
/
Copy pathTestComparatorHelper.java
More file actions
72 lines (58 loc) · 2.67 KB
/
TestComparatorHelper.java
File metadata and controls
72 lines (58 loc) · 2.67 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package sqlancer;
import static org.junit.jupiter.api.Assertions.assertThrowsExactly;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.Test;
import sqlancer.h2.H2Options;
import sqlancer.h2.H2Schema;
public class TestComparatorHelper {
// TODO: Implement tests for the other ComparatorHelper methods
// TODO: create test state that not depends on specific database
final SQLGlobalState<H2Options, H2Schema> state = new SQLGlobalState<H2Options, H2Schema>() {
@Override
protected H2Schema readSchema() throws SQLException {
return H2Schema.fromConnection(getConnection(), getDatabaseName());
}
@Override
public MainOptions getOptions() {
return new MainOptions();
}
};
@Test
public void testAssumeResultSetsAreEqualWithEqualSets() {
List<String> r1 = Arrays.asList("a", "b", "c");
List<String> r2 = Arrays.asList("a", "b", "c");
ComparatorHelper.assumeResultSetsAreEqual(r1, r2, "", Arrays.asList(""), state);
}
@Test
public void testAssumeResultSetsAreEqualWithUnequalLengthSets() {
List<String> r1 = Arrays.asList("a", "b", "c");
List<String> r2 = Arrays.asList("a", "b", "c", "d", "g");
// NullPointerException is raised instead of AssertionError because state is null and the state.getState()...
// line occurs before AssertionError is thrown, but it's good enough as an indicator that one of the Exceptions
// is raised
assertThrowsExactly(NullPointerException.class, () -> {
ComparatorHelper.assumeResultSetsAreEqual(r1, r2, "", Arrays.asList(""), state);
});
}
@Test
public void testAssumeResultSetsAreEqualWithUnequalValueSets() {
List<String> r1 = Arrays.asList("a", "b", "c");
List<String> r2 = Arrays.asList("a", "b", "d");
// NullPointerException is raised instead of AssertionError because state is null and the state.getState()...
// line occurs before AssertionError is thrown, but it's good enough as an indicator that one of the Exceptions
// is raised
assertThrowsExactly(NullPointerException.class, () -> {
ComparatorHelper.assumeResultSetsAreEqual(r1, r2, "", Arrays.asList(""), state);
});
}
@Test
public void testAssumeResultSetsAreEqualWithCanonicalizationRule() {
List<String> r1 = Arrays.asList("a", "b", "c");
List<String> r2 = Arrays.asList("a", "b", "d");
ComparatorHelper.assumeResultSetsAreEqual(r1, r2, "", Arrays.asList(""), state, (String s) -> {
return s.equals("d") ? "c" : s;
});
}
}