Skip to content

Commit

Permalink
Merge 6219b2d into f605449
Browse files Browse the repository at this point in the history
  • Loading branch information
kompacher committed Sep 18, 2018
2 parents f605449 + 6219b2d commit 55fe289
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 114 deletions.
8 changes: 1 addition & 7 deletions src/main/java/junitparams/JUnitParamsRunner.java
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
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 && runner.count() != 0;
}
}
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
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
@@ -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

This file was deleted.

6 changes: 3 additions & 3 deletions src/test/java/junitparams/internal/TestMethodTest.java
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
43 changes: 43 additions & 0 deletions src/test/java/junitparams/rules/MethodAnnotationInfoTest.java
@@ -0,0 +1,43 @@
package junitparams.rules;

import junitparams.JUnitParamsRunner;
import junitparams.Parameters;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.junit.runners.model.Statement;

import java.lang.annotation.Annotation;
import java.util.Collection;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(JUnitParamsRunner.class)
public class MethodAnnotationInfoTest {

@Rule
public final TestDescription testDescription = new TestDescription();

@Test
@Parameters({""})
public void annotationInfoInDescriptionPresent(String n) {
assertThat(testDescription.getAnnotations()).isNotEmpty();
}

public static class TestDescription implements TestRule {

private Description description;

@Override
public Statement apply(Statement statement, Description description) {
this.description = description;
return statement;
}

Collection<Annotation> getAnnotations() {
return description.getAnnotations();
}
}
}

This file was deleted.

0 comments on commit 55fe289

Please sign in to comment.