@Test public void getCommand6() throws Exception { Command command = commandFactory.getCommand("B 1 3 o"); Assert.assertThat(command, CoreMatchers.instanceOf(BucketFillCommand.class)); }
public Command getCommand(String commandLine) throws InvalidCommandException, InvalidCommandParams { commandLine = commandLine.trim().replaceAll(" {2}", " "); String[] split = commandLine.split(" "); String mainCommand = split[0].toUpperCase(); String[] params = Arrays.copyOfRange(split, 1, split.length); switch (mainCommand) { case "Q": return new QuitCommand(); case "C": return new CreateCommand(params); case "L": return new DrawLineCommand(params); case "R": return new DrawRectangleCommand(params); case "B": return new BucketFillCommand(params); default: throw new InvalidCommandException(); } }
CommandFactory { public Command getCommand(String commandLine) throws InvalidCommandException, InvalidCommandParams { commandLine = commandLine.trim().replaceAll(" {2}", " "); String[] split = commandLine.split(" "); String mainCommand = split[0].toUpperCase(); String[] params = Arrays.copyOfRange(split, 1, split.length); switch (mainCommand) { case "Q": return new QuitCommand(); case "C": return new CreateCommand(params); case "L": return new DrawLineCommand(params); case "R": return new DrawRectangleCommand(params); case "B": return new BucketFillCommand(params); default: throw new InvalidCommandException(); } } }
CommandFactory { public Command getCommand(String commandLine) throws InvalidCommandException, InvalidCommandParams { commandLine = commandLine.trim().replaceAll(" {2}", " "); String[] split = commandLine.split(" "); String mainCommand = split[0].toUpperCase(); String[] params = Arrays.copyOfRange(split, 1, split.length); switch (mainCommand) { case "Q": return new QuitCommand(); case "C": return new CreateCommand(params); case "L": return new DrawLineCommand(params); case "R": return new DrawRectangleCommand(params); case "B": return new BucketFillCommand(params); default: throw new InvalidCommandException(); } }  }
CommandFactory { public Command getCommand(String commandLine) throws InvalidCommandException, InvalidCommandParams { commandLine = commandLine.trim().replaceAll(" {2}", " "); String[] split = commandLine.split(" "); String mainCommand = split[0].toUpperCase(); String[] params = Arrays.copyOfRange(split, 1, split.length); switch (mainCommand) { case "Q": return new QuitCommand(); case "C": return new CreateCommand(params); case "L": return new DrawLineCommand(params); case "R": return new DrawRectangleCommand(params); case "B": return new BucketFillCommand(params); default: throw new InvalidCommandException(); } }  Command getCommand(String commandLine); }
CommandFactory { public Command getCommand(String commandLine) throws InvalidCommandException, InvalidCommandParams { commandLine = commandLine.trim().replaceAll(" {2}", " "); String[] split = commandLine.split(" "); String mainCommand = split[0].toUpperCase(); String[] params = Arrays.copyOfRange(split, 1, split.length); switch (mainCommand) { case "Q": return new QuitCommand(); case "C": return new CreateCommand(params); case "L": return new DrawLineCommand(params); case "R": return new DrawRectangleCommand(params); case "B": return new BucketFillCommand(params); default: throw new InvalidCommandException(); } }  Command getCommand(String commandLine);  }