Changeset 234 for trunk/tests


Ignore:
Timestamp:
08/19/08 14:11:51 (16 years ago)
Author:
ra33
Message:
 
File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/tests/org/expeditee/gui/AttributeValuePairTest.java

    r227 r234  
    77import org.expeditee.items.Text;
    88
    9 public class AttributeUtilsTest extends TestCase {
     9public class AttributeValuePairTest extends TestCase {
    1010
    1111        public final void testExtractAttributes() {
     
    1414
    1515        public final void testSetAttribute() {
    16                 Text attributes = new Text("s:50");
    17                
    18                 assertFalse( AttributeUtils.setAttribute(null,attributes));
    19                 assertFalse( AttributeUtils.setAttribute(attributes,null));
    20                
    21                 assertTrue( AttributeUtils.setAttribute(attributes, attributes));
     16                Text attributes = new Text("");
     17                Text text = new Text("Test");
     18
     19                assertFalse(AttributeUtils.setAttribute(text, attributes));
     20
     21                // Do a test with no attribute value pairs
     22                attributes.setText("NO_AVP");
     23                assertFalse(AttributeUtils.setAttribute(text, attributes));
     24
     25                assertFalse(AttributeUtils.setAttribute(null, attributes));
     26                assertFalse(AttributeUtils.setAttribute(attributes, null));
     27
     28                attributes.setText("s:50");
     29                assertTrue(AttributeUtils.setAttribute(attributes, attributes));
    2230                assertEquals(50.0F, attributes.getSize());
    2331                attributes.setText("size:25");
    2432                assertTrue(AttributeUtils.setAttribute(attributes, attributes));
    2533                assertEquals(25.0F, attributes.getSize());
    26                
     34
    2735                attributes.setText("c:red");
    2836                assertTrue(AttributeUtils.setAttribute(attributes, attributes));
     
    3947                                { "@NoValue", "" },
    4048                                { " @NoVaLuE ", "" },
    41                                 { "@Value   : : : value3", "value3" },
     49                                { "@Value   : : : value3", "" },
     50                                { "@Value:  value3", "value3" },
    4251                                { "   ", "" },
    43                                 { "Att: value4 " + (char)Character.LINE_SEPARATOR + "A comment",
    44                                                 "value4" } };
     52                                {
     53                                                "Att: value4 " + (char) Character.LINE_SEPARATOR
     54                                                                + "A comment", "value4" } };
    4555                for (int i = 0; i < data.length; i++) {
    46                         assertEquals(data[i][1], AttributeUtils.getValue(data[i][0]));
     56                        AttributeValuePair avp = new AttributeValuePair(data[i][0]);
     57                        assertEquals(data[i][1], avp.getValue());
    4758                }
    4859        }
     
    5061        public final void testGetAttribute() {
    5162                String[][] data = new String[][] { { "AtT1: Value1", "AtT1" },
    52                                 { "  Att2  :  Value2  ", "Att2" }, { "@NoValue", "@NoValue" },
     63                                { "  Att2  :  Value2  ", "Att2" }, { "@NoValue", "NoValue" },
    5364                                { "@Att3 : Value", null }, { "@ Att3: Value", null },
    5465                                { " @Att3: Value ", "@Att3" }, { ": value3", null },
    5566                                { "@1Test: value3", null }, { "@t est: value3", null },
    56                                 { "Att4 : test : value4", "Att4" },{ "@", null },{ "a", null }, { "*!*", null } };
     67                                { "Att4 : test : value4", "Att4 : test" }, { "@", null },
     68                                { "a", null }, { "*!*", null }, { "*!*: @%@", "*!*" } };
    5769                for (int i = 0; i < data.length; i++) {
    58                         assertEquals(data[i][1], AttributeUtils.getAttribute(data[i][0]));
     70                        // System.out.println("i = " + i);
     71                        AttributeValuePair avp = new AttributeValuePair(data[i][0]);
     72                        assertEquals(data[i][1], avp.getAttribute());
    5973                }
    6074        }
     
    6478                                { "AtT1: Value1", "NewValue", "AtT1: NewValue" },
    6579                                { "  Att2  :  Value2  ", "Att2", "Att2: Att2" },
    66                                 { " @NoValue ", " 15", "@NoValue:  15" } };
     80                                { " @NoValue ", " 15", "@NoValue: 15" },
     81                                { " 54 ", " 15", "54: 15" } };
    6782                Text test = new Text(-1);
    6883
     
    7590
    7691        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()));
     92                Object[][] validData = new Object[][] { { "  Att2  :  3.5  ", 3.5 } };
     93                for (int i = 0; i < validData.length; i++) {
     94                        AttributeValuePair avp = new AttributeValuePair(validData[i][0]
     95                                        .toString());
     96                        assertEquals(validData[i][1], avp.getDoubleValue());
     97                }
     98                Object[][] invalidData = new Object[][] { { "AtT1: Value1", null },
     99                                { "@NoValue", null } };
     100                for (int i = 0; i < invalidData.length; i++) {
     101                        try {
     102                                AttributeValuePair avp = new AttributeValuePair(
     103                                                invalidData[i][0].toString());
     104                                avp.getDoubleValue();
     105                        } catch (Exception e) {
     106                                continue;
     107                        }
     108                        fail();
    82109                }
    83110        }
Note: See TracChangeset for help on using the changeset viewer.