dimanche 15 mars 2015

How to make a Spring Shell command fail?

Imagine I have following Spring Shell commands class:



import org.springframework.shell.core.CommandMarker;

@Component
public class MyShellCommands implements CommandMarker {

@CliCommand(value = COMMAND_RUN, help = "")
public String run() {
[...]
// Something can go wrong here
[...]
}
}


If some error occurs in the method, I want the command to fail.


How can I make the run command fail, i. e. make sure that in case of error in the command, following assertion fails:



JLineShellComponent shell = ...;
final CommandResult result = shell.executeCommand("run");
assertThat(result.isSuccess()).isTrue(); // I want result.isSuccess() to be false, if run fails


?


Aucun commentaire:

Enregistrer un commentaire