public static void main(String[] args) { SimpleRemoteControl remote = new SimpleRemoteControl(); Light light = new Light(); LightOnCommand lightOn = new LightOnCommand(light); LightOffCommand lightOff = new LightOffCommand(light); GarageDoor garageDoor = new GarageDoor(light); GarageDoorOpenCommand doorUp = new GarageDoorOpenCommand(garageDoor); remote.setCommand(lightOn); remote.buttonPressed(); remote.setCommand(lightOff); remote.buttonPressed(); remote.setCommand(doorUp); remote.buttonPressed(); RemoteControl complexRemote = new RemoteControl(); Stereo stereo = new Stereo(); CD cd = new CD("Sgt. PepperÕs Lonely Hearts Club Band"); StereoOnWithCDCommand stereoOn = new StereoOnWithCDCommand(stereo, cd); StereoOffWithCDCommand stereoOff = new StereoOffWithCDCommand(stereo, cd); complexRemote.setCommand(0, lightOn, lightOff); complexRemote.setCommand(1, stereoOn, stereoOff); System.out.println(complexRemote); complexRemote.onButtonWasPushed(0); complexRemote.onButtonWasPushed(1); complexRemote.offButtonWasPushed(0); CeilingFan ceilingFan = new CeilingFan("Living Room"); CeilingFanMediumCommand ceilingFanMedium = new CeilingFanMediumCommand(ceilingFan); CeilingFanLowCommand ceilingFanLow = new CeilingFanLowCommand(ceilingFan); CeilingFanHighCommand ceilingFanHigh = new CeilingFanHighCommand(ceilingFan); CeilingFanOffCommand ceilingFanOff = new CeilingFanOffCommand(ceilingFan); complexRemote.setCommand(0, ceilingFanMedium, ceilingFanOff); complexRemote.setCommand(1, ceilingFanHigh, ceilingFanOff); complexRemote.setCommand(2, ceilingFanLow, ceilingFanOff); complexRemote.onButtonWasPushed(0); complexRemote.offButtonWasPushed(0); System.out.println(complexRemote); complexRemote.undoButtonWasPushed(); }
@Test public void testMacroCommands() { Light light = new Light("Living Room"); Stereo stereo = new Stereo("Livin Room"); LightOnCommand lightOnCommand = new LightOnCommand(light); StereoOnWithCDCommand stereoOnWithCDCommand = new StereoOnWithCDCommand(stereo); LightOffCommand lightOffCommand = new LightOffCommand(light); StereoOffCommand stereoOffCommand = new StereoOffCommand(stereo); Command[] partyOn = {lightOnCommand, stereoOnWithCDCommand}; Command[] partyOff = {lightOffCommand, stereoOffCommand}; MacroCommand partyOnMacro = new MacroCommand(partyOn); MacroCommand partyOffMacro = new MacroCommand(partyOff); RemoteControl remoteControl = new RemoteControl(); remoteControl.setCommand(0, partyOnMacro, partyOffMacro); System.out.println(remoteControl); System.out.println("-----Pushing macro on-----"); remoteControl.onButtonWasPushed(0); System.out.println("-----Pushing macro off-----"); remoteControl.offButtonWasPushed(0); }