01: package net.sourceforge.squirrel_sql.fw.gui;
02:
03: import junit.framework.TestCase;
04: import net.sourceforge.squirrel_sql.client.ApplicationManager;
05:
06: public class GUIUtilsTest extends TestCase {
07:
08: static final String LENGTH_10 = "123456789 ";
09: static final String LENGTH_20 = LENGTH_10 + LENGTH_10;
10: static final String LENGTH_40 = LENGTH_20 + LENGTH_20;
11: static final String LENGTH_80 = LENGTH_40 + LENGTH_40;
12: static final String LENGTH_160 = LENGTH_80 + LENGTH_80;
13:
14: public void testGetWrappedLine() {
15: ApplicationManager.initApplication();
16: assertEquality(LENGTH_80, 40, 2, trimLength(LENGTH_40));
17: assertEquality(LENGTH_80, 20, 4, trimLength(LENGTH_20));
18: assertEquality(LENGTH_20, 15, 2, trimLength(LENGTH_10));
19: // Here the max line length == original line size - so it doesn't get
20: // trimmed of white space.
21: assertEquality(LENGTH_20, 40, 1, LENGTH_20.length());
22: assertEquality(LENGTH_160, 80, 2, trimLength(LENGTH_80));
23: assertEquality(LENGTH_10, 5, 1, -1);
24: }
25:
26: // Helpers
27:
28: private void assertEquality(String origLine, int maxLineSize,
29: int expPartsArrayLength, int expPartLenth) {
30: String wrappedLine = GUIUtils.getWrappedLine(origLine,
31: maxLineSize);
32: String[] parts = wrappedLine.split("\\n");
33: assertEquals("number of newlines in word-wrapped string",
34: expPartsArrayLength, parts.length);
35: if (expPartLenth != -1) {
36: for (int i = 0; i < parts.length; i++) {
37: assertEquals("length of parts[" + i + "]",
38: expPartLenth, parts[0].length());
39: }
40: }
41: }
42:
43: private int trimLength(String s) {
44: return s.trim().length();
45: }
46: }
|