Source:
public void testImportDataObjects() { final DataObject present = mock(DataObject.class); final DataObject notPresent = mock(DataObject.class); final List<DataObject> imported = asList(present, notPresent); final DataType presentDataType = mock(DataType.class); final DataType notPresentDataType = mock(DataType.class); final String importedPresentClass = "org.something.MyClass"; final DataType existingDataType = mock(DataType.class); doReturn(presentDataType).when(dataTypeList).createNewDataType(present); doReturn(notPresentDataType).when(dataTypeList).createNewDataType(notPresent); doReturn(true).when(dataTypeList).isPresent(present); doReturn(false).when(dataTypeList).isPresent(notPresent); when(present.getClassType()).thenReturn(importedPresentClass); doReturn(existingDataType).when(dataTypeList).findDataTypeByName(importedPresentClass); doNothing().when(dataTypeList).replace(existingDataType, presentDataType); doNothing().when(dataTypeList).insertProperties(present); doNothing().when(dataTypeList).insertProperties(notPresent); doNothing().when(dataTypeList).insert(notPresentDataType); doNothing().when(dataTypeList).removeFullQualifiedNames(imported); dataTypeList.importDataObjects(imported); verify(dataTypeList).isPresent(present); verify(dataTypeList).isPresent(notPresent); verify(dataTypeList).findDataTypeByName(importedPresentClass); verify(dataTypeList).replace(existingDataType, presentDataType); verify(dataTypeList).insertProperties(present); verify(dataTypeList).insert(notPresentDataType); verify(dataTypeList, never()).insert(presentDataType); verify(dataTypeList).insertProperties(notPresent); verify(dataTypeList).removeFullQualifiedNames(imported); }

Target:
public void testImportDataObjects() { final DataObject present = mock(DataObject.class); final DataObject notPresent = mock(DataObject.class); final List<DataObject> selectedDataObjects = asList(present, notPresent); final DataType presentDataType = mock(DataType.class); final DataType notPresentDataType = mock(DataType.class); final String notPresentClass = "not.present"; final String importedPresentClass = "org.something.MyClass"; final DataType existingDataType = mock(DataType.class); doReturn(presentDataType).when(dataTypeList).createNewDataType(present); doReturn(notPresentDataType).when(dataTypeList).createNewDataType(notPresent); doReturn(Optional.of(existingDataType)).when(dataTypeList).findDataTypeByName(importedPresentClass); doReturn(Optional.empty()).when(dataTypeList).findDataTypeByName(notPresentClass); doNothing().when(dataTypeList).replace(existingDataType, presentDataType); doNothing().when(dataTypeList).insertProperties(present); doNothing().when(dataTypeList).insertProperties(notPresent); doNothing().when(dataTypeList).insert(notPresentDataType); doNothing().when(dataTypeList).removeFullQualifiedNames(selectedDataObjects); when(notPresent.getClassType()).thenReturn(notPresentClass); when(present.getClassType()).thenReturn(importedPresentClass); dataTypeList.importDataObjects(selectedDataObjects); verify(dataTypeList).findDataTypeByName(importedPresentClass); verify(dataTypeList).replace(existingDataType, presentDataType); verify(dataTypeList).insertProperties(present); verify(dataTypeList, never()).insert(presentDataType); verify(dataTypeList).insert(notPresentDataType); verify(dataTypeList).insertProperties(notPresent); verify(dataTypeList).removeFullQualifiedNames(selectedDataObjects); }