Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@DataPoints-related fixes #328

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,17 @@ public List<PotentialAssignment> getValueSources(ParameterSignature sig) {

private void addMultiPointMethods(List<PotentialAssignment> list) {
for (FrameworkMethod dataPointsMethod : fClass
.getAnnotatedMethods(DataPoints.class))
.getAnnotatedMethods(DataPoints.class)) {
if (!dataPointsMethod.isStatic()) {
throw new RuntimeException("The @" + DataPoints.class.getSimpleName() +
" annotation is illegal for the method " + dataPointsMethod.getName() + " because it is not static.");
}
try {
addArrayValues(dataPointsMethod.getName(), list, dataPointsMethod.invokeExplosively(null));
} catch (Throwable e) {
// ignore and move on
throw new RuntimeException("Method " + dataPointsMethod.getName() + " threw " + e, e);
}
}
}

@SuppressWarnings("deprecation")
Expand Down
35 changes: 35 additions & 0 deletions src/test/java/org/junit/tests/experimental/theories/Issue125.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.junit.tests.experimental.theories;

import org.junit.Test;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.runner.RunWith;

/**
* Test for Issue #125
*/
@RunWith(Theories.class)
public class Issue125 {

int theInteger;

@DataPoints
public static Integer[] dataPoints1() {
return new Integer[] {1,2};
}

// this is not static, so we should get a warning
@DataPoints
public Integer[] dataPoints2() {
return new Integer[] {3,4};
}

public Issue125(int i) {
theInteger = i;
}

@Test
public void test() {
System.out.println("Running test method for " + theInteger);
}
}
36 changes: 36 additions & 0 deletions src/test/java/org/junit/tests/experimental/theories/Issue137.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.junit.tests.experimental.theories;

import org.junit.Test;
import org.junit.experimental.categories.Categories.ExcludeCategory;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.runner.RunWith;

/**
* Test for Issue #137
*/
@RunWith(Theories.class)
public class Issue137 {

int theInteger;

@DataPoints
public static Integer[] dataPoints1() {
return new Integer[] {1,2};
}

// this throws an error, so we should see that error when running tests
@DataPoints
public static Integer[] dataPoints2() {
throw new RuntimeException("throwing exception from dataPoints2!");
}

public Issue137(int i) {
theInteger = i;
}

@Test
public void test() {
System.out.println("Running test method for " + theInteger);
}
}