Added more explicit exception msg; fixes gh-72
This commit is contained in:
@@ -29,15 +29,21 @@ class Task {
|
||||
}
|
||||
|
||||
void execute(Args args) {
|
||||
boolean interactive = args.interactive;
|
||||
printLog(interactive);
|
||||
if (interactive) {
|
||||
boolean skipStep = skipStep();
|
||||
if (!skipStep) {
|
||||
try {
|
||||
boolean interactive = args.interactive;
|
||||
printLog(interactive);
|
||||
if (interactive) {
|
||||
boolean skipStep = skipStep();
|
||||
if (!skipStep) {
|
||||
consumer.accept(args);
|
||||
}
|
||||
} else {
|
||||
consumer.accept(args);
|
||||
}
|
||||
} else {
|
||||
consumer.accept(args);
|
||||
} catch (Exception e) {
|
||||
log.error("\n\n\nBUILD FAILED!!!\n\nException occurred for task <" +
|
||||
this.name + "> \n\nwith description <" + this.description + ">\n\n", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
package org.springframework.cloud.release.internal.spring;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.springframework.boot.test.rule.OutputCapture;
|
||||
|
||||
import static org.assertj.core.api.BDDAssertions.then;
|
||||
import static org.assertj.core.api.BDDAssertions.thenThrownBy;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Marcin Grzejszczak
|
||||
*/
|
||||
public class TaskTests {
|
||||
|
||||
@Rule public OutputCapture capture = new OutputCapture();
|
||||
|
||||
@Test public void should_successfully_execute_task() {
|
||||
final AtomicBoolean someBool = new AtomicBoolean();
|
||||
Task task = new Task("foo", "bar", "baz", "descr", new Consumer<Args>() {
|
||||
@Override public void accept(Args args) {
|
||||
someBool.set(true);
|
||||
}
|
||||
});
|
||||
|
||||
task.execute(Mockito.mock(Args.class));
|
||||
|
||||
then(someBool.get()).isTrue();
|
||||
}
|
||||
|
||||
@Test public void should_fail_with_nice_text_on_exception() {
|
||||
final AtomicBoolean someBool = new AtomicBoolean();
|
||||
Task task = new Task("foo", "bar", "baz", "descr", new Consumer<Args>() {
|
||||
@Override public void accept(Args args) {
|
||||
someBool.set(true);
|
||||
throw new RuntimeException("foooooooo");
|
||||
}
|
||||
});
|
||||
|
||||
thenThrownBy(() -> task.execute(Mockito.mock(Args.class)))
|
||||
.isInstanceOf(RuntimeException.class);
|
||||
then(someBool.get()).isTrue();
|
||||
then(this.capture.toString())
|
||||
.contains("BUILD FAILED!!!")
|
||||
.contains("Exception occurred for task <foo>")
|
||||
.contains("with description <descr>");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user