AsyncJobWorkerImpl implements AsyncJobWorker { public boolean beforeExecute(final String jobSequenceId) { boolean updated = jobStatusChanger.changeToStartStatus(jobSequenceId); return updated; } protected  AsyncJobWorkerImpl(BLogicResolver blogicResolver,
            BLogicExceptionHandlerResolver blogicExceptionHandlerResolver,
            ApplicationContextResolver blogicApplicationContextResolver,
            JobControlFinder jobControlFinder,
            BLogicParamConverter blogicParamConverter,
            BLogicExecutor blogicExecutor, JobStatusChanger jobStatusChanger); boolean beforeExecute(final String jobSequenceId); @Override void executeWorker(final String jobSequenceId);  }
@Test public void testBeforeExecute01() throws Exception { when(mockJobStatusChanger.changeToStartStatus(anyString())).thenReturn( true); AsyncJobWorkerImpl target = new AsyncJobWorkerImpl(mockBLogicResolver, mockBLogicExceptionHandlerResolver, mockBLogicApplicationContextResolver, mockJobControlFinder, mockBLogicParamConverter, mockBLogicExecutor, mockJobStatusChanger); boolean actual = target.beforeExecute("0000001"); assertTrue(actual); verify(mockJobStatusChanger).changeToStartStatus("0000001"); }
@Test public void testBeforeExecute02() throws Exception { when(mockJobStatusChanger.changeToStartStatus(anyString())).thenReturn( false); AsyncJobWorkerImpl target = new AsyncJobWorkerImpl(mockBLogicResolver, mockBLogicExceptionHandlerResolver, mockBLogicApplicationContextResolver, mockJobControlFinder, mockBLogicParamConverter, mockBLogicExecutor, mockJobStatusChanger); boolean actual = target.beforeExecute("0000001"); assertFalse(actual); verify(mockJobStatusChanger).changeToStartStatus("0000001"); }
@Test public void testBeforeExecute03() throws Exception { @SuppressWarnings("serial") Exception ex = new DataAccessException("dummy exception") {}; when(mockJobStatusChanger.changeToStartStatus(anyString())).thenThrow( ex); AsyncJobWorkerImpl target = new AsyncJobWorkerImpl(mockBLogicResolver, mockBLogicExceptionHandlerResolver, mockBLogicApplicationContextResolver, mockJobControlFinder, mockBLogicParamConverter, mockBLogicExecutor, mockJobStatusChanger); try { target.beforeExecute("0000001"); fail("The exception has not been detected."); } catch (DataAccessException dae) { assertSame(ex, dae); verify(mockJobStatusChanger).changeToStartStatus("0000001"); } }