piynamertest.java
字号:
//---------------------------
// This should be moved later
//---------------------------
package piy;
import junit.framework.*;
/**
* Checks various apsects of the PIYNamer class.
* Note: because most of the PIYNamer methods are protected, this test class needs
* to be in the same package as it.
* @author David Vivash
* @version 1.1, 22/11/00
*/
public class PIYNamerTest extends TestCase
{
private PIYNamer empty, full;
private UserWindow test1 = new UserWindow();
private UserWindow test2 = new UserWindow();
private UserWindow test3 = new UserWindow();
public PIYNamerTest(String name) {
super(name);
}
public static Test suite() {
return new TestSuite(PIYNamerTest.class);
}
public void setUp() {
empty = new PIYNamer(3);
full = new PIYNamer(3);
full.add(test1, "Window"); //name = Window1
full.add(test2, "Window"); //name = Window2
full.add(test3, "Window"); //name = Window3
}
/**
* Tests the operations when no components have been named yet
*/
public void testEmptyOperations() {
assert(empty.getNames() != null);
assert(empty.getNames().length == 0);
assert(empty.nameIsUnique("anything"));
assert(!empty.nameIsUnique(null)); //we don't allow null as a value name
assert(!empty.nameIsUnique("")); //we don't allow "" as a value name
assert(empty.getUniqueName("Window").equals("Window1"));
}
public void testAddAndGet() {
UserWindow test = new UserWindow();
assert(empty.add(test, "Window").equals("Window1"));
assert(empty.getValue("Window1") == test);
assert(empty.getValue("Window2") == null);
assert(empty.getName(test).equals("Window1"));
assert(empty.getName(new UserWindow()) == null);
assert(full.add(new UserWindow(), "Window").equals("Window4"));
}
public void testRename() {
assert(!full.renameValue("Window1", "Window2")); //can't rename to an existing name
assert(full.renameValue("Window1", "Window1")); //this should be allowed
assert(full.renameValue("Window1", "Window4"));
assert(full.getName(test1).equals("Window4")); //test1 successfully renamed
assert(full.getName(test2).equals("Window2")); //test2 untouched
assert(full.getValue("Window4") == test1);
assert(full.getValue("Window1") == null);
assert(full.renameValue("anything", "anythingelse") == false);
}
public void testSize() {
try{
new PIYNamer(0);
new PIYNamer(-1);
} catch (Exception e) {
fail("Constructor failed to initialise");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -