WilmaBootstrap { public void bootstrap() { ClassPathXmlApplicationContext applicationContext = null; try { applicationContext = getApplicationContext(); WilmaEngine wilmaEngine = applicationContext.getBean(WilmaEngine.class); WilmaServiceListener wilmaServiceListener = applicationContext.getBean(WilmaServiceListener.class); wilmaEngine.addListener(wilmaServiceListener, MoreExecutors.directExecutor()); wilmaEngine.start(); } catch (Exception e) { logErrorByTypeOfException(e); closeApplicationContext(applicationContext); } } WilmaBootstrap(final ApplicationContextFactory applicationContextFactory); void bootstrap();  }
@Test public void testBootstrapShouldStartWilmaEngine() { given(applicationContext.getBean(WilmaEngine.class)).willReturn(wilmaEngine); underTest.bootstrap(); verify(wilmaEngine).start(); }
@Test public void testBootstrapWhenThrowsSchedulingCannotBeStartedExceptionShouldLogException() { given(applicationContext.getBean(WilmaEngine.class)).willThrow(beanCreationException); given(beanCreationException.getMostSpecificCause()).willReturn(schedulingCannotBeStartedException); given(beanCreationException.contains(SchedulingCannotBeStartedException.class)).willReturn(true); given(beanCreationException.getCause()).willReturn(schedulingCannotBeStartedException); given(systemExceptionSelector.getSystemException(beanCreationException)).willReturn(schedulingCannotBeStartedException); underTest.bootstrap(); verify(systemExceptionSelector).getSystemException(beanCreationException); verify(logger).error(WILMA_CANNOT_BE_STARTED_ERROR_MSG + beanCreationException.getMostSpecificCause().getMessage(), schedulingCannotBeStartedException); }
@Test public void testBootstrapWhenThrowsInvalidPropertyExceptionShouldLogException() { given(applicationContext.getBean(WilmaEngine.class)).willThrow(beanCreationException); given(beanCreationException.getMostSpecificCause()).willReturn(invalidPropertyException); given(beanCreationException.contains(InvalidPropertyException.class)).willReturn(true); given(beanCreationException.getCause()).willReturn(invalidPropertyException); given(systemExceptionSelector.getSystemException(beanCreationException)).willReturn(invalidPropertyException); underTest.bootstrap(); verify(systemExceptionSelector).getSystemException(beanCreationException); verify(logger).error(WILMA_CANNOT_BE_STARTED_ERROR_MSG + beanCreationException.getMostSpecificCause().getMessage(), invalidPropertyException); }
@Test public void testBootstrapWhenThrowsPropertiesNotAvailableExceptionShouldLogException() { given(applicationContext.getBean(WilmaEngine.class)).willThrow(beanCreationException); given(beanCreationException.getMostSpecificCause()).willReturn(schedulingCannotBeStartedException); given(beanCreationException.contains(PropertiesNotAvailableException.class)).willReturn(true); given(beanCreationException.getCause()).willReturn(schedulingCannotBeStartedException); given(systemExceptionSelector.getSystemException(beanCreationException)).willReturn(schedulingCannotBeStartedException); underTest.bootstrap(); verify(systemExceptionSelector).getSystemException(beanCreationException); verify(logger).error(WILMA_CANNOT_BE_STARTED_ERROR_MSG + beanCreationException.getMostSpecificCause().getMessage(), schedulingCannotBeStartedException); }
@Test public void testBootstrapShouldLogAnyNonWilmaSpecificException() { given(applicationContext.getBean(WilmaEngine.class)).willThrow(beanCreationException); given(beanCreationException.getMostSpecificCause()).willReturn(schedulingCannotBeStartedException); given(beanCreationException.contains(RuntimeException.class)).willReturn(true); given(systemExceptionSelector.getSystemException(beanCreationException)).willReturn(null); given(beanCreationException.getCause()).willReturn(null); underTest.bootstrap(); verify(systemExceptionSelector).getSystemException(beanCreationException); verify(logger).error(WILMA_CANNOT_BE_STARTED_ERROR_MSG, beanCreationException); }