@@ -0,0 +1,3727 @@
+%0A// Functional automated test against component, 7 lines of reasonably concise code.%0A@Test%0Apublic void followed_by_running_state_determineIfOptimizationContinues_should_recurse_once_and_return_true()%7B%0A   //setup%0A   OptimizerSynchronizationMarshaller marshaller = makeMarshaller();%0A   when(stateMachine.getState()).thenReturn(State.Pending, State.Running);%0A%0A   //act%0A   boolean shouldContinue = marshaller.determineIfOptimizationContinues();%0A%0A   //assert%0A   assertThat(shouldContinue).isTrue();%0A   assertThat(marshaller.acknowledgements).containsExactly(pendingState);%0A   verify(stateMachine, twice()).getState();%0A%7D%0A%0A// Atomicity (non-functional) test against the same component. %0A// significanty more code, author thought it warranted substantial documentation and a timeout.%0A// cyclomatic complexity is an order of magnitude higher.%0A%0A/**%0A * This is a test to assert that the scheme handles contention between the optimizer and the HMI thread%0A * in the Start-Order state well. In this state, whether we transfer back to Idle or on to Running%0A * is determined by a 'race'%0A * (first order to be recieved -- more specifically the first one to lock the state machine)%0A * between these two threads. This test asserts that, in one scenario, the locks work out correctly.%0A */%0A@Test(timeout = 1000)%0Apublic void when_in_state_StartPending_and_a_StopOrder_happens_immediately_before_the_optimizer_tries_to_ack_should_become_idle() throws InterruptedException %7B%0A    //setup%0A    marshaller = makeMarshaller();%0A    marshaller.getStateMachine().currentState = StartPending;%0A%0A    CountDownLatch stopOrderShouldContinueSignal = new CountDownLatch(1);%0A    CountDownLatch stopOrderIsReadyToContinueSignal = new CountDownLatch(1);%0A    CountDownLatch optimizerIsChecking = new CountDownLatch(1);%0A%0A    LinqingList%3CTransfer%3E reportedTransfers = new LinqingList%3C%3E();%0A%0A    marshaller.getStateMachine().addTransferListener((oldState, xfer, newState) -%3E %7B%0A%0A        reportedTransfers.add(xfer);%0A%0A        if(xfer == Transfer.StopOrder)%7B%0A            //blocks us while we're in the middle of transferring, a vary precarious spot!%0A            stopOrderIsReadyToContinueSignal.countDown();%0A            ExceptionUtilities.failOnException(stopOrderShouldContinueSignal::await);%0A        %7D%0A    %7D);%0A%0A    Runnable hmiWorkload = () -%3E %7B%0A        marshaller.issueOrderAndAwaitAcknowledgement(Transfer.StopOrder);%0A    %7D;%0A%0A    Runnable optimizerWorkload = () -%3E %7B%0A        optimizerIsChecking.countDown();%0A        boolean shouldContinue = marshaller.determineIfOptimizationContinues();%0A        assertThat(shouldContinue).isFalse();%0A    %7D;%0A%0A    //act I : get HMI thread ordering change-back to stop%0A    Thread fauxHMIThread = syncingUtilities.asynchronously(%22fauxHMIThread%22, ThreadTag.HMI, hmiWorkload).get();%0A    stopOrderIsReadyToContinueSignal.await();%0A%0A    //act II : get optimizer asking if it should continue while HMI thread is transferring states%0A    Thread fauxOptimizer = syncingUtilities.asynchronously(%22fauxOptimizer%22, ThreadTag.Optimizer, optimizerWorkload).get();%0A    optimizerIsChecking.await();%0A    syncingUtilities.sleepUnlessInterruptedFor(CheckDelay); //let optimizer *attempt* to continue%0A    Thread.State optimizerStateAfterChecking = fauxOptimizer.getState();%0A%0A    //act III : let the HMI thread finish its transfer%0A    stopOrderShouldContinueSignal.countDown();%0A    fauxHMIThread.join();%0A    fauxOptimizer.join();%0A%0A    //assert%0A    assertThat(marshaller.getState()).isEqualTo(Idle);%0A    assertThat(reportedTransfers).containsExactly(StopOrder);%0A    assertThat(optimizerStateAfterChecking).isEqualTo(Thread.State.BLOCKED);%0A    eventBus.shouldNotHaveBeenAskedToPost(OptimizationRunGroupHaltedEvent.class); //remember this test is pending -%3E stopped%0A%7D%0A

Create SampleTestsFromOASIS.java