### Question:
AddContextEntryCommand extends AbstractCanvasGraphCommand implements VetoExecutionCommand,
                                                                                  VetoUndoCommand { @Override protected Command<GraphCommandExecutionContext, RuleViolation> newGraphCommand(final AbstractCanvasHandler handler) { return new AbstractGraphCommand() { @Override protected CommandResult<RuleViolation> check(final GraphCommandExecutionContext gce) { return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> execute(final GraphCommandExecutionContext gce) { context.getContextEntry().add(uiRowIndex, contextEntry); final InformationItem informationItem = contextEntry.getVariable(); informationItem.getName().setValue(name); contextEntry.setParent(context); contextEntry.getVariable().setParent(contextEntry); return GraphCommandResultBuilder.SUCCESS; } @Override public CommandResult<RuleViolation> undo(final GraphCommandExecutionContext gce) { context.getContextEntry().remove(contextEntry); return GraphCommandResultBuilder.SUCCESS; } }; } AddContextEntryCommand(final Context context,
                                  final ContextEntry contextEntry,
                                  final GridData uiModel,
                                  final GridRow uiModelRow,
                                  final int uiRowIndex,
                                  final ContextUIModelMapper uiModelMapper,
                                  final org.uberfire.mvp.Command canvasOperation); void updateRowNumbers(); void updateParentInformation();  }### Answer:
@Test public void testGraphCommandAllow() { makeCommand(); final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler); assertEquals(GraphCommandResultBuilder.SUCCESS, c.allow(gce)); }
@Test public void testGraphCommandExecute() { makeCommand(); final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler); assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce)); assertEquals(2, context.getContextEntry().size()); assertEquals(contextEntry, context.getContextEntry().get(0)); assertEquals(ContextEntryDefaultValueUtilities.PREFIX + "1", contextEntry.getVariable().getName().getValue()); assertEquals(defaultResultContextEntry, context.getContextEntry().get(1)); assertEquals(context, contextEntry.getParent()); assertEquals(contextEntry, contextEntry.getVariable().getParent()); }
@Test public void testGraphCommandExecuteMultipleEntriesPresent() { final String EXISTING_ENTRY_NAME = "old one"; final ContextEntry firstEntry = new ContextEntry() {{ setVariable(new InformationItem() {{ setName(new Name(EXISTING_ENTRY_NAME)); }}); }}; context.getContextEntry().add(0, firstEntry); makeCommand(); final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler); assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce)); assertEquals(3, context.getContextEntry().size()); assertEquals(firstEntry, context.getContextEntry().get(0)); assertEquals(EXISTING_ENTRY_NAME, firstEntry.getVariable().getName().getValue()); assertEquals(contextEntry, context.getContextEntry().get(1)); assertEquals(ContextEntryDefaultValueUtilities.PREFIX + "1", contextEntry.getVariable().getName().getValue()); assertEquals(defaultResultContextEntry, context.getContextEntry().get(2)); assertEquals(context, contextEntry.getParent()); assertEquals(contextEntry, contextEntry.getVariable().getParent()); }
@Test public void testGraphCommandUndo() { makeCommand(); final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler); assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce)); assertEquals(GraphCommandResultBuilder.SUCCESS, c.undo(gce)); assertEquals(1, context.getContextEntry().size()); assertEquals(defaultResultContextEntry, context.getContextEntry().get(0)); }
@Test public void testGraphCommandUndoMultipleEntriesPresent() { final ContextEntry firstEntry = new ContextEntry() {{ setVariable(new InformationItem() {{ setName(new Name("old one")); }}); }}; context.getContextEntry().add(0, firstEntry); makeCommand(); final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler); assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce)); assertEquals(GraphCommandResultBuilder.SUCCESS, c.undo(gce)); assertEquals(2, context.getContextEntry().size()); assertEquals(firstEntry, context.getContextEntry().get(0)); assertEquals(defaultResultContextEntry, context.getContextEntry().get(1)); }