package tudelft.healthpsychology.traumaontologies; import static org.junit.Assert.assertTrue; import java.io.IOException; import java.io.InputStream; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; import tudelft.utilities.translator.BasicCsvTranslator; /** * Check csv translation files * * @author wouter * */ @RunWith(Parameterized.class) public class CsvTranslationFilesTest { private final static String[] csvFiles = new String[] { "NL.csv", "EN.csv" }; @Parameters public static Object[] data() { return csvFiles; } @Parameter public String csvFile; /** * Test that all csv files have the same keys (the original language * sentences) * * @throws IOException */ @Test public void testSameKeys() throws IOException { System.out.println("testing file " + csvFile); MyTranslator tested = new MyTranslator( getClass().getResourceAsStream("/" + csvFile)); MyTranslator baseline = new MyTranslator( getClass().getResourceAsStream("/" + csvFiles[0])); checkMissing(tested.getMap().keySet(), baseline.getMap().keySet(), "There are keys missing in " + csvFile); checkMissing(baseline.getMap().keySet(), tested.getMap().keySet(), "There are keys extra in " + csvFile); } /** * Check if values are missing in testset that are in baselineset. * * @param testset the set to check * @param baselineset the baseline of must-have values * @param message error message if there are values */ private void checkMissing(Set testkeys, Set baselinekeys, String message) { Set remaining = new HashSet(baselinekeys); remaining.removeAll(testkeys); assertTrue(message + ":" + remaining, remaining.isEmpty()); } } /** * Extend to access map for direct testing of map contents. * */ class MyTranslator extends BasicCsvTranslator { public MyTranslator(InputStream csvResource) throws IOException { super(csvResource); } public Map getMap() { return map; } }