shivadorepally / junitparams

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

Newline in test parameter value causes NullPointerException #61

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
If a test parameter value has a newline character in it, 
ParameterisedTestMethodRunner throws a NullPointerException (Stack trace is 
below). Below is a simple class and corresponding test. Running the test causes 
the NPE shown.

public class TextUtils
{
    public static String normalize(CharSequence text)
    {
        return text.toString().toUpperCase();
    }
}

import org.junit.Test;
import org.junit.runner.RunWith;

import junitparams.JUnitParamsRunner;
import junitparams.Parameters;

import static junitparams.JUnitParamsRunner.$;
import static org.junit.Assert.assertEquals;

@RunWith(JUnitParamsRunner.class)
public class TextUtilsTest
{
    @Test
    @Parameters(method = "normalizeValues")
    public void testNormalize(String text, String expected)
    {
        assertEquals("Wrong result", expected, TextUtils.normalize(text));
    }

    private Object[] normalizeValues()
    {
        return $(
            $("This and\nthat", "THIS AND\nTHAT")
        );
    }
}

java.lang.NullPointerException
    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.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    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:606)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

Original issue reported on code.google.com by scsi_dev...@yahoo.com on 7 May 2014 at 3:09

GoogleCodeExporter commented 8 years ago
Same probleme here.
This case should be fixed by allowing *METHOD_AND_CLASS_NAME_PATTERN* to match 
carriage return with dot.

{{{
at org.junit.runner.Description(32)
    private static final Pattern METHOD_AND_CLASS_NAME_PATTERN = Pattern
-            .compile("(.*)\\((.*)\\)");
+            .compile("(.*)\\((.*)\\)", Pattern.DOTALL);
}}}

Not tested, but should do the trick.

Original comment by jonathan...@gmail.com on 14 May 2014 at 9:04

GoogleCodeExporter commented 8 years ago
Works fine with 1.0.3

Original comment by lipinski...@gmail.com on 28 Jul 2014 at 12:42