Browse files

Merge remote-tracking branch 'remotes/kentbeck/master' into cucumber-…

…jvm-322
  • Loading branch information...
2 parents cfeb604 + daeda1a commit 1c545fd83cc7a59a9062828a3277a578d9150904 Petter Måhlén committed Aug 2, 2012
View
1 README.html
@@ -2,7 +2,6 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="Author" content="Erich Gamma, Kent Beck, and David Saff">
<title>JUnit 4.6</title>
</head>
View
11 src/main/java/org/junit/experimental/theories/Theories.java
@@ -34,9 +34,14 @@ protected void collectInitializationErrors(List<Throwable> errors) {
private void validateDataPointFields(List<Throwable> errors) {
Field[] fields= getTestClass().getJavaClass().getDeclaredFields();
- for (Field each : fields)
- if (each.getAnnotation(DataPoint.class) != null && !Modifier.isStatic(each.getModifiers()))
- errors.add(new Error("DataPoint field " + each.getName() + " must be static"));
+ for (Field field : fields) {
+ if (field.getAnnotation(DataPoint.class) == null)
+ continue;
+ if (!Modifier.isStatic(field.getModifiers()))
+ errors.add(new Error("DataPoint field " + field.getName() + " must be static"));
+ if (!Modifier.isPublic(field.getModifiers()))
+ errors.add(new Error("DataPoint field " + field.getName() + " must be public"));
+ }
}
@Override
View
10 src/main/java/org/junit/rules/TemporaryFolder.java
@@ -52,7 +52,7 @@ protected void after() {
* for testing purposes only. Do not use.
*/
public void create() throws IOException {
- folder = createTemporaryFolderIn(parentFolder);
+ folder= createTemporaryFolderIn(parentFolder);
}
/**
@@ -77,6 +77,14 @@ public File newFile() throws IOException {
* Returns a new fresh folder with the given name under the temporary
* folder.
*/
+ public File newFolder(String folder) {
+ return newFolder(new String[]{folder});
+ }
+
+ /**
+ * Returns a new fresh folder with the given name(s) under the temporary
+ * folder.
+ */
public File newFolder(String... folderNames) {
File file= getRoot();
for (String folderName : folderNames) {
View
12 src/test/java/org/junit/internal/MethodSorterTest.java
@@ -17,18 +17,18 @@
private static final String DELTA= "void delta()";
private static final String EPSILON= "void epsilon()";
- private static class Dummy {
+ static class Dummy {
Object alpha(int i, double d, Thread t) {return null;}
void beta(int[][] x) {}
int gamma() {return 0;}
void gamma(boolean b) {}
void delta() {}
void epsilon() {}
}
- private static class Super {
+ static class Super {
void testOne() {}
}
- private static class Sub extends Super {
+ static class Sub extends Super {
void testTwo() {}
}
@@ -48,7 +48,7 @@ private String declaredMethods(Class<?> clazz) {
}
@FixMethodOrder(MethodSorters.DEFAULT)
- private static class DummySortWithDefault {
+ static class DummySortWithDefault {
Object alpha(int i, double d, Thread t) {return null;}
void beta(int[][] x) {}
int gamma() {return 0;}
@@ -63,7 +63,7 @@ void epsilon() {}
}
@FixMethodOrder(MethodSorters.JVM)
- private static class DummySortJvm {
+ static class DummySortJvm {
Object alpha(int i, double d, Thread t) {return null;}
void beta(int[][] x) {}
int gamma() {return 0;}
@@ -80,7 +80,7 @@ void epsilon() {}
}
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
- private static class DummySortWithNameAsc {
+ static class DummySortWithNameAsc {
Object alpha(int i, double d, Thread t) {return null;}
void beta(int[][] x) {}
int gamma() {return 0;}
View
23 src/test/java/org/junit/tests/experimental/rules/TempFolderRuleTest.java
@@ -11,6 +11,7 @@
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Method;
import java.util.Arrays;
import org.junit.After;
@@ -43,14 +44,30 @@ public void tempFolderIsDeleted() {
public TemporaryFolder folder= new TemporaryFolder();
@Test
- public void testUsingTempFolder() throws IOException {
+ public void testUsingTempFolderStringReflection() throws Exception {
String subfolder = "subfolder";
String filename = "a.txt";
+ // force usage of folder.newFolder(String),
+ // check is available and works, to avoid a potential NoSuchMethodError with non-recompiled code.
+ Method method = folder.getClass().getMethod("newFolder", new Class<?>[] {String.class});
+ createdFiles[0]= (File) method.invoke(folder, subfolder);
+ new File(createdFiles[0], filename).createNewFile();
+
+ File expectedFile = new File(folder.getRoot(), join(subfolder, filename));
+
+ assertTrue(expectedFile.exists());
+ }
+
+ @Test
+ public void testUsingTempFolderString() throws IOException {
+ String subfolder = "subfolder";
+ String filename = "a.txt";
+ // this uses newFolder(String), ensure that a single String works
createdFiles[0]= folder.newFolder(subfolder);
new File(createdFiles[0], filename).createNewFile();
-
+
File expectedFile = new File(folder.getRoot(), join(subfolder, filename));
-
+
assertTrue(expectedFile.exists());
}
View
35 ...st/java/org/junit/tests/experimental/theories/runner/UnsuccessfulWithDataPointFields.java
@@ -84,10 +84,10 @@ public void nullsUsedUnlessProhibited() throws Exception {
@RunWith(Theories.class)
public static class DataPointsMustBeStatic {
@DataPoint
- int THREE= 3;
+ public int THREE= 3;
@DataPoint
- int FOUR= 3;
+ public int FOUR= 4;
@Theory
public void numbers(int x) {
@@ -123,4 +123,35 @@ public void theoriesMustBePublic() {
testResult(TheoriesMustBePublic.class),
hasSingleFailureContaining("public"));
}
+
+ @RunWith(Theories.class)
+ public static class DataPointsMustBePublic {
+ @DataPoint
+ static int THREE= 3;
+
+ @DataPoint
+ protected static int FOUR= 4;
+
+ @SuppressWarnings("unused")
+ @DataPoint
+ private static int FIVE= 5;
+
+ @Theory
+ public void numbers(int x) {
+
+ }
+ }
+
+ @Test
+ public void dataPointsMustBePublic() {
+ assertThat(
+ testResult(DataPointsMustBePublic.class),
+ both(failureCountIs(3))
+ .and(
+ hasFailureContaining("DataPoint field THREE must be public"))
+ .and(
+ hasFailureContaining("DataPoint field FOUR must be public"))
+ .and(
+ hasFailureContaining("DataPoint field FIVE must be public")));
+ }
}

0 comments on commit 1c545fd

Please sign in to comment.