Skip to content

Commit

Permalink
Merge pull request junit-team#903 from baev/master
Browse files Browse the repository at this point in the history
Description.getMethodName() should not return null. Fixes junit-team#892
  • Loading branch information
kcooney committed May 14, 2014
2 parents ad09a5c + 5d05993 commit 950702c
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/org/junit/runner/Description.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Description implements Serializable {
private static final long serialVersionUID = 1L;

private static final Pattern METHOD_AND_CLASS_NAME_PATTERN = Pattern
.compile("(.*)\\((.*)\\)");
.compile("([\\s\\S]*)\\((.*)\\)");

/**
* Create a <code>Description</code> named <code>name</code>.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.junit.runners.parameterized;

import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.Request;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.assertEquals;

/**
* @author Dmitry Baev [email protected]
* Date: 03.05.14
*/
public class ParameterizedNamesTest {
@RunWith(Parameterized.class)
public static class ParametrizedWithSpecialCharsInName {

@SuppressWarnings("unused")
public ParametrizedWithSpecialCharsInName(String s) {
}

@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[]{"\n"},
new Object[]{"\r\n"},
new Object[]{"\r"},
new Object[]{"\u0085"},
new Object[]{"\u2028"},
new Object[]{"\u2029"}
);
}

@Test
public void test() {
}
}

@Test
public void parameterizedTestsWithSpecialCharsInName() {
Request request = Request.aClass(ParametrizedWithSpecialCharsInName.class);
for (Description parent : request.getRunner().getDescription().getChildren()) {
for (Description description : parent.getChildren()) {
assertEquals("test" + parent.getDisplayName(), description.getMethodName());
}
}
}
}
4 changes: 4 additions & 0 deletions src/test/java/org/junit/tests/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
import org.junit.runners.model.FrameworkFieldTest;
import org.junit.runners.model.FrameworkMethodTest;
import org.junit.runners.model.TestClassTest;
import org.junit.runners.parameterized.ParameterizedNamesTest;
import org.junit.runners.parameterized.TestWithParametersTest;
import org.junit.tests.assertion.AssertionTest;
import org.junit.tests.assertion.ComparisonFailureTest;
import org.junit.tests.assertion.MultipleFailureExceptionTest;
import org.junit.tests.deprecated.JUnit4ClassRunnerTest;
import org.junit.tests.description.AnnotatedDescriptionTest;
import org.junit.tests.description.SuiteDescriptionTest;
import org.junit.tests.description.TestDescriptionMethodNameTest;
import org.junit.tests.description.TestDescriptionTest;
import org.junit.tests.experimental.AssumptionTest;
import org.junit.tests.experimental.ExperimentalTests;
Expand Down Expand Up @@ -113,6 +115,7 @@
ListenerTest.class,
FailedConstructionTest.class,
TestDescriptionTest.class,
TestDescriptionMethodNameTest.class,
SuiteDescriptionTest.class,
AllTestsTest.class,
AnnotationTest.class,
Expand Down Expand Up @@ -204,6 +207,7 @@
FailOnTimeoutTest.class,
JUnitCoreTest.class,
TestWithParametersTest.class,
ParameterizedNamesTest.class,
PublicClassValidatorTest.class
})
public class AllTests {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.junit.tests.description;

import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import java.util.Arrays;
import java.util.Collection;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
* @author Dmitry Baev [email protected]
* Date: 03.05.14
*/
@RunWith(Parameterized.class)
public class TestDescriptionMethodNameTest {

private String methodName;

public TestDescriptionMethodNameTest(String methodName) {
this.methodName = methodName;
}

@Parameterized.Parameters
public static Collection<Object[]> getMethodNames() {
return Arrays.asList(
new Object[]{"simple"},
new Object[]{"with space"},
new Object[]{"[]!@#$%^&*()"},
new Object[]{""},
new Object[]{"\t"},
new Object[]{"\n"},
new Object[]{"\r\n"},
new Object[]{"\r"},
new Object[]{"\u0085"},
new Object[]{"\u2028"},
new Object[]{"\u2029"}
);
}

@Test
public void methodNameTest() throws Exception {
Description description = Description.createTestDescription("some-class-name", methodName);
assertNotNull("Method name should be not null", description.getMethodName());
assertEquals(methodName, description.getMethodName());
}
}

0 comments on commit 950702c

Please sign in to comment.