@Test public void testAttemptsToStopAllServicesOnCloseFailure() { Service s1 = mock(CacheProvider.class); Service s2 = mock(FooProvider.class); Service s3 = mock(CacheLoaderWriterProvider.class); ServiceLocator locator = new ServiceLocator(s1, s2, s3); try { locator.startAllServices(); } catch (Exception e) { fail(); } final RuntimeException thrown = new RuntimeException(); doThrow(thrown).when(s1).stop(); try { locator.stopAllServices(); fail(); } catch (Exception e) { assertThat(e, CoreMatchers.<Exception>sameInstance(thrown)); } verify(s1).stop(); verify(s2).stop(); verify(s3).stop(); }
/** * Creates a new instance of IsSame * * @param object The predicate evaluates to true only when the argument is this object. */ public void same(T object) { verifyUsingMatcher(CoreMatchers.sameInstance(object)); }