source: TraumaOntologies/src/test/java/tudelft/healthpsychology/traumaontologies/CsvTranslationFilesTest.java@ 5

Last change on this file since 5 was 4, checked in by Bart Vastenhouw, 5 years ago

Added traumaontologies

File size: 2.2 KB
Line 
1package tudelft.healthpsychology.traumaontologies;
2
3import static org.junit.Assert.assertTrue;
4
5import java.io.IOException;
6import java.io.InputStream;
7import java.util.HashSet;
8import java.util.Map;
9import java.util.Set;
10
11import org.junit.Test;
12import org.junit.runner.RunWith;
13import org.junit.runners.Parameterized;
14import org.junit.runners.Parameterized.Parameter;
15import org.junit.runners.Parameterized.Parameters;
16
17import tudelft.utilities.translator.BasicCsvTranslator;
18
19/**
20 * Check csv translation files
21 *
22 * @author wouter
23 *
24 */
25@RunWith(Parameterized.class)
26public class CsvTranslationFilesTest {
27
28 private final static String[] csvFiles = new String[] { "NL.csv",
29 "EN.csv" };
30
31 @Parameters
32 public static Object[] data() {
33 return csvFiles;
34 }
35
36 @Parameter
37 public String csvFile;
38
39 /**
40 * Test that all csv files have the same keys (the original language
41 * sentences)
42 *
43 * @throws IOException
44 */
45 @Test
46 public void testSameKeys() throws IOException {
47 System.out.println("testing file " + csvFile);
48
49 MyTranslator tested = new MyTranslator(
50 getClass().getResourceAsStream("/" + csvFile));
51
52 MyTranslator baseline = new MyTranslator(
53 getClass().getResourceAsStream("/" + csvFiles[0]));
54
55 checkMissing(tested.getMap().keySet(), baseline.getMap().keySet(),
56 "There are keys missing in " + csvFile);
57 checkMissing(baseline.getMap().keySet(), tested.getMap().keySet(),
58 "There are keys extra in " + csvFile);
59
60 }
61
62 /**
63 * Check if values are missing in testset that are in baselineset.
64 *
65 * @param testset the set to check
66 * @param baselineset the baseline of must-have values
67 * @param message error message if there are values
68 */
69 private void checkMissing(Set<String> testkeys, Set<String> baselinekeys,
70 String message) {
71 Set<String> remaining = new HashSet<String>(baselinekeys);
72 remaining.removeAll(testkeys);
73 assertTrue(message + ":" + remaining, remaining.isEmpty());
74 }
75
76}
77
78/**
79 * Extend to access map for direct testing of map contents.
80 *
81 */
82class MyTranslator extends BasicCsvTranslator {
83 public MyTranslator(InputStream csvResource) throws IOException {
84 super(csvResource);
85 }
86
87 public Map<String, String> getMap() {
88 return map;
89 }
90}
Note: See TracBrowser for help on using the repository browser.