Java Reference
In-Depth Information
package com.oozinoz.util;
import junit.framework.*;
public class TestCommand extends TestCase
{
public TestCommand(String name)
{
super(name);
}
public static void main(String[] args)
{
new junit.awtui.TestRunner().start(
new String[] { "com.oozinoz.util.TestCommand" });
}
public void testSleep()
{
Command doze = new Command()
{
public void execute()
{
try
{
Thread.sleep(2000);
}
catch (InterruptedException ignore)
{
}
}
};
long t = /* ? */
assertEquals(2000, t, 50);
}
}
The assertEquals() method checks that the expected value, 2,000, is within 50
milliseconds of the actual value.
CHALLENGE 24.3
Complete the assignment statement that times the execution of the doze command.
Command in Relation to Other Patterns
The C OMMAND pattern has interesting relationships to many other patterns. For example,
C OMMAND provides an alternative to T EMPLATE M ETHOD . Recall the Aster star press code
that let you override the method that marks a mold as incomplete if it is in process when you
shut down the press. The AsterStarPress class is abstract, requiring you to subclass it
with a class that has a markMoldIncomplete() method. The shutdown() method of
AsterStarPress relies on this method to ensure that your domain object knows that the
mold is incomplete:
Search WWH ::




Custom Search