### Question:
SafeLifecycle implements Lifecycle { public State state() { return state; } protected  SafeLifecycle();   SafeLifecycle( State state ); @Override final synchronized void init(); @Override final synchronized void start(); @Override final synchronized void stop(); @Override final synchronized void shutdown(); void init0(); void start0(); void stop0(); void shutdown0(); State state();  }### Answer:
@Test void shouldPerformSuccessfulTransitionsCorrectly() throws Throwable { for ( int state = 0; state < State.values().length; state++ ) { for ( int op = 0; op < ops.length; op++ ) { MySafeAndSuccessfulLife sf = new MySafeAndSuccessfulLife( State.values()[state] ); boolean caughtIllegalTransition = false; try { ops[op].accept( sf ); } catch ( IllegalStateException e ) { caughtIllegalTransition = true; } if ( onSuccess[state][op] == null ) { assertTrue( caughtIllegalTransition ); assertEquals( State.values()[state], sf.state() ); } else { assertFalse( caughtIllegalTransition ); assertEquals( onSuccess[state][op], sf.state() ); int expectedOpCode = ignored[state][op] ? -1 : op; assertEquals( expectedOpCode, sf.opCode ); } } } }
@Test void shouldPerformFailedTransitionsCorrectly() throws Throwable { for ( int state = 0; state < State.values().length; state++ ) { for ( int op = 0; op < ops.length; op++ ) { MyFailedLife sf = new MyFailedLife( State.values()[state] ); boolean caughtIllegalTransition = false; boolean failedOperation = false; try { ops[op].accept( sf ); } catch ( IllegalStateException e ) { caughtIllegalTransition = true; } catch ( UnsupportedOperationException e ) { failedOperation = true; } if ( onFailed[state][op] == null ) { assertTrue( caughtIllegalTransition ); assertEquals( State.values()[state], sf.state() ); } else { assertFalse( caughtIllegalTransition ); assertEquals( onFailed[state][op], sf.state() ); if ( ignored[state][op] ) { assertEquals( -1, sf.opCode ); assertFalse( failedOperation ); } else { assertEquals( op, sf.opCode ); assertTrue( failedOperation ); } } } } }