@Test
public void testStaleBackgroundTaskIsSkipped() throws Exception {

	CompanyLocalService companyLocalService = Mockito.mock(
		CompanyLocalService.class);
	Mockito.when(
		companyLocalService.fetchCompany(Mockito.anyLong())
	).thenReturn(
		null
	);
	backgroundTaskThreadLocalManagerImpl.companyLocalService =
		companyLocalService;
	BackgroundTaskExecutor backgroundTaskExecutor = Mockito.mock(
		BackgroundTaskExecutor.class);
	ThreadLocalAwareBackgroundTaskExecutor
		threadLocalAwareBackgroundTaskExecutor =
			new ThreadLocalAwareBackgroundTaskExecutor(
				backgroundTaskExecutor,
				backgroundTaskThreadLocalManagerImpl);
	BackgroundTask backgroundTask = Mockito.mock(BackgroundTask.class);
	Mockito.when(
		backgroundTask.getTaskContextMap()
	).thenReturn(
		Collections.singletonMap(
			BackgroundTaskThreadLocalManagerImpl.KEY_THREAD_LOCAL_VALUES,
			(Serializable)new HashMap<>(
				Collections.singletonMap("companyId", 1)))
	);
	BackgroundTaskResult backgroundTaskResult =
		threadLocalAwareBackgroundTaskExecutor.execute(backgroundTask);
	Assert.assertTrue(backgroundTaskResult.isSuccessful());
	Mockito.verifyZeroInteractions(backgroundTaskExecutor);
}