Which mocking/test classes are available that can help me test a class/method like an implementation of AbstractMultiSettableCFType.getValueFromIssue(CustomField, Issue)? I tried various approaches, using PowerMockito and such, but every time I run into some database backend instantiation that I'm not sure how to configure correctly.
// public class OtrsLinkCFType extends AbstractMultiSettableCFType
OtrsLinkCFType q = new OtrsLinkCFType(cfvp, gcm, om);
Collection<OtrsPageReference> refs = (Collection<OtrsPageReference>) q.getValueFromIssue(null, issue);
Community moderators have prevented the ability to post new answers.
Simple Mockito works for me:
/**
* Unit tests for the CurrencyCFType custom field type.
*/
public class CurrencyCFTypeTest {
@Mock private CustomFieldValuePersister customFieldValuePersister;
@Mock private JiraAuthenticationContext jiraAuthenticationContext;
@Mock private GenericConfigManager genericConfigManager;
@Mock private Issue issue;
@Mock private CustomField customField;
@Mock private I18nHelper i18nHelper;
@Mock private FieldLayoutItem fieldLayoutItem;
private DoubleConverter doubleConverter;
@Before
public void setUp() {
// Create all the mock objects marked with @Mock
MockitoAnnotations.initMocks(this);
doubleConverter = new DoubleConverterImpl(jiraAuthenticationContext);
// This is needed by DoubleConverter getDisplayFormat
when(jiraAuthenticationContext.getI18nHelper()).thenReturn(i18nHelper);
when(i18nHelper.getLocale()).thenReturn(Locale.getDefault());
}
@Test
public void testGetSingularObjectFromString() {
CurrencyCFType currencyCFType = new CurrencyCFType(customFieldValuePersister,
doubleConverter,
genericConfigManager);
assertTrue(currencyCFType.getSingularObjectFromString("10.0").equals(new Double(10.0)));
But more complex methods get stuck pretty quickly:
@Test
public void testVelocityParameters() {
CurrencyCFType currencyCFType = new CurrencyCFType(customFieldValuePersister,
doubleConverter,
genericConfigManager);
// This requires a servlet context for ComponentManager and
// getI18nBean to work. Plain Mockito doesn't handle that well
// but Power Mockito does. For more details see
// https://www.adaptavist.com/display/~jmcgivern/2010/05/09/Unit+Testing+JIRA+with+PowerMock+for+Mockito</pre<>>//Map<String, Object> velocityParams = currencyCFType.getVelocityParameters(issue, customField, fieldLayoutItem);//assertNotNull(velocityParams.get("currencySymbol"));}
Gosh, code formatting is terrible on this new platform!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Wait. the title says you want unit tests but the first line says you want to debug the class. Debug with log messages or a debugger.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Test, I mean test. I guess if you're testing your classes you're automatically debugging them as well, though :P Edited.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
We could bounce that one around for a while :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.