### Question:
ClearSessionCommand extends AbstractClientSessionCommand<EditorSession> { @Override @SuppressWarnings("unchecked") public <V> void execute(final Callback<V> callback) { checkNotNull("callback", callback); final CommandResult<CanvasViolation> result = getSession() .getCommandManager() .execute(getSession().getCanvasHandler(), canvasCommandFactory.clearCanvas()); if (!CommandUtils.isError(result)) { cleanSessionRegistry(); commandExecutedEvent.fire(new ClearSessionCommandExecutedEvent(this, getSession())); callback.onSuccess(); } else { callback.onError((V) result); } } protected  ClearSessionCommand(); @Inject  ClearSessionCommand(final @Any ManagedInstance<CanvasCommandFactory<AbstractCanvasHandler>> canvasCommandFactoryInstance,
                               final SessionCommandManager<AbstractCanvasHandler> sessionCommandManager,
                               final Event<ClearSessionCommandExecutedEvent> commandExecutedEvent,
                               final DefinitionUtils definitionUtils); @Override void bind(final EditorSession session); @Override boolean accepts(final ClientSession session); @Override @SuppressWarnings("unchecked") void execute(final Callback<V> callback);  }### Answer:
@Test @SuppressWarnings("unchecked") public void testExecuteSuccess() { when(sessionCommandManager.execute(canvasHandler, clearCanvasCommand)).thenReturn(null); command.execute(callback); verify(sessionCommandManager, times(1)).execute(canvasHandler, clearCanvasCommand); verify(commandRegistry, times(1)).clear(); verify(callback, times(1)).onSuccess(); verify(commandExecutedEvent, times(1)).fire(commandExecutedEventCaptor.capture()); assertEquals(session, commandExecutedEventCaptor.getValue().getClientSession()); assertEquals(command, commandExecutedEventCaptor.getValue().getExecutedCommand()); }
@Test @SuppressWarnings("unchecked") public void testExecuteWithErrors() { when(sessionCommandManager.execute(canvasHandler, clearCanvasCommand)).thenReturn(commandResult); when(commandResult.getType()).thenReturn(CommandResult.Type.ERROR); command.execute(callback); verify(sessionCommandManager, times(1)).execute(canvasHandler, clearCanvasCommand); verify(commandRegistry, never()).clear(); verify(callback, times(1)).onError(commandResult); verify(commandExecutedEvent, never()).fire(commandExecutedEventCaptor.capture()); }