This is an automated email from the ASF dual-hosted git repository. dhemery pushed a commit to branch develop in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/develop by this push: new e362324d21 GEODE-10251: Make DescribedExternalResource report all exceptions (#7609) e362324d21 is described below commit e362324d21f6be0760357d74d6f5cb95d12f3a1c Author: Dale Emery <dem...@vmware.com> AuthorDate: Wed Apr 20 08:59:23 2022 -0700 GEODE-10251: Make DescribedExternalResource report all exceptions (#7609) * GEODE-10251: Make DescribedExternalResource report all exceptions Co-authored-by: Dale Emery <dem...@vmware.com> Co-authored-by: Kirk Lund <kl...@apache.org> * Fix test name Co-authored-by: Dale Emery <dem...@vmware.com> Co-authored-by: Kirk Lund <kl...@apache.org> * Spotless Co-authored-by: Dale Emery <dem...@vmware.com> Co-authored-by: Kirk Lund <kl...@apache.org> Co-authored-by: Kirk Lund <kl...@apache.org> --- .../junit/rules/DescribedExternalResource.java | 14 +++++- .../junit/rules/DescribedExternalResourceTest.java | 57 ++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/DescribedExternalResource.java b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/DescribedExternalResource.java index 57835a9163..90c66bf0d0 100644 --- a/geode-junit/src/main/java/org/apache/geode/test/junit/rules/DescribedExternalResource.java +++ b/geode-junit/src/main/java/org/apache/geode/test/junit/rules/DescribedExternalResource.java @@ -14,8 +14,12 @@ */ package org.apache.geode.test.junit.rules; +import java.util.ArrayList; +import java.util.List; + import org.junit.rules.TestRule; import org.junit.runner.Description; +import org.junit.runners.model.MultipleFailureException; import org.junit.runners.model.Statement; /** @@ -36,11 +40,19 @@ public abstract class DescribedExternalResource implements TestRule { @Override public void evaluate() throws Throwable { before(description); + List<Throwable> errors = new ArrayList<Throwable>(); try { base.evaluate(); + } catch (Throwable e) { + errors.add(e); } finally { - after(description); + try { + after(description); + } catch (Throwable e) { + errors.add(e); + } } + MultipleFailureException.assertEmpty(errors); } }; } diff --git a/geode-junit/src/test/java/org/apache/geode/test/junit/rules/DescribedExternalResourceTest.java b/geode-junit/src/test/java/org/apache/geode/test/junit/rules/DescribedExternalResourceTest.java new file mode 100644 index 0000000000..17e400324e --- /dev/null +++ b/geode-junit/src/test/java/org/apache/geode/test/junit/rules/DescribedExternalResourceTest.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for additional information regarding + * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. You may obtain a + * copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * + */ + +package org.apache.geode.test.junit.rules; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; + +import org.junit.jupiter.api.Test; +import org.junit.runner.Description; +import org.junit.runners.model.MultipleFailureException; +import org.junit.runners.model.Statement; + +public class DescribedExternalResourceTest { + @Test + void reportsErrorsFromBaseAndAfter() { + Throwable thrownByBase = new RuntimeException("thrown by base"); + Throwable thrownByAfter = new RuntimeException("thrown by after"); + + DescribedExternalResource rule = new DescribedExternalResource() { + @Override + protected void after(Description description) throws Throwable { + throw thrownByAfter; + } + }; + Statement base = new Statement() { + @Override + public void evaluate() throws Throwable { + throw thrownByBase; + } + }; + + Statement ruleStatement = rule.apply(base, null); + + Throwable thrownByRule = catchThrowable(ruleStatement::evaluate); + + assertThat(thrownByRule) + .isInstanceOf(MultipleFailureException.class); + assertThat(((MultipleFailureException) thrownByRule).getFailures()) + .containsExactlyInAnyOrder(thrownByBase, thrownByAfter); + } + + +}