testsleepcommand.java
来自「著名的uncle Bob的Agile software development的」· Java 代码 · 共 36 行
JAVA
36 行
import junit.framework.*;
import junit.swingui.TestRunner;
public class TestSleepCommand extends TestCase
{
public static void main(String[] args)
{
TestRunner.main(new String[]{"TestSleepCommand"});
}
public TestSleepCommand(String name)
{
super(name);
}
private boolean commandExecuted = false;
public void testSleep() throws Exception
{
Command wakeup = new Command()
{
public void execute() {commandExecuted = true;}
};
ActiveObjectEngine e = new ActiveObjectEngine();
SleepCommand c = new SleepCommand(1000,e,wakeup);
e.addCommand(c);
long start = System.currentTimeMillis();
e.run();
long stop = System.currentTimeMillis();
long sleepTime = (stop-start);
assert("SleepTime " + sleepTime + " expected > 1000", sleepTime > 1000);
assert("SleepTime " + sleepTime + " expected < 1100", sleepTime < 1100);
assert("Command Executed", commandExecuted);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?