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 -> {
{ RetryingTransactionCallback callback = (RetryingTransactionCallback)invocation.getArguments()[0];
@SuppressWarnings("rawtypes") return callback.execute();
@Override
public Object answer(InvocationOnMock invocation) throws Throwable
{
RetryingTransactionCallback callback = (RetryingTransactionCallback)invocation.getArguments()[0];
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,32 +303,26 @@ 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>() SearchParameters params = invocation.getArgumentAt(0, SearchParameters.class);
if (params.getSkipCount() == 0)
{ {
@Override // mock first page
public ResultSet answer(InvocationOnMock invocation) ResultSet result1 = mock(ResultSet.class);
{ when(result1.getNodeRefs()).thenReturn(Arrays.asList(node1, node2));
SearchParameters params = invocation.getArgumentAt(0, SearchParameters.class); when(result1.hasMore()).thenReturn(true);
if (params.getSkipCount() == 0) return result1;
{ }
// mock first page else if (params.getSkipCount() == 2)
ResultSet result1 = mock(ResultSet.class); {
when(result1.getNodeRefs()).thenReturn(Arrays.asList(node1, node2)); // mock second page
when(result1.hasMore()).thenReturn(true); ResultSet result2 = mock(ResultSet.class);
return result1; when(result2.getNodeRefs()).thenReturn(Arrays.asList(node3, node4));
} when(result2.hasMore()).thenReturn(false);
else if (params.getSkipCount() == 2) return result2;
{ }
// mock second page throw new IndexOutOfBoundsException("Pagination did not stop after the second page!");
ResultSet result2 = mock(ResultSet.class); });
when(result2.getNodeRefs()).thenReturn(Arrays.asList(node3, node4));
when(result2.hasMore()).thenReturn(false);
return result2;
}
throw new IndexOutOfBoundsException("Pagination did not stop after the second page!");
}
});
// call the service // call the service
executer.executeImpl(); executer.executeImpl();