package net.yacy.data; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import org.junit.Test; import static org.junit.Assert.*; public class TranslatorTest { /** * Test of translate method, of class Translator. */ @Test public void testTranslate() { // test that translator respects word bondaries ( e.g. key=bug not translate "mybugfix" Translator t = new Translator(); final Map translationTable = new HashMap(); translationTable.put("MIST", "Nebel"); // key upper case just to easy identify it in test strings translationTable.put(">MIST", ">Nebel"); translationTable.put("BY", "bei"); translationTable.put(">BY", ">bei"); translationTable.put("BY<", "bei<"); translationTable.put(">BY<", ">bei<"); // source test text, expected not to be translated Set noChange = new HashSet(); noChange.add("MISTer wong "); noChange.add("make no MISTake"); noChange.add("value=\"MISTake\" "); noChange.add("MISTral"); noChange.add("value=\"#[MISTake]#\" "); noChange.add(" optiMIST "); noChange.add("goodBY."); noChange.add(" BYte"); noChange.add(""); //noChange.add(" BY_BY "); // this translates // source test text, to be translated Set doChange = new HashSet(); doChange.add("Queen of the MIST "); doChange.add("value=\"#[MIST]#\" "); doChange.add("text#[MIST]#text "); doChange.add("MIST in the forrest"); doChange.add("MIST\nin the forrest"); doChange.add(""); String result; for (String stringToExamine : noChange) { StringBuilder source = new StringBuilder(stringToExamine); result = t.translate(source, translationTable); assertEquals(result, stringToExamine); } for (String stringToExamine : doChange) { StringBuilder source = new StringBuilder(stringToExamine); result = t.translate(source, translationTable); assertNotEquals(result, stringToExamine); } } }