commit 29a89abb35361ad4807fff32b4b76b48e8bdf337 Author: j-denboer <joost.denb...@tele2.com> AuthorDate: Tue, 17 Dec 2013 15:23:13 +0100 Commit: Mauro Talevi <mauro.tal...@aquilonia.org> CommitDate: Wed, 26 Feb 2014 08:49:11 +0000
JBEHAVE-970 Fix for issue where tests give a false positive when Spring context fails to load properly. Solved by having the SpringAnnotationBuilder throw an InstantiationFailed exception, just like is done in AnnotationBuilder class and not only consume the exception in the annotationMonitor. diff --git a/jbehave-spring/src/main/java/org/jbehave/core/configuration/spring/SpringAnnotationBuilder.java b/jbehave-spring/src/main/java/org/jbehave/core/configuration/spring/SpringAnnotationBuilder.java index 12d55aa..db1374b 100755 --- a/jbehave-spring/src/main/java/org/jbehave/core/configuration/spring/SpringAnnotationBuilder.java +++ b/jbehave-spring/src/main/java/org/jbehave/core/configuration/spring/SpringAnnotationBuilder.java @@ -47,6 +47,7 @@ public class SpringAnnotationBuilder extends AnnotationBuilder { context = createApplicationContext(annotatedClass().getClassLoader(), resources); } catch (Exception e) { annotationMonitor().elementCreationFailed(ApplicationContext.class, e); + throw new InstantiationFailed(annotatedClass(), e); } } } else { diff --git a/jbehave-spring/src/test/java/org/jbehave/core/configuration/spring/SpringAnnotationBuilderBehaviour.java b/jbehave-spring/src/test/java/org/jbehave/core/configuration/spring/SpringAnnotationBuilderBehaviour.java index 5d8ddb6..d4f0af9 100755 --- a/jbehave-spring/src/test/java/org/jbehave/core/configuration/spring/SpringAnnotationBuilderBehaviour.java +++ b/jbehave-spring/src/test/java/org/jbehave/core/configuration/spring/SpringAnnotationBuilderBehaviour.java @@ -11,6 +11,7 @@ import static org.jbehave.core.reporters.Format.HTML; import static org.jbehave.core.reporters.Format.STATS; import static org.jbehave.core.reporters.Format.TXT; import static org.jbehave.core.reporters.Format.XML; +import static org.junit.Assert.fail; import static org.mockito.Matchers.isA; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -75,7 +76,7 @@ public class SpringAnnotationBuilderBehaviour { try { assertThat((Date) parameterConverters.convert(date, Date.class), equalTo(dateFormat.parse(date))); } catch (ParseException e) { - Assert.fail(); + fail(); } } @@ -145,7 +146,12 @@ public class SpringAnnotationBuilderBehaviour { public void shouldNotBuildContainerIfResourceNotLoadable() { AnnotationMonitor annotationMonitor = mock(AnnotationMonitor.class); AnnotationBuilder builderUnloadableResource = new SpringAnnotationBuilder(AnnotatedWithUnloadableResource.class, annotationMonitor); + try { assertThatStepsInstancesAre(builderUnloadableResource.buildCandidateSteps()); + fail("Exception expected"); + } catch (AnnotationBuilder.InstantiationFailed e) { + // expected + } verify(annotationMonitor).elementCreationFailed(isA(Class.class), isA(Exception.class)); }