RemovePropertyCommand implements DynamicCommand { @Override public void execute(final ConsoleReader reader, final PrintWriter out, final ConsoleState state) { Assertions.checkNotNull("reader", reader); Assertions.checkNotNull("out", out); Assertions.checkNotNull("state", state); if (!accept(state)) { return; } final String propertyName = state.getInput().substring(16).trim(); state.removesAdditionalProperty(propertyName); out.print(propertyName); out.println(" property removed."); out.flush(); state.setInput(null); state.clearBuffer(); }  @Override boolean accept(final ConsoleState state); @Override void execute(final ConsoleReader reader,
                         final PrintWriter out,
                         final ConsoleState state); @Override String getAutoCompleteCommand(); @Override String getCommand(); @Override String getDescription(); @Override String getFileCompletionCommand(); @Override FileCompletionMode getFileCompletionMode(); @Override boolean hasFileCompletion();  }
@Test(expected = IllegalArgumentException.class) public void testExecuteNull() { command.execute(null, null, null); }
@Test public void testValidParameter() { final ConsoleState state = new ConsoleState(null); state.setInput("remove property ?"); state.addAdditionalProperty("?"); assertThat(state.getAdditionalProperties().size(), is(1)); assertThat(state.getAdditionalProperties().contains("?"), is(true)); state.appendBuffer("something"); command.execute(reader, out, state); assertThat(state.getBuffer().length(), is(0)); assertThat(state.getAdditionalProperties().size(), is(0)); assertThat(state.getAdditionalProperties().contains("?"), is(false)); assertThat(state.getInput(), is("")); }
@Test public void testValidParameter2() { final ConsoleState state = new ConsoleState(null); state.addAdditionalProperty("myProperty"); state.addAdditionalProperty("myProperty2"); assertThat(state.getAdditionalProperties().contains("myProperty"), is(true)); assertThat(state.getAdditionalProperties().contains("myProperty2"), is(true)); state.setInput("remove property myProperty"); state.appendBuffer("something"); command.execute(reader, out, state); assertThat(state.getAdditionalProperties().size(), is(1)); assertThat(state.getAdditionalProperties().contains("myProperty"), is(false)); assertThat(state.getAdditionalProperties().contains("myProperty2"), is(true)); assertThat(state.getInput(), is("")); state.appendBuffer("something"); state.setInput("remove property myProperty2"); command.execute(reader, out, state); assertThat(state.getBuffer().length(), is(0)); assertThat(state.getAdditionalProperties().size(), is(0)); assertThat(state.getAdditionalProperties().contains("myProperty"), is(false)); assertThat(state.getAdditionalProperties().contains("myProperty2"), is(false)); assertThat(state.getInput(), is("")); }