### Question:
RedoCommandHandler { @SuppressWarnings("unchecked") public CommandResult<?> execute(final Object context, final CommandManager commandManager) { if (registry.isEmpty()) { return GraphCommandResultBuilder.SUCCESS; } final C last = registry.peek(); return commandManager.execute(context, last); } protected  RedoCommandHandler(); @Inject  RedoCommandHandler(final DefaultRegistry<C> registry, final Event<RegisterChangedEvent> registerChangedEvent); boolean onUndoCommandExecuted(final C command); boolean onCommandExecuted(final C command); @SuppressWarnings("unchecked") CommandResult<?> execute(final Object context,
                                    final CommandManager commandManager); void setSession(final ClientSession clientSession); boolean isEnabled(); void clear();  }### Answer:
@Test @SuppressWarnings("unchecked") public void testExecute() { Object obj = mock(Object.class); CommandManager manager = mock(CommandManager.class); CommandResult expectedResult = mock(CommandResult.class); when(commandRegistry.isEmpty()).thenReturn(false); when(commandRegistry.peek()).thenReturn(command1); when(manager.execute(anyObject(), eq(command1))).thenReturn(expectedResult); CommandResult actualResult = tested.execute(obj, manager); assertEquals(expectedResult, actualResult); verify(manager).execute(eq(obj), eq(command1)); }
@Test @SuppressWarnings("unchecked") public void testExecuteOnNull() { Object obj = mock(Object.class); CommandManager manager = mock(CommandManager.class); when(commandRegistry.isEmpty()).thenReturn(true); RedoCommandHandler tested = new RedoCommandHandler(commandRegistry, registerChangedEvent); assertEquals(GraphCommandResultBuilder.SUCCESS, tested.execute(obj, manager)); verify(manager, never()).execute(anyObject(), any(Command.class)); }