Skip to content

Commit

Permalink
Revert "Fix for #120 - proper description (with correct method name) …
Browse files Browse the repository at this point in the history
…passed to Rules"

This reverts commit bbceaa2.
  • Loading branch information
kompacher committed Sep 21, 2018
1 parent 433961e commit a8e633a
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 84 deletions.
8 changes: 1 addition & 7 deletions src/main/java/junitparams/JUnitParamsRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ protected void runChild(FrameworkMethod method, RunNotifier notifier) {
super.runChild(method, notifier);
}
}

private boolean initializedProperly(Statement statement, RunNotifier notifier) {
boolean initializedProperly = true;
if (statement instanceof Fail) {
Expand All @@ -470,12 +470,6 @@ private boolean initializedProperly(Statement statement, RunNotifier notifier) {
return initializedProperly;
}

@Override
protected Description describeChild(FrameworkMethod method) {
Description description = parameterisedRunner.getDescriptionFor(method);
return description == null ? super.describeChild(method) : description;
}

private void verifyMethodCanBeRunByStandardRunner(TestMethod testMethod) {
List<Throwable> errors = new ArrayList<Throwable>();
testMethod.frameworkMethod().validatePublicVoidNoArg(false, errors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Description describeParameterisedMethod(FrameworkMethod method) {
if (!testMethod.isParameterised())
return null;

return testMethod.description();
return testMethod.describe();
}

/**
Expand All @@ -174,24 +174,4 @@ public TestMethod testMethodFor(FrameworkMethod method) {
return testMethods.get(method);
}

/**
* Returns description of parametrized method for given set of parameters (considering test name convention
* given with @{@link junitparams.naming.TestCaseName}). If method is not parametrized or runner has not been created yet
* returns null.
*
* @param method
* @return description of given method
*/
public Description getDescriptionFor(FrameworkMethod method) {
TestMethod testMethod = testMethodFor(method);
if (shouldRun(testMethod)) {
ParameterisedTestMethodRunner runner = parameterisedMethods.get(testMethod);
return wasInvoked(runner) ? runner.currentTestDescription() : null;
}
return null;
}

private boolean wasInvoked(ParameterisedTestMethodRunner runner) {
return runner != null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Object currentParamsFromAnnotation() {
}

void runTestMethod(Statement methodInvoker, RunNotifier notifier) {
Description methodWithParams = findChildForParams(methodInvoker, method.description());
Description methodWithParams = findChildForParams(methodInvoker, method.describe());

runMethodInvoker(notifier, methodInvoker, methodWithParams);
}
Expand Down Expand Up @@ -105,8 +105,4 @@ private Statement getOriginalStatement(Statement methodInvoker, Field field) {
return null;
}
}

Description currentTestDescription() {
return method.description().getChildren().get(count - 1);
}
}
9 changes: 5 additions & 4 deletions src/main/java/junitparams/internal/TestMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
return frameworkMethodAnnotations.getAnnotation(annotationType);
}

Description describe() {
return description.get();
}


public Object[] parametersSets() {
return parameters.get();
}
Expand All @@ -128,8 +133,4 @@ public FrameworkMethod frameworkMethod() {
boolean isParameterised() {
return frameworkMethodAnnotations.isParametrised();
}

Description description() {
return description.get();
}
}
3 changes: 1 addition & 2 deletions src/test/java/junitparams/RulesTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package junitparams;

import junitparams.naming.TestCaseName;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ErrorCollector;
Expand Down Expand Up @@ -32,9 +31,9 @@ public class RulesTest {
@Rule
public Timeout timeout = new Timeout(0);


@Test
@Parameters("")
@TestCaseName("{method}")
public void shouldHandleRulesProperly(String n) {
assertThat(testName.getMethodName()).isEqualTo("shouldHandleRulesProperly");
}
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/junitparams/internal/TestMethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void forOthersToWorkWithArray(String... arg) throws Exception {
public void flatTestMethodStructure() throws Exception {
System.setProperty("JUnitParams.flat", "true");

Description description = plainTestMethod.description();
Description description = plainTestMethod.describe();

assertEquals("for_others_to_work(junitparams.internal.TestMethodTest)", description.getDisplayName());
assertTrue(description.getChildren().isEmpty());
Expand All @@ -57,7 +57,7 @@ public void flatTestMethodStructure() throws Exception {
@Test
public void hierarchicalTestMethodStructure() throws Exception {
System.clearProperty("JUnitParams.flat");
Description description = plainTestMethod.description();
Description description = plainTestMethod.describe();

assertEquals("forOthersToWork", description.getDisplayName());
assertEquals("forOthersToWork(a) [0](junitparams.internal.TestMethodTest)", description.getChildren().get(0).getDisplayName());
Expand All @@ -67,7 +67,7 @@ public void hierarchicalTestMethodStructure() throws Exception {
@Test
public void hierarchicalArrayTestMethodStructure() throws Exception {
System.clearProperty("JUnitParams.flat");
Description description = arrayTestMethod.description();
Description description = arrayTestMethod.describe();

assertEquals("forOthersToWorkWithArray", description.getDisplayName());
assertEquals("forOthersToWorkWithArray(a,b) [0](junitparams.internal.TestMethodTest)",
Expand Down

This file was deleted.

0 comments on commit a8e633a

Please sign in to comment.