@Test
public void testLanguageIndentifier() {
try {
long total = 0;
LanguageIdentifier identifier;
BufferedReader in = new BufferedReader(new InputStreamReader(this
.getClass().getResourceAsStream("test-referencial.txt")));
String line = null;
while ((line = in.readLine()) != null) {
String[] tokens = line.split(";");
if (!tokens[0].equals("")) {
StringBuilder content = new StringBuilder();
// Test each line of the file...
BufferedReader testFile = new BufferedReader(new InputStreamReader(
this.getClass().getResourceAsStream(tokens[0]), "UTF-8"));
String testLine = null, lang = null;
while ((testLine = testFile.readLine()) != null) {
content.append(testLine + "\n");
testLine = testLine.trim();
if (testLine.length() > 256) {
identifier = new LanguageIdentifier(testLine);
lang = identifier.getLanguage();
Assert.assertEquals(tokens[1], lang);
}
}
testFile.close();
// Test the whole file
long start = System.currentTimeMillis();
System.out.println(content.toString());
identifier = new LanguageIdentifier(content.toString());
lang = identifier.getLanguage();
System.out.println(lang);
total += System.currentTimeMillis() - start;
Assert.assertEquals(tokens[1], lang);
}
}