issues/1142: proper exception handling
@@ -5,6 +5,7 @@ import static org.carlspring.strongbox.testing.storage.repository.TestRepository
import java.io.IOException;
import java.lang.annotation.Annotation;
+import java.lang.reflect.UndeclaredThrowableException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
@@ -136,8 +137,39 @@ public class TestRepositoryManagementApplicationContext extends AnnotationConfig
}
lock();
+ try
+ {
super.refresh();
}
+ catch (Throwable e)
+ {
+ unlockWithExceptionPropagation(e);
+ }
+ }
+
+ private void unlockWithExceptionPropagation(Throwable e)
+ throws BeansException,
+ IllegalStateException
+ {
+ try
+ {
+ unlock();
+ }
+ catch (Throwable e1)
+ {
+ e1.addSuppressed(e);
+ throw new ApplicationContextException("Failed to unlock test resources.", e1);
+ }
+ if (e instanceof BeansException)
+ {
+ throw (BeansException) e;
+ }
+ else if (e instanceof IllegalStateException)
+ {
+ throw (IllegalStateException) e;
+ }
+ throw new UndeclaredThrowableException(e);
+ }
private void lock()
{
