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
{{ message }}
Repository navigation
[java] UseObjectForClearerAPI conflicts with TestNG DataProvider #1867
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);
}
Activity
adangel commentedon Jun 14, 2019
We could add an exception for methods, annotated with TestNG's
@Testannotation.UncleOwen commentedon Jun 19, 2026
ExcessiveParameterList suffers from the same problem
UncleOwen commentedon Jun 19, 2026
... and an exception for methods that override a superclass method. Nothing you can do about the long parameter list in that case. See #3741 (comment)