1 | package org.expeditee.gui;
|
---|
2 |
|
---|
3 | import java.awt.Color;
|
---|
4 |
|
---|
5 | import junit.framework.TestCase;
|
---|
6 |
|
---|
7 | import org.expeditee.items.Text;
|
---|
8 |
|
---|
9 | public class AttributeUtilsTest extends TestCase {
|
---|
10 |
|
---|
11 | public final void testExtractAttributes() {
|
---|
12 | assertEquals(null, AttributeUtils.extractAttributes(null));
|
---|
13 | }
|
---|
14 |
|
---|
15 | public final void testSetAttribute() {
|
---|
16 | Text attributes = new Text(-1, "s:50");
|
---|
17 |
|
---|
18 | assertFalse( AttributeUtils.setAttribute(null,attributes));
|
---|
19 | assertFalse( AttributeUtils.setAttribute(attributes,null));
|
---|
20 |
|
---|
21 | assertTrue( AttributeUtils.setAttribute(attributes, attributes));
|
---|
22 | assertEquals(50, attributes.getSize());
|
---|
23 | attributes.setText("size:25");
|
---|
24 | assertTrue(AttributeUtils.setAttribute(attributes, attributes));
|
---|
25 | assertEquals(25, attributes.getSize());
|
---|
26 |
|
---|
27 | attributes.setText("c:red");
|
---|
28 | assertTrue(AttributeUtils.setAttribute(attributes, attributes));
|
---|
29 | assertEquals(Color.red, attributes.getColor());
|
---|
30 | attributes.setText("color:green");
|
---|
31 | assertTrue(AttributeUtils.setAttribute(attributes, attributes));
|
---|
32 | assertEquals(Color.green, attributes.getColor());
|
---|
33 | }
|
---|
34 |
|
---|
35 | public final void testGetValue() {
|
---|
36 | String[][] data = new String[][] {
|
---|
37 | { "Att:Value1", "Value1" },
|
---|
38 | { " Att : Value2 ", "Value2" },
|
---|
39 | { "@NoValue", "" },
|
---|
40 | { " @NoVaLuE ", "" },
|
---|
41 | { "@Value : : : value3", "value3" },
|
---|
42 | { " ", "" },
|
---|
43 | { "Att: value4 " + (char)Character.LINE_SEPARATOR + "A comment",
|
---|
44 | "value4" } };
|
---|
45 | for (int i = 0; i < data.length; i++) {
|
---|
46 | assertEquals(data[i][1], AttributeUtils.getValue(data[i][0]));
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | public final void testGetAttribute() {
|
---|
51 | String[][] data = new String[][] { { "AtT1: Value1", "AtT1" },
|
---|
52 | { " Att2 : Value2 ", "Att2" }, { "@NoValue", null },
|
---|
53 | { "@Att3 : Value", null }, { "@ Att3: Value", null },
|
---|
54 | { " @Att3: Value ", "@Att3" }, { ": value3", null },
|
---|
55 | { "@1Test: value3", null }, { "@t est: value3", null },
|
---|
56 | { "Att4 : test : value4", "Att4" } };
|
---|
57 | for (int i = 0; i < data.length; i++) {
|
---|
58 | assertEquals(data[i][1], AttributeUtils.getAttribute(data[i][0]));
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public final void testReplaceValue() {
|
---|
63 | String[][] data = new String[][] {
|
---|
64 | { "AtT1: Value1", "NewValue", "AtT1: NewValue" },
|
---|
65 | { " Att2 : Value2 ", "Att2", "Att2: Att2" },
|
---|
66 | { " @NoValue ", " 15", "@NoValue: 15" } };
|
---|
67 | Text test = new Text(-1);
|
---|
68 |
|
---|
69 | for (int i = 0; i < data.length; i++) {
|
---|
70 | test.setText(data[i][0]);
|
---|
71 | AttributeUtils.replaceValue(test, data[i][1]);
|
---|
72 | assertEquals(data[i][2], test.getText());
|
---|
73 | }
|
---|
74 | }
|
---|
75 |
|
---|
76 | public final void testGetDoubleValue() {
|
---|
77 | Object[][] data = new Object[][] { { "AtT1: Value1", null },
|
---|
78 | { " Att2 : 3.5 ", 3.5 }, { "@NoValue", null } };
|
---|
79 | for (int i = 0; i < data.length; i++) {
|
---|
80 | assertEquals(data[i][1], AttributeUtils.getDoubleValue(data[i][0]
|
---|
81 | .toString()));
|
---|
82 | }
|
---|
83 | }
|
---|
84 |
|
---|
85 | }
|
---|