forked from junit-team/junit4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request junit-team#903 from baev/master
Description.getMethodName() should not return null. Fixes junit-team#892
- Loading branch information
Showing
4 changed files
with
107 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/test/java/org/junit/runners/parameterized/ParameterizedNamesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/test/java/org/junit/tests/description/TestDescriptionMethodNameTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} |