### Question:
LearningBehavior implements ILearningBehavior<ACTION> { @Override public void handleEpisodeEnd(Observation finalObservation) { experienceHandler.setFinalObservation(finalObservation); if(experienceHandler.isTrainingBatchReady()) { handleBatch(); } }  @Override void handleEpisodeStart(); @Override void handleNewExperience(Observation observation, ACTION action, double reward, boolean isTerminal); @Override void handleEpisodeEnd(Observation finalObservation); void notifyBeforeStep();  }### Answer:
@Test public void when_callingHandleEpisodeEnd_expect_experienceHandlerSetFinalObservationCalled() { INDArray observationData = Nd4j.rand(1, 1); when(experienceHandlerMock.isTrainingBatchReady()).thenReturn(false); sut.handleEpisodeEnd(new Observation(observationData)); ArgumentCaptor<Observation> observationCaptor = ArgumentCaptor.forClass(Observation.class); verify(experienceHandlerMock, times(1)).setFinalObservation(observationCaptor.capture()); assertEquals(observationData.getDouble(0, 0), observationCaptor.getValue().getData().getDouble(0, 0), 0.00001); verify(updateRuleMock, never()).update(any(List.class)); }
@Test public void when_callingHandleEpisodeEndAndTrainingBatchIsNotEmpty_expect_updateRuleUpdateWithTrainingBatch() { INDArray observationData = Nd4j.rand(1, 1); when(experienceHandlerMock.isTrainingBatchReady()).thenReturn(true); List<Object> trainingBatch = new ArrayList<Object>(); when(experienceHandlerMock.generateTrainingBatch()).thenReturn(trainingBatch); sut.handleEpisodeEnd(new Observation(observationData)); ArgumentCaptor<Observation> observationCaptor = ArgumentCaptor.forClass(Observation.class); verify(experienceHandlerMock, times(1)).setFinalObservation(observationCaptor.capture()); assertEquals(observationData.getDouble(0, 0), observationCaptor.getValue().getData().getDouble(0, 0), 0.00001); verify(updateRuleMock, times(1)).update(trainingBatch); }