Change doReturn(...).when(...) to typesafe when(...).thenReturn(...) for mocks

This commit is contained in:
Dennis Pietruck 2019-04-29 09:02:31 +02:00 committed by Mustapha Zorgati
parent 7720baaa2b
commit f433f8e474
11 changed files with 139 additions and 147 deletions

View File

@ -4,7 +4,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@ -31,8 +30,8 @@ import pro.taskana.TaskState;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.report.item.MonitorQueryItem;
import pro.taskana.impl.report.header.TimeIntervalColumnHeader;
import pro.taskana.impl.report.item.MonitorQueryItem;
import pro.taskana.mappings.TaskMonitorMapper;
import pro.taskana.report.CategoryReport;
@ -59,9 +58,9 @@ public class CategoryReportBuilderImplTest {
MockitoAnnotations.initMocks(this);
Mockito.doNothing().when(taskanaEngineImplMock).openConnection();
Mockito.doNothing().when(taskanaEngineImplMock).returnConnection();
doReturn(taskanaEngineConfiguration).when(taskanaEngineImplMock).getConfiguration();
doReturn(true).when(taskanaEngineConfiguration).isGermanPublicHolidaysEnabled();
doReturn(null).when(taskanaEngineConfiguration).getCustomHolidays();
when(taskanaEngineImplMock.getConfiguration()).thenReturn(taskanaEngineConfiguration);
when(taskanaEngineConfiguration.isGermanPublicHolidaysEnabled()).thenReturn(true);
when(taskanaEngineConfiguration.getCustomHolidays()).thenReturn(null);
}
@Test
@ -80,8 +79,8 @@ public class CategoryReportBuilderImplTest {
monitorQueryItem.setKey("EXTERN");
monitorQueryItem.setNumberOfTasks(1);
expectedResult.add(monitorQueryItem);
doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfCategories(workbasketIds, states, categories,
domains, classificationIds, excludedClassificationIds, customAttributeFilter);
when(taskMonitorMapperMock.getTaskCountOfCategories(workbasketIds, states, categories, domains,
classificationIds, excludedClassificationIds, customAttributeFilter)).thenReturn(expectedResult);
CategoryReport actualResult = cut.createCategoryReportBuilder()
.workbasketIdIn(workbasketIds)
@ -128,8 +127,9 @@ public class CategoryReportBuilderImplTest {
monitorQueryItem.setAgeInDays(0);
monitorQueryItem.setNumberOfTasks(1);
expectedResult.add(monitorQueryItem);
doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfCategories(workbasketIds, states, categories,
domains, classificationIds, excludedClassificationIds, customAttributeFilter);
when(taskMonitorMapperMock.getTaskCountOfCategories(workbasketIds, states, categories, domains,
classificationIds,
excludedClassificationIds, customAttributeFilter)).thenReturn(expectedResult);
CategoryReport actualResult = cut.createCategoryReportBuilder()
.workbasketIdIn(workbasketIds)

View File

@ -4,7 +4,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@ -62,9 +61,9 @@ public class ClassificationReportBuilderImplTest {
MockitoAnnotations.initMocks(this);
Mockito.doNothing().when(taskanaEngineImplMock).openConnection();
Mockito.doNothing().when(taskanaEngineImplMock).returnConnection();
doReturn(taskanaEngineConfiguration).when(taskanaEngineImplMock).getConfiguration();
doReturn(true).when(taskanaEngineConfiguration).isGermanPublicHolidaysEnabled();
doReturn(null).when(taskanaEngineConfiguration).getCustomHolidays();
when(taskanaEngineImplMock.getConfiguration()).thenReturn(taskanaEngineConfiguration);
when(taskanaEngineConfiguration.isGermanPublicHolidaysEnabled()).thenReturn(true);
when(taskanaEngineConfiguration.getCustomHolidays()).thenReturn(null);
}
@Test
@ -83,8 +82,8 @@ public class ClassificationReportBuilderImplTest {
monitorQueryItem.setKey("CLI:000000000000000000000000000000000001");
monitorQueryItem.setNumberOfTasks(1);
expectedResult.add(monitorQueryItem);
doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfClassifications(workbasketIds, states,
categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter);
when(taskMonitorMapperMock.getTaskCountOfClassifications(workbasketIds, states, categories, domains,
classificationIds, excludedClassificationIds, customAttributeFilter)).thenReturn(expectedResult);
ClassificationReport actualResult = cut.createClassificationReportBuilder()
.workbasketIdIn(workbasketIds)
@ -133,8 +132,8 @@ public class ClassificationReportBuilderImplTest {
monitorQueryItem.setAgeInDays(0);
monitorQueryItem.setNumberOfTasks(1);
expectedResult.add(monitorQueryItem);
doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfClassifications(workbasketIds, states,
categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter);
when(taskMonitorMapperMock.getTaskCountOfClassifications(workbasketIds, states, categories, domains,
classificationIds, excludedClassificationIds, customAttributeFilter)).thenReturn(expectedResult);
ClassificationReport actualResult = cut.createClassificationReportBuilder()
.workbasketIdIn(workbasketIds)
@ -182,8 +181,8 @@ public class ClassificationReportBuilderImplTest {
detailedMonitorQueryItem.setAttachmentKey("CLI:000000000000000000000000000000000006");
detailedMonitorQueryItem.setNumberOfTasks(1);
expectedResult.add(detailedMonitorQueryItem);
doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfDetailedClassifications(workbasketIds,
states, categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter);
when(taskMonitorMapperMock.getTaskCountOfDetailedClassifications(workbasketIds, states, categories, domains,
classificationIds, excludedClassificationIds, customAttributeFilter)).thenReturn(expectedResult);
DetailedClassificationReport actualResult = cut.createClassificationReportBuilder()
.workbasketIdIn(workbasketIds)
@ -234,8 +233,8 @@ public class ClassificationReportBuilderImplTest {
detailedMonitorQueryItem.setAgeInDays(0);
detailedMonitorQueryItem.setNumberOfTasks(1);
expectedResult.add(detailedMonitorQueryItem);
doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfDetailedClassifications(workbasketIds,
states, categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter);
when(taskMonitorMapperMock.getTaskCountOfDetailedClassifications(workbasketIds, states, categories, domains,
classificationIds, excludedClassificationIds, customAttributeFilter)).thenReturn(expectedResult);
DetailedClassificationReport actualResult = cut.createClassificationReportBuilder()
.workbasketIdIn(workbasketIds)

View File

@ -3,8 +3,8 @@ package pro.taskana.impl;
import static junit.framework.TestCase.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import java.util.List;
@ -67,7 +67,7 @@ public class ClassificationServiceImplTest {
NotAuthorizedException, ClassificationAlreadyExistException {
try {
Classification classification = createDummyClassification();
doReturn(true).when(taskanaEngineImplMock).domainExists(any());
when(taskanaEngineImplMock.domainExists(any())).thenReturn(true);
cutSpy.createClassification(classification);
} catch (InvalidArgumentException e) {
assertEquals(e.getMessage(), "ClassificationId should be null on creation");

View File

@ -3,7 +3,6 @@ package pro.taskana.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@ -30,8 +29,8 @@ import pro.taskana.TaskState;
import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.report.item.MonitorQueryItem;
import pro.taskana.impl.report.header.TimeIntervalColumnHeader;
import pro.taskana.impl.report.item.MonitorQueryItem;
import pro.taskana.mappings.TaskMonitorMapper;
import pro.taskana.report.CustomFieldValueReport;
@ -58,9 +57,9 @@ public class CustomFieldValueReportBuilderImplTest {
MockitoAnnotations.initMocks(this);
Mockito.doNothing().when(taskanaEngineImplMock).openConnection();
Mockito.doNothing().when(taskanaEngineImplMock).returnConnection();
doReturn(taskanaEngineConfiguration).when(taskanaEngineImplMock).getConfiguration();
doReturn(true).when(taskanaEngineConfiguration).isGermanPublicHolidaysEnabled();
doReturn(null).when(taskanaEngineConfiguration).getCustomHolidays();
when(taskanaEngineImplMock.getConfiguration()).thenReturn(taskanaEngineConfiguration);
when(taskanaEngineConfiguration.isGermanPublicHolidaysEnabled()).thenReturn(true);
when(taskanaEngineConfiguration.getCustomHolidays()).thenReturn(null);
}
@Test
@ -79,9 +78,9 @@ public class CustomFieldValueReportBuilderImplTest {
monitorQueryItem.setKey("Geschaeftsstelle A");
monitorQueryItem.setNumberOfTasks(1);
expectedResult.add(monitorQueryItem);
doReturn(expectedResult).when(taskMonitorMapperMock)
.getTaskCountOfCustomFieldValues(CustomField.CUSTOM_1, workbasketIds, states, categories, domains,
classificationIds, excludedClassificationIds, customAttributeFilter);
when(taskMonitorMapperMock.getTaskCountOfCustomFieldValues(CustomField.CUSTOM_1, workbasketIds, states,
categories,
domains, classificationIds, excludedClassificationIds, customAttributeFilter)).thenReturn(expectedResult);
CustomFieldValueReport actualResult = cut.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1)
.workbasketIdIn(workbasketIds)
@ -129,9 +128,9 @@ public class CustomFieldValueReportBuilderImplTest {
monitorQueryItem.setAgeInDays(0);
monitorQueryItem.setNumberOfTasks(1);
expectedResult.add(monitorQueryItem);
doReturn(expectedResult).when(taskMonitorMapperMock)
.getTaskCountOfCustomFieldValues(CustomField.CUSTOM_1, workbasketIds, states, categories, domains,
classificationIds, excludedClassificationIds, customAttributeFilter);
when(taskMonitorMapperMock.getTaskCountOfCustomFieldValues(CustomField.CUSTOM_1, workbasketIds, states,
categories,
domains, classificationIds, excludedClassificationIds, customAttributeFilter)).thenReturn(expectedResult);
CustomFieldValueReport actualResult = cut.createCustomFieldValueReportBuilder(CustomField.CUSTOM_1)
.workbasketIdIn(workbasketIds)

View File

@ -15,6 +15,7 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import pro.taskana.ObjectReference;
/**
* Test for ObjectReferenceQueryImpl.
*

View File

@ -1,7 +1,6 @@
package pro.taskana.impl;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
@ -29,23 +28,18 @@ import pro.taskana.TaskSummary;
@RunWith(MockitoJUnitRunner.class)
public class TaskQueryImplTest {
@InjectMocks
private TaskQueryImpl taskQueryImpl;
@Mock
private TaskanaEngineImpl taskanaEngine;
@Mock
private SqlSession sqlSession;
@Mock
private SqlSessionManager sqlSessionManager;
@Mock
ClassificationServiceImpl classificationService;
@Mock
TaskServiceImpl taskServiceMock;
@InjectMocks
private TaskQueryImpl taskQueryImpl;
@Mock
private TaskanaEngineImpl taskanaEngine;
@Mock
private SqlSession sqlSession;
@Mock
private SqlSessionManager sqlSessionManager;
@Before
public void setup() {
@ -65,7 +59,7 @@ public class TaskQueryImplTest {
when(sqlSession.selectList(any(), any())).thenReturn(new ArrayList<>());
List<TaskSummary> intermediate = new ArrayList<>();
intermediate.add(new TaskSummaryImpl());
doReturn(intermediate).when(taskServiceMock).augmentTaskSummariesByContainedSummaries(any());
when(taskServiceMock.augmentTaskSummariesByContainedSummaries(any())).thenReturn(intermediate);
List<TaskSummary> result = taskQueryImpl.nameIn("test", "asd", "blubber")
.priorityIn(1, 2)
@ -80,7 +74,7 @@ public class TaskQueryImplTest {
when(sqlSession.selectList(any(), any(), any())).thenReturn(new ArrayList<>());
List<TaskSummary> intermediate = new ArrayList<>();
intermediate.add(new TaskSummaryImpl());
doReturn(intermediate).when(taskServiceMock).augmentTaskSummariesByContainedSummaries(any());
when(taskServiceMock.augmentTaskSummariesByContainedSummaries(any())).thenReturn(intermediate);
List<TaskSummary> result = taskQueryImpl.nameIn("test", "asd", "blubber")
.priorityIn(1, 2)
@ -95,8 +89,8 @@ public class TaskQueryImplTest {
when(sqlSession.selectOne(any(), any())).thenReturn(new TaskSummaryImpl());
List<TaskSummary> intermediate = new ArrayList<>();
intermediate.add(new TaskSummaryImpl());
doReturn(intermediate).when(taskServiceMock).augmentTaskSummariesByContainedSummaries(any());
// when(taskServiceMock.augmentTaskSummariesByContainedSummaries(any())).thenReturn(intermediate);
when(taskServiceMock.augmentTaskSummariesByContainedSummaries(any())).thenReturn(intermediate);
TaskSummary result = taskQueryImpl.nameIn("test", "asd", "blubber")
.priorityIn(1, 2)

View File

@ -15,6 +15,7 @@ import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import java.time.Duration;
import java.time.Instant;
@ -111,8 +112,8 @@ public class TaskServiceImplTest {
@Before
public void setup() throws WorkbasketNotFoundException {
MockitoAnnotations.initMocks(this);
doReturn(workbasketServiceMock).when(taskanaEngineMock).getWorkbasketService();
doReturn(classificationServiceImplMock).when(taskanaEngineMock).getClassificationService();
when(taskanaEngineMock.getWorkbasketService()).thenReturn(workbasketServiceMock);
when(taskanaEngineMock.getClassificationService()).thenReturn(classificationServiceImplMock);
try {
Mockito.doNothing().when(workbasketServiceMock).checkAuthorization(any(), any());
} catch (NotAuthorizedException e) {
@ -134,14 +135,14 @@ public class TaskServiceImplTest {
wb.setName("workbasket");
wb.setDomain(dummyClassification.getDomain());
doThrow(TaskNotFoundException.class).when(cutSpy).getTask(expectedTask.getId());
doReturn(wb).when(workbasketServiceMock).getWorkbasket(wb.getKey(), wb.getDomain());
when(workbasketServiceMock.getWorkbasket(wb.getKey(), wb.getDomain())).thenReturn(wb);
doNothing().when(taskMapperMock).insert(expectedTask);
doReturn(dummyClassification).when(
classificationServiceImplMock)
.getClassification(dummyClassification.getKey(), dummyClassification.getDomain());
when(classificationServiceImplMock.getClassification(
dummyClassification.getKey(),
dummyClassification.getDomain())).thenReturn(dummyClassification);
expectedTask.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
when(taskanaEngineMock.getConfiguration()).thenReturn(taskanaEngineConfigurationMock);
when(taskanaEngineConfigurationMock.isSecurityEnabled()).thenReturn(false);
Task actualTask = cutSpy.createTask(expectedTask);
@ -180,14 +181,13 @@ public class TaskServiceImplTest {
wb.setName("workbasket");
wb.setDomain(dummyClassification.getDomain());
doThrow(TaskNotFoundException.class).when(cutSpy).getTask(expectedTask.getId());
doReturn(wb).when(workbasketServiceMock).getWorkbasket(wb.getKey(), wb.getDomain());
when(workbasketServiceMock.getWorkbasket(wb.getKey(), wb.getDomain())).thenReturn(wb);
doNothing().when(taskMapperMock).insert(expectedTask);
doReturn(dummyClassification).when(
classificationServiceImplMock)
.getClassification(dummyClassification.getKey(), dummyClassification.getDomain());
when(classificationServiceImplMock.getClassification(dummyClassification.getKey(),
dummyClassification.getDomain())).thenReturn(dummyClassification);
expectedTask.setPrimaryObjRef(JunitHelper.createDefaultObjRef());
doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
doReturn(true).when(taskanaEngineConfigurationMock).isSecurityEnabled();
when(taskanaEngineMock.getConfiguration()).thenReturn(taskanaEngineConfigurationMock);
when(taskanaEngineConfigurationMock.isSecurityEnabled()).thenReturn(true);
cutSpy.createTask(expectedTask);
}
@ -208,16 +208,15 @@ public class TaskServiceImplTest {
expectedTask.setPrimaryObjRef(expectedObjectReference);
ClassificationSummary classification = expectedTask.getClassificationSummary();
doThrow(TaskNotFoundException.class).when(cutSpy).getTask(expectedTask.getId());
doReturn(wb).when(workbasketServiceMock).getWorkbasket(expectedTask.getWorkbasketKey(),
expectedTask.getDomain());
doReturn(expectedObjectReference).when(objectReferenceMapperMock)
.findByObjectReference(expectedObjectReference);
doReturn(dummyClassification).when(
classificationServiceImplMock)
.getClassification(dummyClassification.getKey(), dummyClassification.getDomain());
when(workbasketServiceMock.getWorkbasket(expectedTask.getWorkbasketKey(),
expectedTask.getDomain())).thenReturn(wb);
when(objectReferenceMapperMock.findByObjectReference(expectedObjectReference)).thenReturn(
expectedObjectReference);
when(classificationServiceImplMock.getClassification(dummyClassification.getKey(),
dummyClassification.getDomain())).thenReturn(dummyClassification);
doNothing().when(taskMapperMock).insert(expectedTask);
doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
when(taskanaEngineMock.getConfiguration()).thenReturn(taskanaEngineConfigurationMock);
when(taskanaEngineConfigurationMock.isSecurityEnabled()).thenReturn(false);
Task actualTask = cutSpy.createTask(expectedTask);
verify(taskanaEngineMock, times(1)).openConnection();
@ -256,19 +255,19 @@ public class TaskServiceImplTest {
wb.setName("workbasket");
wb.setDomain("dummy-domain");
doReturn(wb).when(workbasketServiceMock).getWorkbasket(wb.getKey(), wb.getDomain());
when(workbasketServiceMock.getWorkbasket(wb.getKey(), wb.getDomain())).thenReturn(wb);
Classification dummyClassification = createDummyClassification();
TaskImpl expectedTask = createUnitTestTask("", "DUMMYTASK", "key1", dummyClassification);
expectedTask.setPrimaryObjRef(expectedObjectReference);
ClassificationSummary classification = expectedTask.getClassificationSummary();
doThrow(TaskNotFoundException.class).when(cutSpy).getTask(expectedTask.getId());
doReturn(dummyClassification).when(classificationServiceImplMock).getClassification(classification.getKey(),
classification.getDomain());
when(classificationServiceImplMock.getClassification(classification.getKey(),
classification.getDomain())).thenReturn(dummyClassification);
doNothing().when(taskMapperMock).insert(expectedTask);
doNothing().when(objectReferenceMapperMock).insert(expectedObjectReference);
doReturn(null).when(objectReferenceMapperMock).findByObjectReference(expectedTask.getPrimaryObjRef());
doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
when(objectReferenceMapperMock.findByObjectReference(expectedTask.getPrimaryObjRef())).thenReturn(null);
when(taskanaEngineMock.getConfiguration()).thenReturn(taskanaEngineConfigurationMock);
when(taskanaEngineConfigurationMock.isSecurityEnabled()).thenReturn(false);
Task actualTask = cutSpy.createTask(expectedTask);
expectedTask.getPrimaryObjRef().setId(actualTask.getPrimaryObjRef().getId()); // get only new ID
@ -321,14 +320,14 @@ public class TaskServiceImplTest {
task.setPrimaryObjRef(expectedObjectReference);
task.setDescription("simply awesome task");
doThrow(TaskNotFoundException.class).when(cutSpy).getTask(task.getId());
doReturn(wb).when(workbasketServiceMock).getWorkbasket(wb.getId());
doReturn(classification).when(classificationServiceImplMock).getClassification(classification.getKey(),
wb.getDomain());
doReturn(expectedObjectReference).when(objectReferenceMapperMock)
.findByObjectReference(expectedObjectReference);
when(workbasketServiceMock.getWorkbasket(wb.getId())).thenReturn(wb);
when(classificationServiceImplMock.getClassification(classification.getKey(),
wb.getDomain())).thenReturn(classification);
when(objectReferenceMapperMock.findByObjectReference(expectedObjectReference)).thenReturn(
expectedObjectReference);
doNothing().when(taskMapperMock).insert(task);
doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
when(taskanaEngineMock.getConfiguration()).thenReturn(taskanaEngineConfigurationMock);
when(taskanaEngineConfigurationMock.isSecurityEnabled()).thenReturn(false);
cutSpy.createTask(task);
@ -403,7 +402,7 @@ public class TaskServiceImplTest {
TaskImpl task = createUnitTestTask("", "dummyTask", "1", dummyClassification);
Workbasket dummyWorkbasket = createWorkbasket("2", "k1");
task.setWorkbasketSummary(dummyWorkbasket.asSummary());
doReturn(dummyWorkbasket).when(workbasketServiceMock).getWorkbasket(any());
when(workbasketServiceMock.getWorkbasket(any())).thenReturn(dummyWorkbasket);
doThrow(TaskNotFoundException.class).when(cutSpy).getTask(task.getId());
doThrow(NotAuthorizedException.class).when(workbasketServiceMock).checkAuthorization(
task.getWorkbasketSummary().getId(),
@ -433,7 +432,7 @@ public class TaskServiceImplTest {
Classification dummyClassification = createDummyClassification();
TaskImpl task = createUnitTestTask("", "dumma-task", "1", dummyClassification);
doThrow(TaskNotFoundException.class).when(cutSpy).getTask(task.getId());
doThrow(WorkbasketNotFoundException.class).when(workbasketServiceMock).getWorkbasket(any(), any());
when(workbasketServiceMock.getWorkbasket(any(), any())).thenThrow(WorkbasketNotFoundException.class);
try {
cutSpy.createTask(task);
} catch (WorkbasketNotFoundException e) {
@ -494,7 +493,7 @@ public class TaskServiceImplTest {
@Test(expected = TaskNotFoundException.class)
public void testClaimThrowinTaskNotFoundException() throws Exception {
TaskImpl expectedTask = null;
Mockito.doReturn(expectedTask).when(taskMapperMock).findById(any());
when(taskMapperMock.findById(any())).thenReturn(expectedTask);
try {
cut.forceClaim("1");
@ -686,24 +685,24 @@ public class TaskServiceImplTest {
task.setState(TaskState.CLAIMED);
task.setClaimed(Instant.now());
task.setOwner(CurrentUserContext.getUserid());
doReturn(task).when(taskMapperMock).findById(task.getId());
doReturn(null).when(attachmentMapperMock).findAttachmentsByTaskId(task.getId());
when(taskMapperMock.findById(task.getId())).thenReturn(task);
when(attachmentMapperMock.findAttachmentsByTaskId(task.getId())).thenReturn(null);
doReturn(task).when(cutSpy).completeTask(task.getId());
doReturn(classificationQueryImplMock).when(classificationServiceImplMock).createClassificationQuery();
doReturn(classificationQueryImplMock).when(classificationQueryImplMock).idIn(any());
doReturn(new ArrayList<>()).when(classificationQueryImplMock).list();
List<ClassificationSummaryImpl> classificationList = Arrays
when(classificationServiceImplMock.createClassificationQuery()).thenReturn(classificationQueryImplMock);
when(classificationQueryImplMock.idIn(any())).thenReturn(classificationQueryImplMock);
when(classificationQueryImplMock.list()).thenReturn(new ArrayList<>());
List<ClassificationSummary> classificationList = Arrays
.asList((ClassificationSummaryImpl) dummyClassification.asSummary());
doReturn(classificationList).when(
classificationQueryImplMock)
.list();
doReturn(workbasketQueryImplMock).when(workbasketServiceMock).createWorkbasketQuery();
doReturn(workbasketQueryImplMock).when(workbasketQueryImplMock).idIn(any());
when(
classificationQueryImplMock
.list()).thenReturn(classificationList);
when(workbasketServiceMock.createWorkbasketQuery()).thenReturn(workbasketQueryImplMock);
when(workbasketQueryImplMock.idIn(any())).thenReturn(workbasketQueryImplMock);
List<WorkbasketSummary> wbList = new ArrayList<>();
WorkbasketSummaryImpl wb = new WorkbasketSummaryImpl();
wb.setDomain("dummy-domain");
wbList.add(wb);
doReturn(wbList).when(workbasketQueryImplMock).list();
when(workbasketQueryImplMock.list()).thenReturn(wbList);
Task actualTask = cut.completeTask(task.getId());
@ -905,10 +904,10 @@ public class TaskServiceImplTest {
TaskImpl task = createUnitTestTask("1", "Unit Test Task 1", "key47", dummyClassification);
task.setWorkbasketSummary(sourceWorkbasket.asSummary());
task.setRead(true);
doReturn(destinationWorkbasket).when(workbasketServiceMock).getWorkbasket(destinationWorkbasket.getId());
doReturn(sourceWorkbasket).when(workbasketServiceMock).getWorkbasket(sourceWorkbasket.getId());
doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
doReturn(false).when(taskanaEngineConfigurationMock).isSecurityEnabled();
when(workbasketServiceMock.getWorkbasket(destinationWorkbasket.getId())).thenReturn(destinationWorkbasket);
when(workbasketServiceMock.getWorkbasket(sourceWorkbasket.getId())).thenReturn(sourceWorkbasket);
when(taskanaEngineMock.getConfiguration()).thenReturn(taskanaEngineConfigurationMock);
when(taskanaEngineConfigurationMock.isSecurityEnabled()).thenReturn(false);
doReturn(task).when(cutSpy).getTask(task.getId());
doNothing().when(taskMapperMock).update(any());
doNothing().when(workbasketServiceMock).checkAuthorization(destinationWorkbasket.getId(),
@ -944,10 +943,10 @@ public class TaskServiceImplTest {
Classification dummyClassification = createDummyClassification();
TaskImpl task = createUnitTestTask("1", "Unit Test Task 1", "k1", dummyClassification);
task.setRead(true);
doReturn(taskanaEngineConfigurationMock).when(taskanaEngineMock).getConfiguration();
doReturn(true).when(taskanaEngineConfigurationMock).isSecurityEnabled();
when(taskanaEngineMock.getConfiguration()).thenReturn(taskanaEngineConfigurationMock);
when(taskanaEngineConfigurationMock.isSecurityEnabled()).thenReturn(true);
doReturn(task).when(cutSpy).getTask(task.getId());
doReturn(destinationWorkbasket).when(workbasketServiceMock).getWorkbasket(destinationWorkbasket.getId());
when(workbasketServiceMock.getWorkbasket(destinationWorkbasket.getId())).thenReturn(destinationWorkbasket);
doNothing().when(taskMapperMock).update(any());
doNothing().when(workbasketServiceMock).checkAuthorization(any(), any());
// doNothing().when(workbasketServiceMock).checkAuthorizationById(any(), WorkbasketAuthorization.TRANSFER);
@ -1124,25 +1123,25 @@ public class TaskServiceImplTest {
public void testGetTaskByIdWithExistingTask()
throws TaskNotFoundException, NotAuthorizedException {
Classification dummyClassification = createDummyClassification();
Task expectedTask = createUnitTestTask("1", "DUMMY-TASK", "1", dummyClassification);
doReturn(expectedTask).when(taskMapperMock).findById(expectedTask.getId());
doReturn(null).when(attachmentMapperMock).findAttachmentsByTaskId(expectedTask.getId());
TaskImpl expectedTask = createUnitTestTask("1", "DUMMY-TASK", "1", dummyClassification);
when(taskMapperMock.findById(expectedTask.getId())).thenReturn(expectedTask);
when(attachmentMapperMock.findAttachmentsByTaskId(expectedTask.getId())).thenReturn(null);
doReturn(classificationQueryImplMock).when(classificationServiceImplMock).createClassificationQuery();
doReturn(classificationQueryImplMock).when(classificationQueryImplMock).idIn(any());
doReturn(workbasketQueryImplMock).when(workbasketServiceMock).createWorkbasketQuery();
doReturn(workbasketQueryImplMock).when(workbasketQueryImplMock).idIn(any());
when(classificationServiceImplMock.createClassificationQuery()).thenReturn(classificationQueryImplMock);
when(classificationQueryImplMock.idIn(any())).thenReturn(classificationQueryImplMock);
when(workbasketServiceMock.createWorkbasketQuery()).thenReturn(workbasketQueryImplMock);
when(workbasketQueryImplMock.idIn(any())).thenReturn(workbasketQueryImplMock);
List<WorkbasketSummary> wbList = new ArrayList<>();
WorkbasketSummaryImpl wb = new WorkbasketSummaryImpl();
wb.setDomain("dummy-domain");
wbList.add(wb);
doReturn(wbList).when(workbasketQueryImplMock).list();
when(workbasketQueryImplMock.list()).thenReturn(wbList);
List<ClassificationSummaryImpl> classificationList = Arrays
List<ClassificationSummary> classificationList = Arrays
.asList((ClassificationSummaryImpl) dummyClassification.asSummary());
doReturn(classificationList).when(
classificationQueryImplMock)
.list();
when(
classificationQueryImplMock
.list()).thenReturn(classificationList);
Task actualTask = cut.getTask(expectedTask.getId());
verify(taskanaEngineMock, times(1)).openConnection();
@ -1166,7 +1165,7 @@ public class TaskServiceImplTest {
public void testGetTaskByIdWhereTaskDoesNotExist() throws Exception {
Classification dummyClassification = createDummyClassification();
Task task = createUnitTestTask("1", "DUMMY-TASK", "1", dummyClassification);
doThrow(TaskNotFoundException.class).when(taskMapperMock).findById(task.getId());
when(taskMapperMock.findById(task.getId())).thenThrow(TaskNotFoundException.class);
try {
cut.getTask(task.getId());
@ -1337,7 +1336,7 @@ public class TaskServiceImplTest {
}
@Test
public void testTaskSummaryEqualsHashCode() throws InterruptedException {
public void testTaskSummaryEqualsHashCode() throws InterruptedException {
Classification classification = createDummyClassification();
Workbasket wb = createWorkbasket("WB-ID", "WB-Key");
Attachment attachment = JunitHelper.createDefaultAttachment();
@ -1368,7 +1367,7 @@ public class TaskServiceImplTest {
summaryAfter = taskAfter.asSummary();
assertEquals(summaryBefore, summaryAfter);
assertEquals(summaryBefore.hashCode(), summaryAfter.hashCode());
}
}
private TaskImpl createUnitTestTask(String id, String name, String workbasketKey, Classification classification) {
TaskImpl task = new TaskImpl();

View File

@ -53,7 +53,7 @@ public class WorkbasketAccessItemQueryImplTest {
when(sqlSession.selectList(any(), any(), any())).thenReturn(new ArrayList<>());
List<WorkbasketAccessItem> result = workbasketAccessItemQueryImpl.accessIdIn("test", "asd")
.list(1, 1);
.list(1, 1);
Assert.assertNotNull(result);
}

View File

@ -43,9 +43,9 @@ public class WorkbasketQueryImplTest {
when(sqlSession.selectList(any(), any())).thenReturn(new ArrayList<>());
List<WorkbasketSummary> result = workbasketQueryImpl
.nameIn("Gruppenpostkorb KSC 1", "Gruppenpostkorb KSC 2")
.keyLike("GPK_%")
.list();
.nameIn("Gruppenpostkorb KSC 1", "Gruppenpostkorb KSC 2")
.keyLike("GPK_%")
.list();
Assert.assertNotNull(result);
}
@ -55,9 +55,9 @@ public class WorkbasketQueryImplTest {
when(sqlSession.selectList(any(), any(), any())).thenReturn(new ArrayList<>());
List<WorkbasketSummary> result = workbasketQueryImpl
.nameIn("Gruppenpostkorb KSC 1", "Gruppenpostkorb KSC 2")
.keyLike("GPK_%")
.list(1, 1);
.nameIn("Gruppenpostkorb KSC 1", "Gruppenpostkorb KSC 2")
.keyLike("GPK_%")
.list(1, 1);
Assert.assertNotNull(result);
}
@ -67,9 +67,9 @@ public class WorkbasketQueryImplTest {
when(sqlSession.selectOne(any(), any())).thenReturn(new WorkbasketSummaryImpl());
WorkbasketSummary result = workbasketQueryImpl
.nameIn("Gruppenpostkorb KSC 1", "Gruppenpostkorb KSC 2")
.keyLike("GPK_%")
.single();
.nameIn("Gruppenpostkorb KSC 1", "Gruppenpostkorb KSC 2")
.keyLike("GPK_%")
.single();
Assert.assertNotNull(result);
}
}

View File

@ -4,7 +4,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
@ -33,8 +32,8 @@ import pro.taskana.configuration.TaskanaEngineConfiguration;
import pro.taskana.exceptions.InvalidArgumentException;
import pro.taskana.exceptions.NotAuthorizedException;
import pro.taskana.impl.report.CombinedClassificationFilter;
import pro.taskana.impl.report.item.MonitorQueryItem;
import pro.taskana.impl.report.header.TimeIntervalColumnHeader;
import pro.taskana.impl.report.item.MonitorQueryItem;
import pro.taskana.mappings.TaskMonitorMapper;
import pro.taskana.report.WorkbasketReport;
@ -61,9 +60,9 @@ public class WorkbasketReportBuilderImplTest {
MockitoAnnotations.initMocks(this);
Mockito.doNothing().when(taskanaEngineImplMock).openConnection();
Mockito.doNothing().when(taskanaEngineImplMock).returnConnection();
doReturn(taskanaEngineConfiguration).when(taskanaEngineImplMock).getConfiguration();
doReturn(true).when(taskanaEngineConfiguration).isGermanPublicHolidaysEnabled();
doReturn(null).when(taskanaEngineConfiguration).getCustomHolidays();
when(taskanaEngineImplMock.getConfiguration()).thenReturn(taskanaEngineConfiguration);
when(taskanaEngineConfiguration.isGermanPublicHolidaysEnabled()).thenReturn(true);
when(taskanaEngineConfiguration.getCustomHolidays()).thenReturn(null);
}
@Test
@ -86,9 +85,9 @@ public class WorkbasketReportBuilderImplTest {
monitorQueryItem.setKey("WBI:000000000000000000000000000000000001");
monitorQueryItem.setNumberOfTasks(1);
expectedResult.add(monitorQueryItem);
doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfWorkbaskets(workbasketIds, states,
when(taskMonitorMapperMock.getTaskCountOfWorkbaskets(workbasketIds, states,
categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter,
combinedClassificationFilter);
combinedClassificationFilter)).thenReturn(expectedResult);
WorkbasketReport actualResult = cut.createWorkbasketReportBuilder()
.workbasketIdIn(workbasketIds)
@ -141,9 +140,9 @@ public class WorkbasketReportBuilderImplTest {
monitorQueryItem.setAgeInDays(0);
monitorQueryItem.setNumberOfTasks(1);
expectedResult.add(monitorQueryItem);
doReturn(expectedResult).when(taskMonitorMapperMock).getTaskCountOfWorkbaskets(workbasketIds, states,
when(taskMonitorMapperMock.getTaskCountOfWorkbaskets(workbasketIds, states,
categories, domains, classificationIds, excludedClassificationIds, customAttributeFilter,
combinedClassificationFilter);
combinedClassificationFilter)).thenReturn(expectedResult);
WorkbasketReport actualResult = cut.createWorkbasketReportBuilder()
.workbasketIdIn(workbasketIds)

View File

@ -11,6 +11,7 @@ import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays;
@ -97,7 +98,7 @@ public class WorkbasketServiceImplTest {
WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
doNothing().when(workbasketMapperMock).insert(expectedWb);
doReturn(expectedWb).when(cutSpy).getWorkbasket(any());
doReturn(true).when(taskanaEngineImplMock).domainExists(any());
when(taskanaEngineImplMock.domainExists(any())).thenReturn(true);
Workbasket actualWb = cutSpy.createWorkbasket(expectedWb);
cutSpy.setDistributionTargets(expectedWb.getId(), createTestDistributionTargets(distTargetAmount));
@ -127,7 +128,7 @@ public class WorkbasketServiceImplTest {
WorkbasketAlreadyExistException, DomainNotFoundException {
WorkbasketImpl expectedWb = createTestWorkbasket("ID-1", "Key-1");
doNothing().when(workbasketMapperMock).insert(expectedWb);
doReturn(true).when(taskanaEngineImplMock).domainExists(any());
when(taskanaEngineImplMock.domainExists(any())).thenReturn(true);
try {
cutSpy.createWorkbasket(expectedWb);
@ -159,7 +160,7 @@ public class WorkbasketServiceImplTest {
throws Exception {
WorkbasketImpl expectedWb = createTestWorkbasket(null, "Key-1");
doNothing().when(workbasketMapperMock).insert(expectedWb);
doThrow(WorkbasketNotFoundException.class).when(workbasketMapperMock).findById(any());
when(workbasketMapperMock.findById(any())).thenThrow(WorkbasketNotFoundException.class);
try {
cutSpy.createWorkbasket(expectedWb);