Added more explicit exception msg; fixes gh-72

This commit is contained in:
Marcin Grzejszczak
2018-02-02 02:08:19 +01:00
parent 2f377debf2
commit dcb782508e
2 changed files with 65 additions and 7 deletions

View File

@@ -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;
}
}

View File

@@ -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>");
}
}