### Question:
AbstractLifecycle implements Lifecycle { @Override public final void stop() throws LifecycleException { try { if (NEW == this.lifecycleStateMachine.getLifecycleState()) { this.lifecycleStateMachine.transition(STOPPED); return; } if (!this.lifecycleStateMachine.isMeaningfulTransition(STOPPING_PREP)) { return; } this.lifecycleStateMachine.transition(STOPPING_PREP); stopPrepInternal(); this.lifecycleStateMachine.transition(STOPPING); stopInternal(); this.lifecycleStateMachine.transition(STOPPED); } catch (RuntimeException e) { this.lifecycleStateMachine.transition(FAILED); throw new LifecycleException("Stop Failed", e); } } protected  AbstractLifecycle(); protected  AbstractLifecycle(LifecycleStateMachine lifecycleStateMachine, LifecycleSupport lifecycleSupport); @Override final void addLifecycleListener(LifecycleListener lifecycleListener); @Override final void destroy(); @Override final LifecycleListener[] findLifecycleListeners(); @Override final LifecycleState getState(); @Override final String getStateName(); @Override final void init(); @Override final void removeLifecycleListener(LifecycleListener lifecycleListener); @Override final void start(); @Override final void stop();  }### Answer:
@Test public void stop() throws LifecycleException { when(this.lifecycleStateMachine.isMeaningfulTransition(STOPPING_PREP)).thenReturn(true); this.lifecycle.stop(); verify(this.lifecycleStateMachine).transition(STOPPING_PREP); verify(this.lifecycleStateMachine).transition(STOPPING); verify(this.lifecycleStateMachine).transition(STOPPED); }
@Test public void stopAlreadyStopped() throws LifecycleException { when(this.lifecycleStateMachine.isMeaningfulTransition(STOPPING_PREP)).thenReturn(false); this.lifecycle.stop(); verify(this.lifecycleStateMachine, times(0)).transition(any(LifecycleState.class)); }
@Test public void stopFromNewCausesStopped() throws LifecycleException { when(this.lifecycleStateMachine.getLifecycleState()).thenReturn(NEW); this.lifecycle.stop(); verify(this.lifecycleStateMachine, times(0)).transition(STOPPING_PREP); verify(this.lifecycleStateMachine).transition(STOPPED); }