shivadorepally / junitparams

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

String parameters with line-endings (\r, \n) cause a NullPointerException #41

Closed GoogleCodeExporter closed 8 years ago

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

1. Create a parameterized unit test that has at least one String parameter and 
runs with JUnitParamsRunner.
2. Put line feeds in one or more String parameters (e.g. "\r", "\n").
3. Execute your test with the offending string(s) as inputs and watch it fail.

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

Expected output is that the tests will be passed the strings as-is.

Actual output is a NullPointerException. Example:

java.lang.NullPointerException: null
        at junitparams.internal.ParameterisedTestMethodRunner.findChildForParams(ParameterisedTestMethodRunner.java:60)
        at junitparams.internal.ParameterisedTestMethodRunner.runTestMethod(ParameterisedTestMethodRunner.java:39)
        at junitparams.internal.ParameterisedTestClassRunner.runParameterisedTest(ParameterisedTestClassRunner.java:143)
        at junitparams.JUnitParamsRunner.runChild(JUnitParamsRunner.java:405)
        at junitparams.JUnitParamsRunner.runChild(JUnitParamsRunner.java:383)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at org.junit.runners.Suite.runChild(Suite.java:127)
        at org.junit.runners.Suite.runChild(Suite.java:26)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
        at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.createReqestAndRun(JUnitCoreWrapper.java:139)
        at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.executeEager(JUnitCoreWrapper.java:111)
        at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:84)
        at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray2(ReflectionUtils.java:208)
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:158)
        at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:86)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:153)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:95)

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

JUnitParams 1.0.0 on Windows 7, 64-bit, using JUnit 4.11, Maven 3.0.5, and JDK 
7u17.

Please provide any additional information below.

See attached test cases. String parameters that are null cause the same error. 
Notice also that this error kills the test runner, so that none of the other 
tests will execute once this error has occurred.

Original issue reported on code.google.com by ngr...@inco5.com on 27 Mar 2013 at 8:11

Attachments:

GoogleCodeExporter commented 8 years ago
After hunting through the closed issues, this looks like a duplicate of #31
I grabbed the latest source code and couldn't build without skipping tests due 
to failures from this exact defect. I can confirm that my test case indeed 
fails against the latest code in trunk (1.0.1-SNAPSHOT). I wish I had time to 
code a patch for you.

Original comment by ngr...@inco5.com on 27 Mar 2013 at 8:24

GoogleCodeExporter commented 8 years ago
I created a patch that seems to work for me.

Original comment by ngr...@inco5.com on 29 Mar 2013 at 7:22

Attachments:

GoogleCodeExporter commented 8 years ago
The problem was actually not in JUnitParams, but in the way JUnit stores test 
method description. Your fix just skipped such "wrong" test instead of working 
around the JUnit problem by skipping the '\r' in the test description. Now it's 
ok, will be released with 1.0.1 still today.

Original comment by pawel.li...@pragmatists.pl on 4 Apr 2013 at 8:51

GoogleCodeExporter commented 8 years ago

Original comment by lipinski...@gmail.com on 4 Apr 2013 at 8:51

GoogleCodeExporter commented 8 years ago
I see... It now handles carriage returns and nulls, but line feeds still fail:

@Test
@Parameters({ "\n" })
public void causeSimpleRunnerNPE(String param1) {
    assertNotNull("param1", param1);
}

Original comment by ngr...@inco5.com on 4 Apr 2013 at 9:35

GoogleCodeExporter commented 8 years ago
I should say, the line feeds fail on Windows, where 
System.getProperty("line.separator") returns \r\n

Original comment by ngr...@inco5.com on 4 Apr 2013 at 9:36

GoogleCodeExporter commented 8 years ago
Since this issue is closed I opened new issue for fixing the bug introduced by 
fix for this issue:
http://code.google.com/p/junitparams/issues/detail?id=46

Original comment by jankowsk...@gmail.com on 9 Jul 2013 at 3:24