@Test public void shouldAddCustomFieldParamsOnDelete() throws Exception { final CustomField customField1 = createMock(CustomField.class); expect(customField1.getId()).andReturn("customfield_10000"); expect(customField1.getValue(issue)).andReturn("Value1"); final CustomField customField2 = createMock(CustomField.class); expect(customField2.getId()).andReturn("customfield_10001"); expect(customField2.getValue(issue)).andReturn("Value2"); replay(customField1, customField2); expect(customFieldManager.getCustomFieldObjects(issue)) .andReturn(ImmutableList.of(customField1, customField2)); IssueDeleteHelper tested = getIssueDeleteHelper(); setUpEmptyWatchers(); expect(mockSubTaskManager.isSubTask(issueGenericValue)).andReturn(false); replayMocks(); tested.deleteIssue((User) null, issue, EventDispatchOption.ISSUE_DELETED, true); makeAssertions(); verify(customField1, customField2); final Map<String, Object> expected = ImmutableMap.<String, Object>of( "customfield_10000", "Value1", "customfield_10001", "Value2"); assertEquals(expected, capturedEventParams.get(IssueEvent.CUSTOM_FIELDS_PARAM_NAME)); assertTrue(capturedSendMailFlag); }
public CustomField getCustomFieldObject(Long id) { if (id == null) { return null; } String idString = id.toString(); for (Iterator iterator = customFields.iterator(); iterator.hasNext(); ) { CustomField customField = (CustomField) iterator.next(); if (idString.equals(customField.getId()) || ("customfield_" + idString).equals(customField.getId())) { return customField; } } return null; }
/** Get custom fields by type. */ private Map<String, String> getFieldsByType(String type) { Map<String, String> params = new TreeMap<String, String>(); List<CustomField> fields = ComponentAccessor.getCustomFieldManager().getCustomFieldObjects(); if (fields != null) { for (CustomField cf : fields) { if (cf.getCustomFieldType().getKey().equals(type)) { params.put(cf.getId(), cf.getName()); } } } return params; }