You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The UseObjectForClearerAPI rule doesn't work well with parameterised unit test APIs such as TestNG's DataProvider. With DataProvider, it's perfectly normal and usable to pass a bunch of strings (or other objects) to a method.
Code Sample demonstrating the issue:
@DataProvider(name = "dataProvider")
public Object[][] subjectLines() {
return new Object[][] {
// title, givenName, surname, organisation, receiptNumber, date, expected
{ "Mr", "Harry", "Walsh", "ABC Corporation", "1650028", new LocalDate(2009, 5, 27), "Right to Information Application - Mr Harry Walsh ABC Corporation (Receipt No: 1650028) - 27-05-2009" },
{ null, "Harry", "Walsh", null, "1650027", new LocalDate(2009, 5, 26), "Right to Information Application - Harry Walsh (Receipt No: 1650027) - 26-05-2009" },
{ null, null, null, "ABC Corporation", "1650026", new LocalDate(2009, 4, 1), "Right to Information Application - ABC Corporation (Receipt No: 1650026) - 01-04-2009" },
{ null, null, null, null, "1650025", new LocalDate(2008, 1, 27), "Right to Information Application - (Receipt No: 1650025) - 27-01-2008" },
};
}
@Test(dataProvider = "dataProvider")
public void shouldBuildSubjectLineWithDetailsSupplied(String title, String givenName, String surname, String organisation, String receiptNumber, LocalDate date, String expected) {
when(orderDetails.getNameTitle()).thenReturn(title);
when(orderDetails.getGivenName()).thenReturn(givenName);
when(orderDetails.getFamilyName()).thenReturn(surname);
when(orderDetails.getOrganisationName()).thenReturn(organisation);
when(orderStatus.getReceiptNumber()).thenReturn(receiptNumber);
String actual = builder.buildSubjectLine(orderDetails, orderStatus);
assertThat(actual).isEqualTo(expected);
}
Running PMD through: Maven
The text was updated successfully, but these errors were encountered:
Affects PMD Version: 6.11.0
Rule: UseObjectForClearerAPI
Description:
The
UseObjectForClearerAPI
rule doesn't work well with parameterised unit test APIs such as TestNG'sDataProvider
. With DataProvider, it's perfectly normal and usable to pass a bunch of strings (or other objects) to a method.Code Sample demonstrating the issue:
Running PMD through: Maven
The text was updated successfully, but these errors were encountered: