Remove verifyQuery method and use verifyQueryTimes(1) instead

Remove unused import
   Update license header year to 2021
   Clear the code a little bit by:
   Remove explicit type arguments
   Make use of lambda
This commit is contained in:
Epure Alexandru-Eusebiu
2021-04-07 13:24:42 +03:00
parent 50da5e2156
commit 6e268330da
2 changed files with 30 additions and 51 deletions

View File

@@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited * Copyright (C) 2005 - 2021 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* - * -

View File

@@ -2,7 +2,7 @@
* #%L * #%L
* Alfresco Records Management Module * Alfresco Records Management Module
* %% * %%
* Copyright (C) 2005 - 2020 Alfresco Software Limited * Copyright (C) 2005 - 2021 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* - * -
@@ -59,7 +59,6 @@ import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Matchers; import org.mockito.Matchers;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer; import org.mockito.stubbing.Answer;
/** /**
@@ -75,7 +74,7 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
private static final String RETAIN = "retain"; private static final String RETAIN = "retain";
private static final String DESTROY = "destroy"; private static final String DESTROY = "destroy";
/** test query snipit */ /** test query snippet */
private static final String QUERY = "\"" + CUTOFF + "\" OR \"" + RETAIN + "\""; private static final String QUERY = "\"" + CUTOFF + "\" OR \"" + RETAIN + "\"";
/** mocked result set */ /** mocked result set */
@@ -94,17 +93,11 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
super.before(); super.before();
// Because of the fix implemented in MNT-22310, a new setup for retrying transaction helper is required. // Because of the fix implemented in MNT-22310, a new setup for retrying transaction helper is required.
Answer<Object> doInTransactionAnswer = new Answer<Object>() Answer<Object> doInTransactionAnswer = invocation -> {
{
@SuppressWarnings("rawtypes")
@Override
public Object answer(InvocationOnMock invocation) throws Throwable
{
RetryingTransactionCallback callback = (RetryingTransactionCallback)invocation.getArguments()[0]; RetryingTransactionCallback callback = (RetryingTransactionCallback)invocation.getArguments()[0];
return callback.execute(); return callback.execute();
}
}; };
doAnswer(doInTransactionAnswer).when(mockedRetryingTransactionHelper).<Object>doInTransaction(any(RetryingTransactionCallback.class), doAnswer(doInTransactionAnswer).when(mockedRetryingTransactionHelper).doInTransaction(any(RetryingTransactionCallback.class),
Matchers.anyBoolean(), Matchers.anyBoolean()); Matchers.anyBoolean(), Matchers.anyBoolean());
// setup data // setup data
@@ -117,14 +110,6 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
when(mockedResultSet.hasMore()).thenReturn(false); when(mockedResultSet.hasMore()).thenReturn(false);
} }
/**
* Helper method to verify that the query has been executed and closed
*/
private void verifyQuery()
{
verifyQueryTimes(1);
}
/** /**
* Helper method to verify that the query has been executed and closed * Helper method to verify that the query has been executed and closed
* @param numberOfInvocation number of times the query has been executed and closed * @param numberOfInvocation number of times the query has been executed and closed
@@ -153,7 +138,7 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
// then // then
// ensure the query is executed and closed // ensure the query is executed and closed
verifyQuery(); verifyQueryTimes(1);
// ensure nothing else happens becuase we have no results // ensure nothing else happens becuase we have no results
verifyZeroInteractions(mockedNodeService, mockedRecordFolderService, mockedRetryingTransactionHelper); verifyZeroInteractions(mockedNodeService, mockedRecordFolderService, mockedRetryingTransactionHelper);
@@ -192,7 +177,7 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
// ensure work is executed in transaction for each node processed // ensure work is executed in transaction for each node processed
verify(mockedNodeService, times(2)).exists(any(NodeRef.class)); verify(mockedNodeService, times(2)).exists(any(NodeRef.class));
verify(mockedRetryingTransactionHelper, times(2)).<Object>doInTransaction(any(RetryingTransactionCallback.class), verify(mockedRetryingTransactionHelper, times(2)).doInTransaction(any(RetryingTransactionCallback.class),
Matchers.anyBoolean(), Matchers.anyBoolean()); Matchers.anyBoolean(), Matchers.anyBoolean());
// ensure each node is process correctly // ensure each node is process correctly
@@ -224,7 +209,7 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
// then // then
// ensure the query is executed and closed // ensure the query is executed and closed
verifyQuery(); verifyQueryTimes(1);
// ensure the node exist check is made for the node // ensure the node exist check is made for the node
verify(mockedNodeService, times(1)).exists(any(NodeRef.class)); verify(mockedNodeService, times(1)).exists(any(NodeRef.class));
@@ -269,7 +254,7 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
// ensure work is executed in transaction for each node processed // ensure work is executed in transaction for each node processed
verify(mockedNodeService, times(2)).exists(any(NodeRef.class)); verify(mockedNodeService, times(2)).exists(any(NodeRef.class));
verify(mockedRetryingTransactionHelper, times(2)).<Object>doInTransaction(any(RetryingTransactionCallback.class), verify(mockedRetryingTransactionHelper, times(2)).doInTransaction(any(RetryingTransactionCallback.class),
Matchers.anyBoolean(), Matchers.anyBoolean()); Matchers.anyBoolean(), Matchers.anyBoolean());
// ensure each node is process correctly // ensure each node is process correctly
@@ -318,12 +303,7 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
final NodeRef node4 = generateNodeRef(); final NodeRef node4 = generateNodeRef();
// mock the search service to return the right page // mock the search service to return the right page
when(mockedSearchService.query(any(SearchParameters.class))).thenAnswer( when(mockedSearchService.query(any(SearchParameters.class))).thenAnswer((Answer<ResultSet>) invocation -> {
new Answer<ResultSet>()
{
@Override
public ResultSet answer(InvocationOnMock invocation)
{
SearchParameters params = invocation.getArgumentAt(0, SearchParameters.class); SearchParameters params = invocation.getArgumentAt(0, SearchParameters.class);
if (params.getSkipCount() == 0) if (params.getSkipCount() == 0)
{ {
@@ -342,7 +322,6 @@ public class DispositionLifecycleJobExecuterUnitTest extends BaseUnitTest
return result2; return result2;
} }
throw new IndexOutOfBoundsException("Pagination did not stop after the second page!"); throw new IndexOutOfBoundsException("Pagination did not stop after the second page!");
}
}); });
// call the service // call the service