001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Evgeniya G. Maenkova
019: * @version $Revision$
020: */package javax.swing.text.html.parser;
021:
022: import java.util.Vector;
023: import junit.framework.TestCase;
024:
025: public class AttributeListTest extends TestCase {
026: AttributeList attrList;
027: String name = "first";
028: int type = 26;
029: int modifier = 16;
030: String value = "value";
031: Vector values = new Vector();
032: AttributeList next = new AttributeList("second");
033:
034: protected void setUp() throws Exception {
035: super .setUp();
036: attrList = new AttributeList(name, type, modifier, value,
037: values, next);
038: }
039:
040: protected void tearDown() throws Exception {
041: super .tearDown();
042: }
043:
044: public void testAttributeListConstr1() {
045: Utils.checkAttributeList(attrList, modifier, type, name, next,
046: values, value, true);
047: }
048:
049: public void testAttributeListConstr2() {
050: assertEquals(0, next.modifier);
051: assertEquals("second", next.name);
052: assertNull(next.next);
053: assertEquals(0, next.type);
054: assertNull(next.value);
055: assertNull(next.values);
056:
057: AttributeList attributeList = new AttributeList(null);
058: assertNull(attributeList.name);
059:
060: attributeList = new AttributeList("AAA");
061: assertEquals("AAA", attributeList.name);
062: }
063:
064: public void testGetNext() {
065: assertEquals(next, attrList.getNext());
066: }
067:
068: public void testGetValue() {
069: assertEquals(value, attrList.getValue());
070: }
071:
072: public void testGetValues() {
073: assertEquals(values.elements().getClass(), attrList.getValues()
074: .getClass());
075: }
076:
077: public void testGetModifier() {
078: assertEquals(modifier, attrList.getModifier());
079: }
080:
081: public void testGetType() {
082: assertEquals(type, attrList.getType());
083: }
084:
085: public void testGetName() {
086: assertEquals(name, attrList.getName());
087: }
088:
089: String[] names = new String[] { null, "CDATA", "ENTITY",
090: "ENTITIES", "ID", "IDREF", "IDREFS", "NAME", "NAMES",
091: "NMTOKEN", "NMTOKENS", "NOTATION", "NUMBER", "NUMBERS",
092: "NUTOKEN", "NUTOKENS" };
093:
094: public void testType2name() {
095: for (int i = 0; i < 300; i++) {
096: assertEquals(i < 16 ? names[i] : null, AttributeList
097: .type2name(i));
098: }
099: }
100:
101: public void testName2type() {
102: for (int i = 0; i < 300; i++) {
103: if (i > 0 && i < 16) {
104: assertEquals(1, AttributeList.name2type(names[i]
105: .toLowerCase()));
106: assertEquals(i, AttributeList.name2type(names[i]));
107: } else {
108: try {
109: assertEquals(1, AttributeList.name2type(null));
110: assertFalse("NPE not thrown", true);
111: } catch (NullPointerException e) {
112: }
113: }
114: }
115: assertEquals(1, AttributeList.name2type("test"));
116: }
117:
118: public void testSerialization() {
119: AttributeList attributeList = (AttributeList) Utils
120: .doSerialization(attrList);
121: Utils.checkAttributeList(attributeList, modifier, type, name,
122: next, values, value, false);
123: }
124: }
|