package be.nikiroo.utils.test;
+import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
addTest(new TestCase("Justifying") {
@Override
public void test() throws Exception {
- for (String data : new String[] {}) {
- // TODO: test it!
- // String result = StringUtils.justifyText(data, 5,
- // StringUtils.Alignment.LEFT);
+ Map<String, Map<Integer, Entry<Alignment, List<String>>>> source = new HashMap<String, Map<Integer, Entry<Alignment, List<String>>>>();
+ addValue(source, Alignment.LEFT, "testy", -1, "testy");
+ addValue(source, Alignment.RIGHT, "testy", -1, "testy");
+ addValue(source, Alignment.CENTER, "testy", -1, "testy");
+ addValue(source, Alignment.JUSTIFY, "testy", -1, "testy");
+ addValue(source, Alignment.LEFT, "testy", 5, "testy");
+ addValue(source, Alignment.LEFT, "testy", 3, "te-", "sty");
+ addValue(source, Alignment.LEFT,
+ "Un petit texte qui se mettra sur plusieurs lignes",
+ 10, "Un petit", "texte qui", "se mettra", "sur",
+ "plusieurs", "lignes");
+ addValue(source, Alignment.LEFT,
+ "Un petit texte qui se mettra sur plusieurs lignes", 7,
+ "Un", "petit", "texte", "qui se", "mettra", "sur",
+ "plusie-", "urs", "lignes");
+ addValue(source, Alignment.RIGHT,
+ "Un petit texte qui se mettra sur plusieurs lignes", 7,
+ " Un", " petit", " texte", " qui se", " mettra",
+ " sur", "plusie-", " urs", " lignes");
+ addValue(source, Alignment.CENTER,
+ "Un petit texte qui se mettra sur plusieurs lignes", 7,
+ " Un ", " petit ", " texte ", "qui se ", "mettra ",
+ " sur ", "plusie-", " urs ", "lignes ");
+ addValue(source, Alignment.JUSTIFY,
+ "Un petit texte qui se mettra sur plusieurs lignes", 7,
+ "Un pet-", "it tex-", "te qui", "se met-", "tra sur",
+ "plusie-", "urs li-", "gnes");
+ addValue(source, Alignment.JUSTIFY,
+ "Un petit texte qui se mettra sur plusieurs lignes",
+ 14, "Un petit", "texte qui se",
+ "mettra sur", "plusieurs lig-", "nes");
+ addValue(source, Alignment.JUSTIFY, "le dash-test", 9,
+ "le dash-", "test");
+
+ for (String data : source.keySet()) {
+ for (int size : source.get(data).keySet()) {
+ Alignment align = source.get(data).get(size).getKey();
+ List<String> values = source.get(data).get(size)
+ .getValue();
+
+ List<String> result = StringUtils.justifyText(data,
+ size, align);
+
+ // System.out.println("[" + data + " (" + size + ")" +
+ // "] -> [");
+ // for (int i = 0; i < result.size(); i++) {
+ // String resultLine = result.get(i);
+ // System.out.println(i + ": " + resultLine);
+ // }
+ // System.out.println("]");
+
+ assertEquals(values, result);
+ }
}
}
});
}
});
}
+
+ static private void addValue(
+ Map<String, Map<Integer, Entry<Alignment, List<String>>>> source,
+ final Alignment align, String input, int size,
+ final String... result) {
+ if (!source.containsKey(input)) {
+ source.put(input,
+ new HashMap<Integer, Entry<Alignment, List<String>>>());
+ }
+
+ source.get(input).put(size, new Entry<Alignment, List<String>>() {
+ @Override
+ public Alignment getKey() {
+ return align;
+ }
+
+ @Override
+ public List<String> getValue() {
+ return Arrays.asList(result);
+ }
+
+ @Override
+ public List<String> setValue(List<String> value) {
+ return null;
+ }
+ });
+ }
}