2828import io .jenkins .plugins .casc .model .Mapping ;
2929import io .jenkins .plugins .casc .model .Scalar ;
3030import io .jenkins .plugins .casc .model .Sequence ;
31+ import java .io .PrintWriter ;
32+ import java .io .StringWriter ;
3133import java .util .HashSet ;
3234import java .util .Set ;
3335import java .util .logging .Level ;
3436import java .util .logging .Logger ;
3537import javax .annotation .ParametersAreNonnullByDefault ;
3638import javax .annotation .PostConstruct ;
39+ import org .junit .jupiter .api .AfterAll ;
3740import org .junit .jupiter .api .BeforeEach ;
3841import org .junit .jupiter .api .Test ;
3942import org .jvnet .hudson .test .Issue ;
@@ -53,6 +56,9 @@ class DataBoundConfiguratorTest {
5356
5457 private final LogRecorder logging = new LogRecorder ();
5558
59+ /** captured exception to be printed after Jenkins is shut down */
60+ private static Throwable savedConfiguratorException ;
61+
5662 @ BeforeEach
5763 void tearUp (JenkinsRule j ) {
5864 this .j = j ;
@@ -164,6 +170,8 @@ void packageParametersAreNonnullByDefault() {
164170 .configure (config , new ConfigurationContext (registry )));
165171
166172 assertThat (exception .getMessage (), is (expectedMessage ));
173+
174+ savedConfiguratorException = exception ;
167175 }
168176
169177 @ Test
@@ -249,6 +257,19 @@ void shouldThrowConfiguratorException() {
249257 + " Constructor: public io.jenkins.plugins.casc.impl.configurators.DataBoundConfiguratorTest$Foo(java.lang.String,boolean,int).\n "
250258 + " Arguments: [java.lang.String, java.lang.Boolean, java.lang.Integer].\n "
251259 + " Expected Parameters: foo java.lang.String, bar boolean, qix int" ));
260+
261+ savedConfiguratorException = e ;
262+ }
263+
264+ @ AfterAll
265+ static void checkConfiguratorExceptionCanBeReportedWithoutJenkins () {
266+ if (savedConfiguratorException != null ) {
267+ StringWriter sw = new StringWriter ();
268+ try (PrintWriter pw = new PrintWriter (sw )) {
269+ savedConfiguratorException .printStackTrace (pw );
270+ }
271+ savedConfiguratorException = null ;
272+ }
252273 }
253274
254275 @ Test
0 commit comments