shivadorepally / junitparams

Automatically exported from code.google.com/p/junitparams
0 stars 0 forks source link

Cannot use empty string ("") as a value of the @Parameters annotation #33

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

The following test will reproduce the bug:
@Test
@Parameters({ "chocolate", "", " " })
public void should_do_some_fancy_stuff(String name) throws Exception {
    // ...
}

What is the expected output? What do you see instead?

The three tests are created as expected
1) "chocolate (should_do_some_fancy_stuff)"
2) "  (should_do_some_fancy_stuff)"
3) "   (should_do_some_fancy_stuff)"

Test 1 and Test 3 are performed as expected.
But for the 2nd test the test runner throws an exception (see attached file for 
complete stack trace):
java.lang.IllegalArgumentException: Cannot parse parameters. Did you use , as 
column separator? 
    at junitparams.internal.InvokeParameterisedMethod.castParamsFromString(InvokeParameterisedMethod.java:85)
    ...
Caused by: java.lang.IllegalArgumentException: Number of parameters inside 
@Parameters annotation doesn't match the number of test method parameters.
There are 0 parameters in annotation, while there's 1 parameters in the 
should_do_some_fancy_stuff method.
    ...

java.lang.IllegalArgumentException: wrong number of arguments
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    ...

What version of the product are you using? On what operating system?

Occurs in JUnitParams 0.5.0 and 0.9.0
Operating system Linux (Mint 12)

Please provide any additional information below.

The issue does not occur, when I have use a method supplying the parameters and 
place the strings each into its own array:
private Object[] provideStrings() {
    return $( $("chocolate"), $(""), $(" ") );
}
@Test
@Parameters(method = "provideStrings")
public void should_do_some_fancy_stuff(String name) throws Exception {
    // ...
}

However, for such a simple list of parameters it is quite cumbersome.

I would be very happy if you could fix this bug :-)

--

Regards
Daniel

Original issue reported on code.google.com by daniel.h...@zimory.com on 18 Jan 2013 at 2:20

Attachments:

GoogleCodeExporter commented 8 years ago
I was curious and had a look into the code. 

This issue might be fixed by just changing the following line in 
junitparams/internal/InvokeParameterisedMethod.java

if (colls.length == 1 && "".equals(colls[0]))

to

if (colls.length == 1 && "".equals(colls[0]) && numberOfParams != 1)

This test succeeds:

@Test
@Parameters({ "" })
public void singleEmptyParam(String empty) {
    assertThat(empty, is(""));
}

... and all other JUnit tests work as expected.

--

Regards
Daniel

Original comment by daniel.h...@zimory.com on 18 Jan 2013 at 7:53

GoogleCodeExporter commented 8 years ago

Original comment by lipinski...@gmail.com on 13 Mar 2013 at 12:53