--- In
junit@..., Ole Ersoy <ole_ersoy@...> wrote:
{clip}
> What about
>
> public String append(String a, String b)
>
> return a+b;
>
> This is 100% tested too, assuming all valid java
> strings are ok.
Ole, forgive me if I'm missing your point, but I'm curious why,
assuming you even have a valid reason to write the above util method,
it is not worthy of a few tests.
Granted, I'm a bit of a perfectionist sometimes, but the above to me
begs at least boundary tests, particularly "null tests". What would
you expect this to do when given nulls? It wasn't obvious to me, so I
wrote a few tests (and, honestly, was surprised by the outcome):
@RunWith(Parameterized.class)
public class StringUtilTest {
class StringUtil {
String append(String a, String b) {
return a + b;
}
}
private String first;
private String second;
private String expected;
@Parameters
public static Collection data() {
return Arrays.asList(new Object[][]{
{null, null, "nullnull"},
{null, "2", "null2"},
{"1", null, "1null"},
{"", "", ""},
{"1", "2", "12"},
});
}
public StringUtilTest(String first, String second, String expected) {
this.first = first;
this.second = second;
this.expected = expected;
}
@Test public void Append(){
assertEquals(expected, new StringUtil().append(first, second));
}
}
Is this, in your opinion, overkill [and paranoid :-)]?
Cheers...
--MB