//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void testStopFailsShutdownFails() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void TestStopFailsShutdownFails() { LifeSupport lifeSupport = NewLifeSupport(); Lifecycle lifecycle1 = mock(typeof(Lifecycle)); Lifecycle lifecycle2 = mock(typeof(Lifecycle)); Exception stopRuntimeException = new Exception(); Exception shutdownRuntimeException = new Exception(); doThrow(stopRuntimeException).when(lifecycle2).stop(); doThrow(shutdownRuntimeException).when(lifecycle1).shutdown(); lifeSupport.Add(lifecycle1); lifeSupport.Add(lifecycle2); lifeSupport.Start(); try { lifeSupport.Shutdown(); fail("Expected exception"); } catch (LifecycleException e) { assertEquals(stopRuntimeException, e.InnerException); assertEquals(1, e.Suppressed.length); assertEquals(shutdownRuntimeException, e.Suppressed[0].Cause); assertThat(e.Suppressed[0], instanceOf(typeof(LifecycleException))); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void addLastComponentSomewhereInAChain() internal virtual void AddLastComponentSomewhereInAChain() { LifeSupport lifeSupport = NewLifeSupport(); Lifecycle notLastComponent1 = mock(typeof(Lifecycle)); Lifecycle notLastComponent2 = mock(typeof(Lifecycle)); Lifecycle lastComponent = mock(typeof(Lifecycle)); Lifecycle notLastComponent3 = mock(typeof(Lifecycle)); Lifecycle notLastComponent4 = mock(typeof(Lifecycle)); lifeSupport.Add(notLastComponent1); lifeSupport.Add(notLastComponent2); lifeSupport.Last = lastComponent; lifeSupport.Add(notLastComponent3); lifeSupport.Add(notLastComponent4); lifeSupport.Start(); IList <Lifecycle> lifecycleInstances = lifeSupport.LifecycleInstances; assertSame(notLastComponent1, lifecycleInstances[0]); assertSame(notLastComponent2, lifecycleInstances[1]); assertSame(notLastComponent3, lifecycleInstances[2]); assertSame(notLastComponent4, lifecycleInstances[3]); assertSame(lastComponent, lifecycleInstances[4]); assertThat(lifecycleInstances, hasSize(5)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void testFailingShutdown() throws LifecycleException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void TestFailingShutdown() { LifeSupport lifeSupport = NewLifeSupport(); LifecycleMock instance1 = new LifecycleMock(null, null, null, null); lifeSupport.Add(instance1); Exception shutdownThrowable = new Exception(); LifecycleMock instance2 = new LifecycleMock(null, null, null, shutdownThrowable); lifeSupport.Add(instance2); LifecycleMock instance3 = new LifecycleMock(null, null, null, null); lifeSupport.Add(instance3); lifeSupport.Start(); try { lifeSupport.Shutdown(); fail("Failure was expected"); } catch (LifecycleException throwable) { assertEquals(shutdownThrowable, throwable.InnerException); } assertEquals(LifecycleStatus.Shutdown, lifeSupport.Status); assertEquals(LifecycleStatus.Shutdown, instance1.Status); assertEquals(LifecycleStatus.Shutdown, instance2.Status); assertEquals(LifecycleStatus.Shutdown, instance3.Status); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void testFailingStartAndFailingStop() internal virtual void TestFailingStartAndFailingStop() { LifeSupport lifeSupport = NewLifeSupport(); Exception stopThrowable = new Exception(); LifecycleMock instance1 = new LifecycleMock(null, null, stopThrowable, null); lifeSupport.Add(instance1); Exception startThrowable = new Exception(); LifecycleMock instance2 = new LifecycleMock(null, startThrowable, null, null); lifeSupport.Add(instance2); LifecycleMock instance3 = new LifecycleMock(null, null, null, null); lifeSupport.Add(instance3); try { lifeSupport.Start(); fail("Failure was expected"); } catch (LifecycleException throwable) { assertEquals(startThrowable, throwable.InnerException); assertEquals(1, throwable.Suppressed.length); assertThat(throwable.Suppressed[0], instanceOf(typeof(LifecycleException))); assertEquals(stopThrowable, throwable.Suppressed[0].Cause); } assertEquals(LifecycleStatus.Stopped, lifeSupport.Status); assertEquals(LifecycleStatus.Stopped, instance1.Status); assertEquals(LifecycleStatus.Stopped, instance2.Status); assertEquals(LifecycleStatus.Stopped, instance3.Status); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void failToAddSeveralLastComponents() internal virtual void FailToAddSeveralLastComponents() { LifeSupport lifeSupport = NewLifeSupport(); Lifecycle lastComponent = mock(typeof(Lifecycle)); Lifecycle anotherLastComponent = mock(typeof(Lifecycle)); lifeSupport.Last = lastComponent; assertThrows(typeof(System.InvalidOperationException), () => lifeSupport.setLast(anotherLastComponent)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void addOnlyLastComponent() internal virtual void AddOnlyLastComponent() { LifeSupport lifeSupport = NewLifeSupport(); Lifecycle lastComponent = mock(typeof(Lifecycle)); lifeSupport.Last = lastComponent; lifeSupport.Start(); IList <Lifecycle> lifecycleInstances = lifeSupport.LifecycleInstances; assertSame(lastComponent, lifecycleInstances[0]); assertThat(lifecycleInstances, hasSize(1)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void testAddInstanceWhenInitInitsInstance() throws LifecycleException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void TestAddInstanceWhenInitInitsInstance() { LifeSupport support = NewLifeSupport(); support.Init(); LifecycleMock instance1 = new LifecycleMock(null, null, null, null); support.Add(instance1); assertEquals(LifecycleStatus.Stopped, instance1.Status); assertEquals(LifecycleStatus.None, instance1.Transitions[0]); assertEquals(2, instance1.Transitions.Count); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void testAddInstanceWhenShutdownDoesNotAffectInstance() throws LifecycleException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void TestAddInstanceWhenShutdownDoesNotAffectInstance() { LifeSupport support = NewLifeSupport(); support.Init(); support.Start(); support.Stop(); support.Shutdown(); LifecycleMock instance1 = new LifecycleMock(null, null, null, null); support.Add(instance1); assertEquals(LifecycleStatus.None, instance1.Status); assertEquals(1, instance1.Transitions.Count); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void testOkLifecycle() throws LifecycleException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void TestOkLifecycle() { LifeSupport lifeSupport = NewLifeSupport(); LifecycleMock instance1 = new LifecycleMock(null, null, null, null); lifeSupport.Add(instance1); LifecycleMock instance2 = new LifecycleMock(null, null, null, null); lifeSupport.Add(instance2); LifecycleMock instance3 = new LifecycleMock(null, null, null, null); lifeSupport.Add(instance3); lifeSupport.Init(); assertEquals(LifecycleStatus.Stopped, lifeSupport.Status); assertEquals(LifecycleStatus.Stopped, instance1.Status); assertEquals(LifecycleStatus.Stopped, instance2.Status); assertEquals(LifecycleStatus.Stopped, instance3.Status); lifeSupport.Start(); assertEquals(LifecycleStatus.Started, lifeSupport.Status); assertEquals(LifecycleStatus.Started, instance1.Status); assertEquals(LifecycleStatus.Started, instance2.Status); assertEquals(LifecycleStatus.Started, instance3.Status); lifeSupport.Stop(); assertEquals(LifecycleStatus.Stopped, lifeSupport.Status); assertEquals(LifecycleStatus.Stopped, instance1.Status); assertEquals(LifecycleStatus.Stopped, instance2.Status); assertEquals(LifecycleStatus.Stopped, instance3.Status); lifeSupport.Start(); assertEquals(LifecycleStatus.Started, lifeSupport.Status); assertEquals(LifecycleStatus.Started, instance1.Status); assertEquals(LifecycleStatus.Started, instance2.Status); assertEquals(LifecycleStatus.Started, instance3.Status); lifeSupport.Shutdown(); assertEquals(LifecycleStatus.Shutdown, lifeSupport.Status); assertEquals(LifecycleStatus.Shutdown, instance1.Status); assertEquals(LifecycleStatus.Shutdown, instance2.Status); assertEquals(LifecycleStatus.Shutdown, instance3.Status); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void testStartFailsStopWorks() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void TestStartFailsStopWorks() { LifeSupport lifeSupport = NewLifeSupport(); Lifecycle lifecycle = mock(typeof(Lifecycle)); Exception runtimeException = new Exception(); doThrow(runtimeException).when(lifecycle).start(); lifeSupport.Add(lifecycle); try { lifeSupport.Start(); fail("Expected exception"); } catch (LifecycleException e) { assertEquals(runtimeException, e.InnerException); assertEquals(0, e.Suppressed.length); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void testInitFailsShutdownWorks() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void TestInitFailsShutdownWorks() { //given LifeSupport lifeSupport = NewLifeSupport(); Lifecycle lifecycle = mock(typeof(Lifecycle)); Exception runtimeException = new Exception(); //when doThrow(runtimeException).when(lifecycle).init(); lifeSupport.Add(lifecycle); try { lifeSupport.Init(); fail("Expected exception"); } catch (LifecycleException e) { assertEquals(runtimeException, e.InnerException); assertEquals(0, e.Suppressed.length); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test void tryToShutdownComponentOnInitFailure() throws Throwable //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: internal virtual void TryToShutdownComponentOnInitFailure() { LifeSupport lifeSupport = NewLifeSupport(); Lifecycle component = mock(typeof(Lifecycle)); doThrow(new Exception("Init exceptions")).when(component).init(); doThrow(new Exception("Shutdown exceptions")).when(component).shutdown(); lifeSupport.Add(component); try { lifeSupport.Init(); fail("Failure was expected"); } catch (Exception e) { string message = GetExceptionStackTrace(e); assertThat(message, containsString("Exception during graceful attempt to shutdown partially initialized component. " + "Please use non suppressed exception to see original component failure.")); } assertEquals(LifecycleStatus.Shutdown, lifeSupport.Status); verify(component).shutdown(); }
internal LifecycleInstance(LifeSupport outerInstance, Lifecycle instance) { this._outerInstance = outerInstance; this.Instance = instance; Debug.Assert(TrackInstantiationStackTrace()); }