From 0fdec440b59be32e16a084a2ff6fd7a596da2c8f Mon Sep 17 00:00:00 2001 From: Tibor Digana Date: Tue, 15 Jan 2013 18:37:52 +0100 Subject: [PATCH 01/18] Prepare for Maven release --- doc/building-junit.txt | 9 ++++--- pom.xml | 40 ++++++++++------------------- src/main/config/settings.xml | 50 +++++++++++++++--------------------- 3 files changed, 41 insertions(+), 58 deletions(-) diff --git a/doc/building-junit.txt b/doc/building-junit.txt index 76ae9e3d651a..7bfd48c0e810 100644 --- a/doc/building-junit.txt +++ b/doc/building-junit.txt @@ -2,13 +2,16 @@ Steps to build junit: - Must be manual - Write release notes - - Update version in pom.xml + - Update SNAPSHOT version in pom.xml - Not too tedious: - Push to github (dsaff _and_ KentBeck) - Run the mvn clean install - Upload stuff to github (including tag) - - Push to maven - - mvn -Dgpg.passphrase="" -Psign clean deploy + - If not done, update src/main/config/settings.xml in /private/.../settings.xml on CloudBees' webdav share. + - If not done, copy GnuPG keys in to ${gpg.homedir}. See settings.xml. + - Perform Maven Release in Jenkins + - (to deploy snapshot version) mvn clean deploy + - (to deploy specified release version) mvn clean release:prepare release:perform - Promote - Tedious: - Update SourceForge if major release diff --git a/pom.xml b/pom.xml index 7f53e558ba44..732b6be96772 100644 --- a/pom.xml +++ b/pom.xml @@ -68,21 +68,14 @@ https://github.com/KentBeck/junit/wiki/Download-and-Install - - maven-central-snapshots - upload.to.maven.central.snapshots + junit-snapshot-repo + Nexus Snapshot Repository https://oss.sonatype.org/content/repositories/snapshots/ - - maven-central - upload.to.maven.central + junit-releases-repo + Nexus Release Repository https://oss.sonatype.org/service/local/staging/deploy/maven2/ @@ -98,20 +91,6 @@ - - - - org.apache.maven.wagon - wagon-http - 1.0 - - diff --git a/src/main/config/settings.xml b/src/main/config/settings.xml index 2b91113182c7..55daae15a2de 100644 --- a/src/main/config/settings.xml +++ b/src/main/config/settings.xml @@ -1,6 +1,6 @@  - maven-central - ??? - ??? - 664 - 775 - - 15000 - - - 15000 - 15000 - - - + junit-snapshot-repo + + - maven-central-snapshots - ??? - ??? - 664 - 775 - - 15000 - - - 15000 - 15000 - - - + junit-releases-repo + + + + + junit-release + + ... + ... + false + true + /private/.../.gnupg + /private/.../.gnupg/pubring.gpg + /private/.../.gnupg/secring.gpg + + + From 57801df202ebf6926ab93611adfc0a10667346b6 Mon Sep 17 00:00:00 2001 From: Tibor Digana Date: Tue, 15 Jan 2013 23:24:21 +0100 Subject: [PATCH 02/18] promoting released artifacts and closed staging --- doc/building-junit.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/building-junit.txt b/doc/building-junit.txt index 7bfd48c0e810..60486d1d34b4 100644 --- a/doc/building-junit.txt +++ b/doc/building-junit.txt @@ -12,7 +12,7 @@ Steps to build junit: - Perform Maven Release in Jenkins - (to deploy snapshot version) mvn clean deploy - (to deploy specified release version) mvn clean release:prepare release:perform - - Promote + - Promote the maven artifacts and close staging repository if release successfully - Tedious: - Update SourceForge if major release - Update javadocs on github site (and "latest" link) From 59f3fa6ea11433ffd914e6c2032cdad0036f435e Mon Sep 17 00:00:00 2001 From: Tibor Digana Date: Wed, 16 Jan 2013 19:52:34 +0100 Subject: [PATCH 03/18] removed settings.xml, updated building-junit.txt and pom.xml --- doc/building-junit.txt | 50 +++++++++++++++++++++++++++++++++--- pom.xml | 3 +++ src/main/config/settings.xml | 48 ---------------------------------- 3 files changed, 49 insertions(+), 52 deletions(-) delete mode 100644 src/main/config/settings.xml diff --git a/doc/building-junit.txt b/doc/building-junit.txt index 60486d1d34b4..913c282aabe8 100644 --- a/doc/building-junit.txt +++ b/doc/building-junit.txt @@ -9,10 +9,13 @@ Steps to build junit: - Upload stuff to github (including tag) - If not done, update src/main/config/settings.xml in /private/.../settings.xml on CloudBees' webdav share. - If not done, copy GnuPG keys in to ${gpg.homedir}. See settings.xml. - - Perform Maven Release in Jenkins - - (to deploy snapshot version) mvn clean deploy - - (to deploy specified release version) mvn clean release:prepare release:perform - - Promote the maven artifacts and close staging repository if release successfully + - Perform Maven deployment of a snapshot or release version in Jenkins + - (to deploy snapshot version) + mvn clean deploy + - (to deploy specified release version in non-interactive mode -B) + An example with the next development version and deploying release version: + mvn -B -DreleaseVersion=4.12 -DdevelopmentVersion=4.13-SNAPSHOT clean release:prepare release:perform + - Promote the maven artifacts and close staging repository if released successfully - Tedious: - Update SourceForge if major release - Update javadocs on github site (and "latest" link) @@ -20,3 +23,42 @@ Steps to build junit: - Put release notes on github. - Announce on blog, user list, dev list, announce list, junit.org, twitter - Profit! + + +=================================================================================== +== Internal template of Maven settings used by JUnit build machine. == +== settings.xml == +=================================================================================== + + + + + junit-snapshot-repo + + + + + junit-releases-repo + + + + + + + junit-release + + + + ... + false + true + /private/.../.gnupg + /private/.../.gnupg/pubring.gpg + /private/.../.gnupg/secring.gpg + + + + +=================================================================================== \ No newline at end of file diff --git a/pom.xml b/pom.xml index 732b6be96772..320a0bd8cada 100644 --- a/pom.xml +++ b/pom.xml @@ -299,6 +299,9 @@ + + junit + diff --git a/src/main/config/settings.xml b/src/main/config/settings.xml deleted file mode 100644 index 55daae15a2de..000000000000 --- a/src/main/config/settings.xml +++ /dev/null @@ -1,48 +0,0 @@ - - - - - - - - - - junit-snapshot-repo - - - - - junit-releases-repo - - - - - - - junit-release - - ... - ... - false - true - /private/.../.gnupg - /private/.../.gnupg/pubring.gpg - /private/.../.gnupg/secring.gpg - - - - From a83de0f2964507e123192272674d7485788d9f42 Mon Sep 17 00:00:00 2001 From: Tibor Digana Date: Wed, 16 Jan 2013 22:21:32 +0100 Subject: [PATCH 04/18] public GnuPG key 67893CC4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 320a0bd8cada..406120e6b4a8 100644 --- a/pom.xml +++ b/pom.xml @@ -300,7 +300,7 @@ - junit + 67893CC4 From 4908f0a00860ce91cdff0bc0941bc7aa58dc7974 Mon Sep 17 00:00:00 2001 From: Tibor Digana Date: Thu, 17 Jan 2013 02:13:24 +0100 Subject: [PATCH 05/18] -Dtag=4.12 --- doc/building-junit.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/building-junit.txt b/doc/building-junit.txt index 913c282aabe8..f388c3036afb 100644 --- a/doc/building-junit.txt +++ b/doc/building-junit.txt @@ -14,7 +14,7 @@ Steps to build junit: mvn clean deploy - (to deploy specified release version in non-interactive mode -B) An example with the next development version and deploying release version: - mvn -B -DreleaseVersion=4.12 -DdevelopmentVersion=4.13-SNAPSHOT clean release:prepare release:perform + mvn -B -Dtag=4.12 -DreleaseVersion=4.12 -DdevelopmentVersion=4.13-SNAPSHOT clean release:prepare release:perform - Promote the maven artifacts and close staging repository if released successfully - Tedious: - Update SourceForge if major release From aa707472cbdfd2f5a0025f423a2c4053549ba819 Mon Sep 17 00:00:00 2001 From: Tibor Digana Date: Thu, 17 Jan 2013 10:36:17 +0100 Subject: [PATCH 06/18] removed "Update SNAPSHOT version in pom.xml" "Upload stuff to github (including tag)" --- doc/building-junit.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/building-junit.txt b/doc/building-junit.txt index f388c3036afb..7d589f29da62 100644 --- a/doc/building-junit.txt +++ b/doc/building-junit.txt @@ -2,11 +2,9 @@ Steps to build junit: - Must be manual - Write release notes - - Update SNAPSHOT version in pom.xml - Not too tedious: - Push to github (dsaff _and_ KentBeck) - Run the mvn clean install - - Upload stuff to github (including tag) - If not done, update src/main/config/settings.xml in /private/.../settings.xml on CloudBees' webdav share. - If not done, copy GnuPG keys in to ${gpg.homedir}. See settings.xml. - Perform Maven deployment of a snapshot or release version in Jenkins From a8542a85773d108fa7f2577a0aee8709b8de3b54 Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Thu, 17 Jan 2013 10:06:13 +0000 Subject: [PATCH 07/18] Apply the canonical ordering of pom.xml elements * You are not required to use the canonical ordering, but it makes it easier if you follow the conventions and follow it. --- pom.xml | 62 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/pom.xml b/pom.xml index 406120e6b4a8..88bd9ad10365 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,4 @@ - + 4.0.0 @@ -7,20 +7,13 @@ 4.12-SNAPSHOT JUnit - http://junit.org JUnit is a unit testing framework for Java, created by Erich Gamma and Kent Beck. + http://junit.org + 2002 JUnit http://www.junit.org - 2002 - - - JUnit Mailing List - junit@yahoogroups.com - http://tech.groups.yahoo.com/group/junit/ - - Common Public License Version 1.0 @@ -28,11 +21,7 @@ repo - - scm:git:git://github.com/KentBeck/junit.git - scm:git:git@github.com:KentBeck/junit.git - http://github.com/KentBeck/junit/tree/master - + dsaff @@ -51,21 +40,24 @@ - - 1.3 - 1.5 - ISO-8859-1 - + + + + JUnit Mailing List + junit@yahoogroups.com + http://tech.groups.yahoo.com/group/junit/ + + + 3.0.4 - - - org.hamcrest - hamcrest-core - ${hamcrestVersion} - - + + + scm:git:git://github.com/KentBeck/junit.git + scm:git:git@github.com:KentBeck/junit.git + http://github.com/KentBeck/junit/tree/master + https://github.com/KentBeck/junit/wiki/Download-and-Install @@ -79,6 +71,21 @@ https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + 1.3 + 1.5 + ISO-8859-1 + + + + + org.hamcrest + hamcrest-core + ${hamcrestVersion} + + + @@ -272,6 +279,7 @@ + junit-release From e15b287ccec2a1f4866a8bd1cd2a313a6163163d Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Thu, 17 Jan 2013 10:10:02 +0000 Subject: [PATCH 08/18] Only use a property where multiple entries need syncing * The hamcrest version is only used in one place, i.e. the dependency. * Using properties to define dependency versions can cause issues for others. * Using properties to define a shared version across multiple dependencies causes less issues when you have multiple dependencies that need to be kept in sync. * We only have one dependency here and it doesn't need syncing to any other dependency * Therefore the right thing is to just specify the version in the dependency * End users can still override the dependency in their poms. --- pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 88bd9ad10365..c8c82ae92926 100644 --- a/pom.xml +++ b/pom.xml @@ -73,7 +73,6 @@ - 1.3 1.5 ISO-8859-1 @@ -82,7 +81,7 @@ org.hamcrest hamcrest-core - ${hamcrestVersion} + 1.3 From 65459319a98852fbccabdcabe9470662845f06e7 Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Thu, 17 Jan 2013 10:14:00 +0000 Subject: [PATCH 09/18] Make the release plugin generate tags according to JUnit convention * JUnit has been using r4.xx as the tag format * Maven Release Plugin would, by default, use junit-4.xx as the tag format * Maven has no strong opinion on the tag, just providing a sensible default * The Maven way is to follow convention, JUnit has the precident convention with existing tags --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index c8c82ae92926..162bb1ea49ff 100644 --- a/pom.xml +++ b/pom.xml @@ -274,6 +274,7 @@ forked-path false -Pjunit-release + r@{project.version} From 2b4742e3b9f794eda24294bea6e78bff0fdc7010 Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Thu, 17 Jan 2013 10:27:42 +0000 Subject: [PATCH 10/18] GPG signature should be generated prior to 'install' phase. * There can be issues for the local repository if the signature happens after the install to local repository cache. * Only people with the GPG key should be running with the 'junit-release' profile active * Therefore safer to move the execution to the 'verify' phase --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 162bb1ea49ff..17b923b772d8 100644 --- a/pom.xml +++ b/pom.xml @@ -301,7 +301,7 @@ gpg-sign - install + verify sign From 4eeb323964386ed38b1d14b1a052cc9f13223e53 Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Thu, 17 Jan 2013 10:33:57 +0000 Subject: [PATCH 11/18] Allow tweaking release arguments form the CLI * We need to provide a default empty value for the 'arguments' property within the pom This ensures that when the property is not provided, the build can still continue * The `arguments` property is especially useful if you don't have the GPG key for signing as you can then test the release process by adding -Darguments=-Dgpg.skip=true to the command line used to prototype a release and the verification build will succeed. --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 17b923b772d8..2847932fce40 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,7 @@ 1.5 ISO-8859-1 + @@ -273,7 +274,7 @@ forked-path false - -Pjunit-release + -Pjunit-release ${arguments} r@{project.version} From 34c0a1aeee1700e2dd7b173b2e3dd4841c2a0e72 Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Thu, 17 Jan 2013 11:17:41 +0000 Subject: [PATCH 12/18] update the building docs * When running there is no need to do a first * Add some docs for people who need to maintain an in-house fork.' --- doc/building-junit.txt | 46 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/doc/building-junit.txt b/doc/building-junit.txt index 7d589f29da62..dff42e6d2771 100644 --- a/doc/building-junit.txt +++ b/doc/building-junit.txt @@ -8,11 +8,48 @@ Steps to build junit: - If not done, update src/main/config/settings.xml in /private/.../settings.xml on CloudBees' webdav share. - If not done, copy GnuPG keys in to ${gpg.homedir}. See settings.xml. - Perform Maven deployment of a snapshot or release version in Jenkins - - (to deploy snapshot version) - mvn clean deploy - - (to deploy specified release version in non-interactive mode -B) + Remember that the version specified in the pom.xml indicates the version + to be deployed, with -SNAPSHOT indicating that this is an unofficial + pre-release version towards the goal of the version without the -SNAPSHOT + + - (to deploy gpg signed snapshot version) + + $ mvn -Pjunit-release clean deploy + + - (to cut a release of the current targetted version) + + $ mvn -B release:prepare release:perform + + This will result in the current pom.xml version having -SNAPSHOT removed + and the release cut from that version. The version will then be incremented + and -SNAPSHOT added back in anticipation of the next release version. + + - (to cut a release of while changing the version from the current target) + + $ mvn -B -DreleaseVersion=5.0 release:prepare release:perform + + This will ignore the current version in the pom.xml, set it to 5.0 and + the release cut from that 5.0 version. Then 5.0 will be incremented (to 5.1) + and -SNAPSHOT added back in anticipation of the next release version. + + - (to deploy specified release version and next target release in non-interactive mode -B) An example with the next development version and deploying release version: - mvn -B -Dtag=4.12 -DreleaseVersion=4.12 -DdevelopmentVersion=4.13-SNAPSHOT clean release:prepare release:perform + + $ mvn -B -DreleaseVersion=4.12 -DdevelopmentVersion=4.13-SNAPSHOT release:prepare release:perform + + - If you are not an official release manager, and you want to cut a release of + JUnit for use within your organization, use the following command + + $ mvn -DpushChanges=false -DlocalCheckout '-Darguments=-Dgpg.skip=true -DaltDeploymentRepository=my-company-repo-id::default::my-company-repo-url' -B -DreleaseVersion=4.12-mycompany-1 release:prepare release:perform + + where + - my-company-repo-id is the of your company's entry in your + settings.xml with the credentials to deploy to your company's Maven repository + - my-company-repo-url is the deployment URL of your company's Maven repository + - 4.12-mycompany-1 is the version you are deploying, be sure to namespace + the version so that you don't conflict with others, hence why the text "mycompany" + is included in the example version number. + - Promote the maven artifacts and close staging repository if released successfully - Tedious: - Update SourceForge if major release @@ -48,7 +85,6 @@ Steps to build junit: junit-release - ... false true From d40631c109d1e09d5be4e66a678f030b11362a2b Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Thu, 17 Jan 2013 11:27:30 +0000 Subject: [PATCH 13/18] Actually allow forkers to sign their own releases * If you run an internal repo, you may be required to have signed artifacts So to make their life easier, use a property to define the default signing key Allows for others to swap in the key they use via the -Darguments=-Dgpg.keyname= trick --- pom.xml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 2847932fce40..00eab3b3a2d1 100644 --- a/pom.xml +++ b/pom.xml @@ -76,6 +76,7 @@ 1.5 ISO-8859-1 + 67893CC4 @@ -308,9 +309,6 @@ - - 67893CC4 - From a813a86dc77dbc50a9bbc74c1e6de61446a5693b Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Thu, 17 Jan 2013 13:16:48 +0000 Subject: [PATCH 14/18] Move the javadoc configuration to the default. * Making the configuration of javadoc tied to the execution makes it harder for people to tweak the javadoc configuration as they have to invoke the lifecycle rather than just invoke 'mvn javadoc:javadoc' to see the effects quickly --- pom.xml | 58 ++++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/pom.xml b/pom.xml index 00eab3b3a2d1..62a92a169b0a 100644 --- a/pom.xml +++ b/pom.xml @@ -230,6 +230,35 @@ --> maven-javadoc-plugin 2.8.1 + + ${basedir}/src/main/javadoc/stylesheet.css + protected + false + false + false + true + true + false + JUnit API + UTF-8 + en + 1.5 + + + api_1.5 + http://docs.oracle.com/javase/1.5.0/docs/api/index.html + + + junit.*,*.internal,*.internal.* + true + 32m + 128m + true + true + + org.hamcrest:hamcrest-core:* + + attach-javadoc @@ -237,35 +266,6 @@ jar - - ${basedir}/src/main/javadoc/stylesheet.css - protected - false - false - false - true - true - false - JUnit API - UTF-8 - en - 1.5 - - - api_1.5 - http://docs.oracle.com/javase/1.5.0/docs/api/index.html - - - junit.*,*.internal,*.internal.* - true - 32m - 128m - true - true - - org.hamcrest:hamcrest-core:* - - From 56cdd8b628f590381759d646dde421eec284c381 Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Thu, 17 Jan 2013 13:20:39 +0000 Subject: [PATCH 15/18] Move javadoc:jar and source:jar to the release profile. * Only need to be generated when cutting a release or deploying a -SNAPSHOT remotely * In those remote deploy situations -Pjunit-release will be active anyway * Moving them out of the main build speeds up development for all --- pom.xml | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 62a92a169b0a..dd1d6b1da655 100644 --- a/pom.xml +++ b/pom.xml @@ -212,15 +212,6 @@ --> maven-source-plugin 2.2 - - - attach-sources - prepare-package - - jar-no-fork - - - + + maven-source-plugin From d0e050c5ab3dc4fba6a92113668fbc799417a4b2 Mon Sep 17 00:00:00 2001 From: Stephen Connolly Date: Mon, 28 Jan 2013 21:43:18 +0000 Subject: [PATCH 17/18] Add issueManagement and ciManagement --- pom.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pom.xml b/pom.xml index 516d6f738d71..6b8c47563e97 100644 --- a/pom.xml +++ b/pom.xml @@ -58,6 +58,14 @@ scm:git:git@github.com:KentBeck/junit.git http://github.com/KentBeck/junit/tree/master + + github + https://github.com/KentBeck/junit/issues + + + jenkins + https://junit.ci.cloudbees.com/ + https://github.com/KentBeck/junit/wiki/Download-and-Install From 2c6c142aa801cef3520ca668e75a670a32b4859a Mon Sep 17 00:00:00 2001 From: pimterry Date: Mon, 28 Jan 2013 23:06:29 +0000 Subject: [PATCH 18/18] Added error validation to check that datapoints array fields are all static and public too, fixing #125 --- .../junit/experimental/theories/Theories.java | 20 ++- .../UnsuccessfulWithDataPointFields.java | 159 ++++++++++++++---- 2 files changed, 146 insertions(+), 33 deletions(-) diff --git a/src/main/java/org/junit/experimental/theories/Theories.java b/src/main/java/org/junit/experimental/theories/Theories.java index b47eb3e561de..dc577dc3bdeb 100644 --- a/src/main/java/org/junit/experimental/theories/Theories.java +++ b/src/main/java/org/junit/experimental/theories/Theories.java @@ -2,6 +2,7 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; @@ -26,13 +27,14 @@ public Theories(Class klass) throws InitializationError { protected void collectInitializationErrors(List errors) { super.collectInitializationErrors(errors); validateDataPointFields(errors); + validateDataPointMethods(errors); } private void validateDataPointFields(List errors) { Field[] fields = getTestClass().getJavaClass().getDeclaredFields(); for (Field field : fields) { - if (field.getAnnotation(DataPoint.class) == null) { + if (field.getAnnotation(DataPoint.class) == null && field.getAnnotation(DataPoints.class) == null) { continue; } if (!Modifier.isStatic(field.getModifiers())) { @@ -44,6 +46,22 @@ private void validateDataPointFields(List errors) { } } + private void validateDataPointMethods(List errors) { + Method[] methods = getTestClass().getJavaClass().getDeclaredMethods(); + + for (Method method : methods) { + if (method.getAnnotation(DataPoint.class) == null && method.getAnnotation(DataPoints.class) == null) { + continue; + } + if (!Modifier.isStatic(method.getModifiers())) { + errors.add(new Error("DataPoint method " + method.getName() + " must be static")); + } + if (!Modifier.isPublic(method.getModifiers())) { + errors.add(new Error("DataPoint method " + method.getName() + " must be public")); + } + } + } + @Override protected void validateConstructor(List errors) { validateOnlyOneConstructor(errors); diff --git a/src/test/java/org/junit/tests/experimental/theories/runner/UnsuccessfulWithDataPointFields.java b/src/test/java/org/junit/tests/experimental/theories/runner/UnsuccessfulWithDataPointFields.java index b466306d3039..fddb09b16c94 100644 --- a/src/test/java/org/junit/tests/experimental/theories/runner/UnsuccessfulWithDataPointFields.java +++ b/src/test/java/org/junit/tests/experimental/theories/runner/UnsuccessfulWithDataPointFields.java @@ -2,16 +2,18 @@ import static org.hamcrest.CoreMatchers.allOf; import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThat; import static org.junit.experimental.results.PrintableResult.testResult; import static org.junit.experimental.results.ResultMatchers.failureCountIs; import static org.junit.experimental.results.ResultMatchers.hasFailureContaining; import static org.junit.experimental.results.ResultMatchers.hasSingleFailureContaining; - import org.hamcrest.CoreMatchers; import org.junit.Test; import org.junit.experimental.results.PrintableResult; import org.junit.experimental.theories.DataPoint; +import org.junit.experimental.theories.DataPoints; import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; @@ -19,7 +21,7 @@ public class UnsuccessfulWithDataPointFields { @RunWith(Theories.class) - public static class HasATheory { + public static class HasAFailingTheory { @DataPoint public static int ONE = 1; @@ -31,19 +33,19 @@ public void everythingIsZero(int x) { @Test public void theoryClassMethodsShowUp() throws Exception { - assertThat(new Theories(HasATheory.class).getDescription() + assertThat(new Theories(HasAFailingTheory.class).getDescription() .getChildren().size(), is(1)); } @Test public void theoryAnnotationsAreRetained() throws Exception { - assertThat(new TestClass(HasATheory.class).getAnnotatedMethods( + assertThat(new TestClass(HasAFailingTheory.class).getAnnotatedMethods( Theory.class).size(), is(1)); } @Test public void canRunTheories() throws Exception { - assertThat(testResult(HasATheory.class), + assertThat(testResult(HasAFailingTheory.class), hasSingleFailureContaining("Expected")); } @@ -83,15 +85,33 @@ public void nullsUsedUnlessProhibited() throws Exception { assertThat(testResult(NullsOK.class), hasSingleFailureContaining("null")); } - + @RunWith(Theories.class) - public static class DataPointsMustBeStatic { + public static class TheoriesMustBePublic { @DataPoint - public int THREE = 3; + public static int THREE = 3; - @DataPoint - public int FOUR = 4; + @Theory + void numbers(int x) { + + } + } + + @Test + public void theoriesMustBePublic() { + assertThat( + testResult(TheoriesMustBePublic.class), + hasSingleFailureContaining("public")); + } + @RunWith(Theories.class) + public static class DataPointFieldsMustBeStatic { + @DataPoint + public int THREE = 3; + + @DataPoints + public int[] FOURS = new int[] { 4 }; + @Theory public void numbers(int x) { @@ -99,59 +119,134 @@ public void numbers(int x) { } @Test - public void dataPointsMustBeStatic() { + public void dataPointFieldsMustBeStatic() { assertThat( - testResult(DataPointsMustBeStatic.class), + testResult(DataPointFieldsMustBeStatic.class), CoreMatchers.both(failureCountIs(2)) .and( hasFailureContaining("DataPoint field THREE must be static")) .and( - hasFailureContaining("DataPoint field FOUR must be static"))); + hasFailureContaining("DataPoint field FOURS must be static"))); } - + @RunWith(Theories.class) - public static class TheoriesMustBePublic { + public static class DataPointMethodsMustBeStatic { @DataPoint - public static int THREE = 3; + public int singleDataPointMethod() { + return 1; + } + + @DataPoints + public int[] dataPointArrayMethod() { + return new int[] { 1, 2, 3 }; + } @Theory - void numbers(int x) { - + public void numbers(int x) { + } } - + @Test - public void theoriesMustBePublic() { + public void dataPointMethodsMustBeStatic() { assertThat( - testResult(TheoriesMustBePublic.class), - hasSingleFailureContaining("public")); + testResult(DataPointMethodsMustBeStatic.class), + CoreMatchers.both(failureCountIs(2)) + .and( + hasFailureContaining("DataPoint method singleDataPointMethod must be static")) + .and( + hasFailureContaining("DataPoint method dataPointArrayMethod must be static"))); } @RunWith(Theories.class) - public static class DataPointsMustBePublic { + public static class DataPointFieldsMustBePublic { @DataPoint static int THREE = 3; + + @DataPoints + static int[] THREES = new int[] { 3 }; @DataPoint protected static int FOUR = 4; + + @DataPoints + protected static int[] FOURS = new int[] { 4 }; - @SuppressWarnings("unused") @DataPoint private static int FIVE = 5; + + @DataPoints + private static int[] FIVES = new int[] { 5 }; @Theory public void numbers(int x) { - + } } @Test - public void dataPointsMustBePublic() { - assertThat( - testResult(DataPointsMustBePublic.class), - allOf(failureCountIs(3), - hasFailureContaining("DataPoint field THREE must be public"), - hasFailureContaining("DataPoint field FOUR must be public"), - hasFailureContaining("DataPoint field FIVE must be public"))); + public void dataPointFieldsMustBePublic() { + PrintableResult result = testResult(DataPointFieldsMustBePublic.class); + assertEquals(6, result.failureCount()); + + assertThat(result, + allOf(hasFailureContaining("DataPoint field THREE must be public"), + hasFailureContaining("DataPoint field THREES must be public"), + hasFailureContaining("DataPoint field FOUR must be public"), + hasFailureContaining("DataPoint field FOURS must be public"), + hasFailureContaining("DataPoint field FIVE must be public"), + hasFailureContaining("DataPoint field FIVES must be public"))); + } + + @RunWith(Theories.class) + public static class DataPointMethodsMustBePublic { + @DataPoint + static int three() { + return 3; + } + + @DataPoints + static int[] threes() { + return new int[] { 3 }; + } + + @DataPoint + protected static int four() { + return 4; + } + + @DataPoints + protected static int[] fours() { + return new int[] { 4 }; + } + + @DataPoint + private static int five() { + return 5; + } + + @DataPoints + private static int[] fives() { + return new int[] { 5 }; + } + + @Theory + public void numbers(int x) { + + } + } + + @Test + public void dataPointMethodsMustBePublic() { + PrintableResult result = testResult(DataPointMethodsMustBePublic.class); + assertEquals(6, result.failureCount()); + + assertThat(result, + allOf(hasFailureContaining("DataPoint method three must be public"), + hasFailureContaining("DataPoint method threes must be public"), + hasFailureContaining("DataPoint method four must be public"), + hasFailureContaining("DataPoint method fours must be public"), + hasFailureContaining("DataPoint method five must be public"), + hasFailureContaining("DataPoint method fives must be public"))); } }