📄 testfilterlist.java
字号:
package org.jdom.test.cases;
/*--
Copyright (C) 2000 Brett McLaughlin & Jason Hunter.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the disclaimer that follows
these conditions in the documentation and/or other materials
provided with the distribution.
3. The name "JDOM" must not be used to endorse or promote products
derived from this software without prior written permission. For
written permission, please contact license@jdom.org.
4. Products derived from this software may not be called "JDOM", nor
may "JDOM" appear in their name, without prior written permission
from the JDOM Project Management (pm@jdom.org).
In addition, we request (but do not require) that you include in the
end-user documentation provided with the redistribution and/or in the
software itself an acknowledgement equivalent to the following:
"This product includes software developed by the
JDOM Project (http://www.jdom.org/)."
Alternatively, the acknowledgment may be graphical using the logos
available at http://www.jdom.org/images/logos.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE JDOM AUTHORS OR THE PROJECT
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
This software consists of voluntary contributions made by many
individuals on behalf of the JDOM Project and was originally
created by Brett McLaughlin <brett@jdom.org> and
Jason Hunter <jhunter@jdom.org>. For more information on the
JDOM Project, please see <http://www.jdom.org/>.
*/
/**
* Please put a description of your test here.
*
* @author unascribed
* @version 0.1
*/
import junit.framework.*;
import org.jdom.*;
import java.util.*;
public final class TestFilterList
extends junit.framework.TestCase
{
Element foo;
Element bar;
Element baz;
Element quux;
Comment comment;
Comment comment2;
Comment comment3;
Text text1;
Text text2;
Text text3;
Text text4;
/**
* Construct a new instance.
*/
public TestFilterList(String name) {
super(name);
}
/**
* This method is called before a test is executed.
*/
public void setUp() {
foo = new Element("foo");
bar = new Element("bar");
baz = new Element("baz");
quux = new Element("quux");
comment = new Comment("comment");
comment2 = new Comment("comment2");
comment3 = new Comment("comment3");
text1 = new Text("\n");
text2 = new Text("\n");
text3 = new Text("\n");
text4 = new Text("\n");
foo.addContent(text1);
foo.addContent(bar);
foo.addContent(text2);
foo.addContent(baz);
foo.addContent(text3);
foo.addContent(comment);
foo.addContent(quux);
foo.addContent(text4);
// Contents of foo are now:
// \n, bar, \n, baz, \n, comment, quux, \n
}
/**
* This method is called after a test is executed.
*/
public void tearDown() {
// your code goes here.
}
/**
* The suite method runs all the tests
*/
public static Test suite () {
TestSuite suite = new TestSuite(TestFilterList.class);
return suite;
}
/**
* The main method runs all the tests in the text ui
*/
public static void main (String args[])
{
junit.textui.TestRunner.run(suite());
}
public void test_TCM__int_hashCode() {
List content = foo.getContent();
List content2 = new ArrayList();
content2.addAll(content);
assertEquals("bad hashcode", content2.hashCode(), content.hashCode());
}
public void test_TCM__boolean_equals_Object() {
List content = foo.getContent();
List content2 = new ArrayList();
content2.addAll(content);
assertTrue("bad equals", content.equals(content2));
List children = foo.getChildren();
List children2 = foo.getChildren();
assertTrue("bad equals", children.equals(children2));
}
public void test_TCM__int_indexOf_Object() {
List children = foo.getChildren();
assertEquals("wrong result from indexOf", 0, children.indexOf(bar));
assertEquals("wrong result from indexOf", 1, children.indexOf(baz));
assertEquals("wrong result from indexOf", 2, children.indexOf(quux));
assertEquals("wrong result from indexOf", -1, children.indexOf(foo));
assertEquals("wrong result from indexOf", -1, children.indexOf(text1));
List content = foo.getContent();
assertEquals("wrong result from indexOf", 0, content.indexOf(text1));
assertEquals("wrong result from indexOf", 1, content.indexOf(bar));
assertEquals("wrong result from indexOf", 2, content.indexOf(text2));
assertEquals("wrong result from indexOf", 3, content.indexOf(baz));
assertEquals("wrong result from indexOf", 4, content.indexOf(text3));
assertEquals("wrong result from indexOf", 5, content.indexOf(comment));
assertEquals("wrong result from indexOf", 6, content.indexOf(quux));
assertEquals("wrong result from indexOf", 7, content.indexOf(text4));
assertEquals("wrong result from indexOf", -1, content.indexOf(comment2));
assertEquals("wrong result from indexOf", -1, content.indexOf(new Integer(17)));
}
public void test_TCM__int_lastIndexOf_Object() {
List children = foo.getChildren();
assertEquals("wrong result from lastIndexOf", 0, children.lastIndexOf(bar));
assertEquals("wrong result from lastIndexOf", 1, children.lastIndexOf(baz));
assertEquals("wrong result from lastIndexOf", 2, children.lastIndexOf(quux));
assertEquals("wrong result from lastIndexOf", -1, children.lastIndexOf(text3));
assertEquals("wrong result from lastIndexOf", -1, children.lastIndexOf(new Integer(17)));
List content = foo.getContent();
assertEquals("wrong result from lastIndexOf", 0, content.lastIndexOf(text1));
assertEquals("wrong result from lastIndexOf", 1, content.lastIndexOf(bar));
assertEquals("wrong result from lastIndexOf", 2, content.lastIndexOf(text2));
assertEquals("wrong result from lastIndexOf", 3, content.lastIndexOf(baz));
assertEquals("wrong result from lastIndexOf", 4, content.lastIndexOf(text3));
assertEquals("wrong result from lastIndexOf", 5, content.lastIndexOf(comment));
assertEquals("wrong result from lastIndexOf", 6, content.lastIndexOf(quux));
assertEquals("wrong result from lastIndexOf", 7, content.lastIndexOf(text4));
assertEquals("wrong result from lastIndexOf", -1, content.lastIndexOf(comment2));
assertEquals("wrong result from lastIndexOf", -1, content.lastIndexOf(new Integer(17)));
}
public void test_TCM__Object_get_int() {
List children = foo.getChildren();
assertEquals("wrong element from get", bar, children.get(0));
assertEquals("wrong element from get", baz, children.get(1));
assertEquals("wrong element from get", quux, children.get(2));
List content = foo.getContent();
assertEquals("wrong element from get", text1, content.get(0));
assertEquals("wrong element from get", bar, content.get(1));
assertEquals("wrong element from get", text2, content.get(2));
assertEquals("wrong element from get", baz, content.get(3));
assertEquals("wrong element from get", text3, content.get(4));
assertEquals("wrong element from get", comment, content.get(5));
assertEquals("wrong element from get", quux, content.get(6));
assertEquals("wrong element from get", text4, content.get(7));
try {
children.get(48);
fail("Should have thrown an IndexOutOfBoundsException");
} catch(IndexOutOfBoundsException ex) {}
try {
children.get(-3);
fail("Should have thrown an IndexOutOfBoundsException");
} catch(IndexOutOfBoundsException ex) {}
try {
content.get(48);
fail("Should have thrown an IndexOutOfBoundsException");
} catch(IndexOutOfBoundsException ex) {}
try {
content.get(-3);
fail("Should have thrown an IndexOutOfBoundsException");
} catch(IndexOutOfBoundsException ex) {}
}
public void test_TCM__Object_set_int_Object() {
List children = foo.getChildren();
List content = foo.getContent();
Element blah = new Element("blah");
Text text5 = new Text("this was bar");
content.set(1, text5);
children.set(1, blah);
assertTrue("parent is not correct", blah.getParent() == foo);
assertEquals("wrong size", 2, children.size());
assertEquals("wrong element from set", baz, children.get(0));
assertEquals("wrong element from set", blah, children.get(1));
assertEquals("wrong size", 8, content.size());
assertEquals("wrong element from set", text1, content.get(0));
assertEquals("wrong element from set", text5, content.get(1));
assertEquals("wrong element from set", text2, content.get(2));
assertEquals("wrong element from set", baz, content.get(3));
assertEquals("wrong element from set", text3, content.get(4));
assertEquals("wrong element from set", comment, content.get(5));
assertEquals("wrong element from set", blah, content.get(6));
assertEquals("wrong element from set", text4, content.get(7));
try {
children.set(48, new Element("test"));
fail("Should have thrown an IndexOutOfBoundsException");
} catch(IndexOutOfBoundsException ex) {}
try {
children.set(-3, new Element("test"));
fail("Should have thrown an IndexOutOfBoundsException");
} catch(IndexOutOfBoundsException ex) {}
try {
children.set(1, new Comment("test"));
fail("Should have thrown an IllegalArgumentException");
} catch(IllegalArgumentException ex) {}
try {
content.set(48, new Element("test"));
fail("Should have thrown an IndexOutOfBoundsException");
} catch(IndexOutOfBoundsException ex) {}
try {
content.set(-3, new Element("test"));
fail("Should have thrown an IndexOutOfBoundsException");
} catch(IndexOutOfBoundsException ex) {}
try {
content.set(1, new Integer(17));
fail("Should have thrown an IllegalArgumentException");
} catch(IllegalArgumentException ex) {}
}
public void test_TCM__void_add_int_Object() {
List children = foo.getChildren();
List content = foo.getContent();
Element blah = new Element("blah");
Text text5 = new Text("this is before bar");
content.add(1, text5);
children.add(1, blah);
assertTrue("parent is not correct", blah.getParent() == foo);
assertEquals("wrong size", 4, children.size());
assertEquals("wrong element from add", bar, children.get(0));
assertEquals("wrong element from add", blah, children.get(1));
assertEquals("wrong element from add", baz, children.get(2));
assertEquals("wrong element from add", quux, children.get(3));
assertEquals("wrong size", 10, content.size());
assertEquals("wrong element from add", text1, content.get(0));
assertEquals("wrong element from add", text5, content.get(1));
assertEquals("wrong element from add", bar, content.get(2));
assertEquals("wrong element from add", text2, content.get(3));
assertEquals("wrong element from add", blah, content.get(4));
assertEquals("wrong element from add", baz, content.get(5));
assertEquals("wrong element from add", text3, content.get(6));
assertEquals("wrong element from add", comment, content.get(7));
assertEquals("wrong element from add", quux, content.get(8));
assertEquals("wrong element from add", text4, content.get(9));
try {
children.add(48, new Element("test"));
fail("Should have thrown an IndexOutOfBoundsException");
} catch(IndexOutOfBoundsException ex) {}
try {
children.add(-3, new Element("test"));
fail("Should have thrown an IndexOutOfBoundsException");
} catch(IndexOutOfBoundsException ex) {}
try {
children.add(1, new Comment("test"));
fail("Should have thrown an IllegalArgumentException");
} catch(IllegalArgumentException ex) {}
try {
content.add(48, new Element("test"));
fail("Should have thrown an IndexOutOfBoundsException");
} catch(IndexOutOfBoundsException ex) {}
try {
content.add(-3, new Element("test"));
fail("Should have thrown an IndexOutOfBoundsException");
} catch(IndexOutOfBoundsException ex) {}
try {
content.add(1, new Integer(17));
fail("Should have thrown an IllegalArgumentException");
} catch(IllegalArgumentException ex) {}
}
public void test_TCM__boolean_add_Object() {
List children = foo.getChildren();
List content = foo.getContent();
Element blah = new Element("blah");
Text text5 = new Text("this is last");
content.add(text5);
children.add(blah);
assertTrue("parent is not correct", blah.getParent() == foo);
assertEquals("wrong size", 4, children.size());
assertEquals("wrong element from add", bar, children.get(0));
assertEquals("wrong element from add", baz, children.get(1));
assertEquals("wrong element from add", quux, children.get(2));
assertEquals("wrong element from add", blah, children.get(3));
assertEquals("wrong size", 10, content.size());
assertEquals("wrong element from add", text1, content.get(0));
assertEquals("wrong element from add", bar, content.get(1));
assertEquals("wrong element from add", text2, content.get(2));
assertEquals("wrong element from add", baz, content.get(3));
assertEquals("wrong element from add", text3, content.get(4));
assertEquals("wrong element from add", comment, content.get(5));
assertEquals("wrong element from add", quux, content.get(6));
assertEquals("wrong element from add", text4, content.get(7));
assertEquals("wrong element from add", text5, content.get(8));
assertEquals("wrong element from add", blah, content.get(9));
assertTrue("parent is not correct", comment.getParent() == foo);
try {
children.add(new Comment("test"));
fail("Should have thrown an IllegalArgumentException");
} catch(IllegalArgumentException ex) {}
try {
content.add(new Integer(17));
fail("Should have thrown an IllegalArgumentException");
} catch(IllegalArgumentException ex) {}
}
public void testModification() {
List children = foo.getChildren();
List content = foo.getContent();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -