### Question:
LifeSupport implements Lifecycle { public synchronized <T extends Lifecycle> T setLast( T instance ) { if ( last != null ) { throw new IllegalStateException( format( "Lifecycle supports only one last component. Already defined component: %s, new component: %s", last, instance ) ); } last = addNewComponent( instance ); return instance; } LifeSupport(); @Override synchronized void init(); @Override synchronized void start(); @Override synchronized void stop(); @Override synchronized void shutdown(); synchronized T add( T instance ); synchronized T setLast( T instance ); synchronized boolean remove( Lifecycle instance ); List<Lifecycle> getLifecycleInstances(); synchronized void clear(); LifecycleStatus getStatus(); synchronized void addLifecycleListener( LifecycleListener listener ); boolean isRunning(); @Override String toString();  }### Answer:
@Test void failToAddSeveralLastComponents() { LifeSupport lifeSupport = newLifeSupport(); Lifecycle lastComponent = mock( Lifecycle.class ); Lifecycle anotherLastComponent = mock( Lifecycle.class ); lifeSupport.setLast( lastComponent ); assertThrows( IllegalStateException.class, () -> lifeSupport.setLast( anotherLastComponent ) ); }