### Question:
DefaultBatchOperationExecutor implements BatchOperationExecutor { @Override public <E extends Exception> void execute(BatchOperation<E> operation) throws E { String batchId = generateBatchId(); execute(operation, batchId); }  @Override void execute(BatchOperation<E> operation); @Override void execute(BatchOperation<E> operation, String batchId); @Override String getCurrentBatchId();  }### Answer:
@Test public void executeWithNoSpecifiedBatchId() throws Exception { BatchOperation operation = mock(BatchOperation.class); mocker.getComponentUnderTest().execute(operation, null); InOrder inOrder = inOrder(operation, executionContext); inOrder.verify(executionContext, times(1)).setProperty(eq(DefaultBatchOperationExecutor.CONTEXT_PROPERTY), matches(".*.*-.*-.*")); inOrder.verify(operation).execute(); inOrder.verify(executionContext, times(1)).setProperty(DefaultBatchOperationExecutor.CONTEXT_PROPERTY, null); }
@Test public void executeWithSpecifiedBatchId() throws Exception { BatchOperation operation = mock(BatchOperation.class); String specifiedBatchId = "a-b-c-d"; mocker.getComponentUnderTest().execute(operation, specifiedBatchId); InOrder inOrder = inOrder(operation, executionContext); inOrder.verify(executionContext, times(1)).setProperty(eq(DefaultBatchOperationExecutor.CONTEXT_PROPERTY), eq(specifiedBatchId)); inOrder.verify(operation).execute(); inOrder.verify(executionContext, times(1)).setProperty(DefaultBatchOperationExecutor.CONTEXT_PROPERTY, null); }
@Test public void executeNested() throws Exception { String existingBatchId = "a-b-c-d"; when(executionContext.getProperty(DefaultBatchOperationExecutor.CONTEXT_PROPERTY)).thenReturn(existingBatchId); BatchOperation operation = mock(BatchOperation.class); mocker.getComponentUnderTest().execute(operation); verify(executionContext, never()).setProperty(eq(DefaultBatchOperationExecutor.CONTEXT_PROPERTY), any()); verify(operation).execute(); }
@Test public void executeNestedWithSpecifiedBatchId() throws Exception { String existingBatchId = "a-b-c-d"; when(executionContext.getProperty(DefaultBatchOperationExecutor.CONTEXT_PROPERTY)).thenReturn(existingBatchId); String specifiedBatchId = "d-c-b-a"; BatchOperation operation = mock(BatchOperation.class); mocker.getComponentUnderTest().execute(operation, specifiedBatchId); verify(executionContext, never()).setProperty(eq(DefaultBatchOperationExecutor.CONTEXT_PROPERTY), any()); verify(operation).execute(); }