You can subscribe to this list here.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(80) |
Nov
(42) |
Dec
(3) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(11) |
Feb
(50) |
Mar
(70) |
Apr
(102) |
May
(28) |
Jun
(45) |
Jul
(14) |
Aug
(75) |
Sep
(17) |
Oct
(15) |
Nov
(11) |
Dec
(4) |
2003 |
Jan
(16) |
Feb
(19) |
Mar
(21) |
Apr
(20) |
May
(29) |
Jun
(7) |
Jul
(5) |
Aug
|
Sep
|
Oct
(2) |
Nov
(3) |
Dec
(3) |
2004 |
Jan
(5) |
Feb
(4) |
Mar
(1) |
Apr
(1) |
May
(1) |
Jun
(1) |
Jul
(7) |
Aug
(1) |
Sep
(6) |
Oct
(6) |
Nov
(1) |
Dec
(2) |
2005 |
Jan
(4) |
Feb
(4) |
Mar
(15) |
Apr
(1) |
May
|
Jun
(4) |
Jul
(6) |
Aug
(6) |
Sep
|
Oct
(4) |
Nov
(2) |
Dec
(4) |
2006 |
Jan
|
Feb
(91) |
Mar
(47) |
Apr
(7) |
May
(4) |
Jun
(9) |
Jul
(1) |
Aug
|
Sep
(5) |
Oct
(36) |
Nov
(95) |
Dec
(12) |
2007 |
Jan
(11) |
Feb
(31) |
Mar
(45) |
Apr
(11) |
May
(9) |
Jun
(1) |
Jul
(146) |
Aug
(15) |
Sep
|
Oct
(3) |
Nov
(6) |
Dec
(1) |
2008 |
Jan
(2) |
Feb
(1) |
Mar
(1) |
Apr
(1) |
May
(1) |
Jun
(3) |
Jul
(2) |
Aug
(19) |
Sep
(1) |
Oct
(10) |
Nov
|
Dec
(8) |
2009 |
Jan
(3) |
Feb
(1) |
Mar
(4) |
Apr
(8) |
May
(5) |
Jun
(4) |
Jul
(2) |
Aug
(1) |
Sep
(2) |
Oct
(13) |
Nov
(13) |
Dec
(4) |
2010 |
Jan
(1) |
Feb
(2) |
Mar
(1) |
Apr
(2) |
May
|
Jun
(1) |
Jul
(3) |
Aug
(2) |
Sep
|
Oct
|
Nov
|
Dec
(1) |
2011 |
Jan
(1) |
Feb
(4) |
Mar
(3) |
Apr
(4) |
May
|
Jun
(12) |
Jul
(16) |
Aug
(4) |
Sep
(7) |
Oct
|
Nov
|
Dec
|
2012 |
Jan
|
Feb
|
Mar
(2) |
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2013 |
Jan
|
Feb
|
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2014 |
Jan
(5) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(3) |
Dec
|
From: worodin <wo...@fr...> - 2006-10-28 09:59:16
|
David, for 1.) Short answer: The patch actually does this. Long answer: The patch places the APT processor into the same junit.jar as the runtime, so users may drop the jar simply into the classpath of apt, which is shared with javac, if you order apt to trigger the compile too, (e.g by *not* using the option '-nocompile'). In fact, it is problematic to separate the required classes into different jars, as in any case, you are likely to need access to the compiled annotation classes, which would end up in both jars then. On a similar track, since the processor isn't generating anything, but only doing checks, its currently not strictly a prerequisite to compiling & running the tests. So prudence requires, that the runtime checks remain in place; but we might want to share the resulting messages. For 2.) APT caters for having several processors in the same build. The processor needs to implement an information method, telling apt which annotations to process. Apt detects process factorys, by peeking into META-INF/services/com.sun.mirror.apt.AnnotationProcessorFactory of every jar found in the -classpath or -factorypath of apt. This means: in the current state of the patch, a supplier of another annotation (junit related or not) would have to implement its own processor, and register it as mentioned above. Of course, we could start thinking about sort of an extension framework for integrating junit specific extensions into our processor, but this would require us to forsee all the needs of those, which proves difficult. In our case: we would have to define an interface, that abstracts the handling for treating any runner, and a way to look up an implementation of that interface for any given runner. While this could be done, I'm still wondering if we really do need to to specify runners via @RunWith. As far as I can see we currently have: - The default runner, which is used if non is specified. - The Suite Runner, which *needs* to be used for a suite, iff a @Suite.Classes() annotation is present, that is. - The Parameterized Runner, which only makes sense, if there is also an @Parametesr annotation. Are there more? My impression is, we might be better off, dropping the @RunWith annotations, and infering the proper runner from other annotations. Dreaming on, this could result in having a resolver, that starts nesting runners, if there are several annotations that require different runners - ordering might become a problem here. Thomas David Saff schrieb: > Thomas, > > It's certainly an interesting approach, and is a candidate for division > of responsibilities. I've been meaning to learn more about APT. I > wonder about the following challenges: > > 1) Can we avoid creating two runtimes, one for APT, and the other for > the test execution? > 2) If third parties create custom runners with custom annotations, how > do they plug into the APT checks? > > David Saff > > worodin wrote: >> Hey ho list! >> >> As a reference for this thread, pls take a look at >> https://sourceforge.net/tracker/?func=detail&atid=315278&aid=1581916&group_id=15278 >> >> and try the jar. >> >> E. g. executing a task like >> >> <exec executable="C:/dev/tool/sun/j2sdk/1.5.0_07/bin/apt.exe"> >> <arg line='-classpath ".;./junit4.1/junit-4.1.jar" -nocompile -d "." >> org/junit/tests/apt/*.java'/> >> </exec> >> >> against the test classes supplied in the patch would yield: >> >> [exec] org/junit/tests/apt/AllTests.java:41: The abstract test >> class org.junit.tests.apt.TestAfter can not be instanced by suite runner >> [exec] public class AllTests { >> [exec] ^ >> [exec] org/junit/tests/apt/AllTests.java:41: The abstract test >> class org.junit.tests.apt.TestAfterClass can not be instanced by suite >> runner >> [exec] public class AllTests { >> [exec] ^ >> [exec] org/junit/tests/apt/AllTests.java:41: The abstract test >> class org.junit.tests.apt.TestBefore can not be instanced by suite runner >> [exec] public class AllTests { >> [exec] ^ >> [exec] org/junit/tests/apt/AllTests.java:41: The abstract test >> class org.junit.tests.apt.TestBeforeClass can not be instanced by suite >> runner >> [exec] public class AllTests { >> [exec] ^ >> [exec] org/junit/tests/apt/AllTests.java:41: The abstract test >> class org.junit.tests.apt.Quiet can not be instanced by suite runner >> [exec] public class AllTests { >> [exec] ^ >> [exec] org/junit/tests/apt/EmptySuiteClasses.java:11: warning: >> Annotation @SuiteClasses was empty - nothing to test. >> [exec] public class EmptySuiteClasses {} >> [exec] ^ >> [exec] org/junit/tests/apt/NoSuiteClasses.java:8: warning: Classes >> annotated with @RunWith(Suite.class) should also be annotated with a non >> empty @SuiteClasses({}). The resulting test suite is empty. >> [exec] public class NoSuiteClasses {} >> [exec] ^ >> [exec] org/junit/tests/apt/NotThrowing.java:7: Checked Exception >> org.junit.tests.apt.NotThrowing.MyException will never be thrown, >> because it isn't declared for method notThrowing. This test will allways >> fail. >> [exec] @Test(expected=MyException.class) public void >> notThrowing() {} >> [exec] ^ >> [exec] org/junit/tests/apt/OrphanedSuite.java:7: warning: The >> annotation @SuiteClasses({...}) is only of use for classes also >> annotated with @RunWith(Suite.class). >> [exec] public class OrphanedSuite {} >> [exec] ^ >> [exec] org/junit/tests/apt/StaticTest.java:7: Methods annotated >> with org.junit.Test must not be static. >> [exec] @Test public static void staticTest() {} >> [exec] ^ >> [exec] org/junit/tests/apt/TestAfter.java:7: Methods annotated with >> org.junit.After need to return void. >> [exec] @After public int notVoid(Object o) {return 0;} >> [exec] ^ >> [exec] org/junit/tests/apt/TestAfter.java:7: Methods annotated with >> org.junit.After shouldn't have parameters. >> [exec] @After public int notVoid(Object o) {return 0;} >> [exec] ^ >> [exec] org/junit/tests/apt/TestAfterClass.java:7: Methods annotated >> with org.junit.AfterClass need to be public. >> [exec] @AfterClass void notPublic(Object o) {} >> [exec] ^ >> [exec] org/junit/tests/apt/TestAfterClass.java:7: Methods annotated >> with org.junit.AfterClass shouldn't have parameters. >> [exec] @AfterClass void notPublic(Object o) {} >> [exec] ^ >> [exec] org/junit/tests/apt/TestAfterClass.java:7: Methods annotated >> with org.junit.AfterClass need to be static. >> [exec] @AfterClass void notPublic(Object o) {} >> [exec] ^ >> [exec] org/junit/tests/apt/TestBefore.java:7: Methods annotated >> with org.junit.Before need to be public. >> [exec] @Before int notPublicNotVoid() {return 0;} >> [exec] ^ >> [exec] org/junit/tests/apt/TestBefore.java:7: Methods annotated >> with org.junit.Before need to return void. >> [exec] @Before int notPublicNotVoid() {return 0;} >> [exec] ^ >> [exec] org/junit/tests/apt/TestBeforeClass.java:7: Methods >> annotated with org.junit.BeforeClass need to be public. >> [exec] @BeforeClass int notPublicNotVoid(Object o) {return 0;} >> [exec] ^ >> [exec] org/junit/tests/apt/TestBeforeClass.java:7: Methods >> annotated with org.junit.BeforeClass need to return void. >> [exec] @BeforeClass int notPublicNotVoid(Object o) {return 0;} >> [exec] ^ >> [exec] org/junit/tests/apt/TestBeforeClass.java:7: Methods >> annotated with org.junit.BeforeClass shouldn't have parameters. >> [exec] @BeforeClass int notPublicNotVoid(Object o) {return 0;} >> [exec] ^ >> [exec] org/junit/tests/apt/TestBeforeClass.java:7: Methods >> annotated with org.junit.BeforeClass need to be static. >> [exec] @BeforeClass int notPublicNotVoid(Object o) {return 0;} >> [exec] ^ >> [exec] org/junit/tests/apt/TestHasParameters.java:7: Methods >> annotated with org.junit.Test shouldn't have parameters. >> [exec] @Test public void hasParameters(Object o) {} >> [exec] ^ >> [exec] org/junit/tests/apt/TestInheritedParameters.java:11: Methods >> annotated with org.junit.runners.Parameterized.Parameters are required >> to return java.util.Collection<java.lang.Object[]>. >> [exec] @Parameters public static Object data2() {return new >> Object();} >> [exec] ^ >> [exec] org/junit/tests/apt/TestNotPublic.java:7: Methods annotated >> with org.junit.Test need to be public. >> [exec] @Test void notPublic() {} >> [exec] ^ >> [exec] org/junit/tests/apt/TestNotVoid.java:7: Methods annotated >> with org.junit.Test need to return void. >> [exec] @Test public int notVoid() {return 0;} >> [exec] ^ >> [exec] >> org/junit/tests/apt/TestParameterizedWith2Constructors.java:15: >> Constructor competes with one allready seen at >> org/junit/tests/apt/TestParameterizedWith2Constructors.java:14 - classes >> annotated with @RunWith(Parameterized.class) require exactly one public >> constructor taking the parameters. >> [exec] public TestParameterizedWith2Constructors() {} >> [exec] ^ >> [exec] >> org/junit/tests/apt/TestParameterizedWith2Constructors.java:12: >> org.junit.tests.apt.TestParameterizedWith2Constructors contains 2 public >> constructors - classes annotated with @RunWith(Parameterized.class) >> require exactly one public constructor taking the parameters. >> [exec] public class TestParameterizedWith2Constructors { >> [exec] ^ >> [exec] >> org/junit/tests/apt/TestParameterizedWith2ParameterMethods.java:26: >> warning: Method annotated with @Parameters competes with one allready >> seen at >> org/junit/tests/apt/TestParameterizedWith2ParameterMethods.java:20 - as >> of Junit 4.1, only one of them will be used to retrieve test parameters. >> [exec] @Parameters public static Collection<Object[]> data2() { >> [exec] ^ >> [exec] >> org/junit/tests/apt/TestParameterizedWith2ParameterMethods.java:11: >> warning: There are 2 competing methods all annotated with @Parameters - >> as of Junit 4.1, only one of them will be used to retrieve test >> parameters. >> [exec] public class TestParameterizedWith2ParameterMethods { >> [exec] ^ >> [exec] >> org/junit/tests/apt/TestParameterizedWithNoParameterMethods.java:9: >> Class org.junit.tests.apt.TestParameterizedWithNoParameterMethods is not >> abstract, annotated as @RunWith(Parameterized.class), but there is no >> instance method annotated with @Parameters within the type hierarchy: >> There will be nothing to test. >> [exec] public class TestParameterizedWithNoParameterMethods { >> [exec] ^ >> [exec] org/junit/tests/apt/TestParameters.java:11: Methods >> annotated with org.junit.runners.Parameterized.Parameters are required >> to return java.util.Collection<java.lang.Object[]>. >> [exec] @Parameters public static Object data2() {return new >> Object();} >> [exec] ^ >> [exec] org/junit/tests/apt/SuiteCycle.java:25: The following >> classes annotated with @RunWith(Suite.class) form a loop: >> org.junit.tests.apt.SuiteCycle.ASuite -> >> org.junit.tests.apt.SuiteCycle.AnotherSuite - invoking any of them will >> result in a stack overflow at runtime. >> [exec] public static class ASuite {} >> [exec] ^ >> [exec] org/junit/tests/apt/SuiteCycle.java:25: Referenced suite >> org.junit.tests.apt.SuiteCycle.AnotherSuite is part of or references a >> loop of suits - invokation will cause a stack overflow at runtime. >> [exec] public static class ASuite {} >> [exec] ^ >> [exec] org/junit/tests/apt/SuiteCycle.java:21: Referenced suite >> org.junit.tests.apt.SuiteCycle.ASuite is part of or references a loop of >> suits - invokation will cause a stack overflow at runtime. >> [exec] public class SuiteCycle { >> [exec] ^ >> [exec] org/junit/tests/apt/AllTests.java:41: Referenced suite >> org.junit.tests.apt.SuiteCycle is part of or references a loop of suits >> - invokation will cause a stack overflow at runtime. >> [exec] public class AllTests { >> [exec] ^ >> [exec] org/junit/tests/apt/NoTestInSuiteClass.java:11: warning: >> Test case org.junit.tests.apt.NoTestInSuiteClass doesn't contain any >> test methods. >> [exec] public class NoTestInSuiteClass {} >> [exec] ^ >> [exec] org/junit/tests/apt/NoSuiteClasses.java:8: warning: Test >> case org.junit.tests.apt.NoSuiteClasses doesn't contain any test methods. >> [exec] public class NoSuiteClasses {} >> [exec] ^ >> [exec] org/junit/tests/apt/EmptySuiteClasses.java:11: warning: Test >> case org.junit.tests.apt.EmptySuiteClasses doesn't contain any test >> methods. >> [exec] public class EmptySuiteClasses {} >> [exec] ^ >> [exec] org/junit/tests/apt/ClassNotPublic.java:9: Class >> org.junit.tests.apt.ClassNotPublic has to be public in order to be >> instanced. >> [exec] class ClassNotPublic { >> [exec] ^ >> [exec] org/junit/tests/apt/NoValidConstructors.java:6: This test >> class requires a public no argument constructor. >> [exec] public class NoValidConstructors { >> [exec] ^ >> [exec] 32 errors >> [exec] 8 warnings >> [exec] Result: 1 >> >> >> As far as I can tell, the checks are pretty complete, but I'm open to >> suggestions. The processor might do with some refactoring, but hey, it's >> my first try at apt. >> >> I see several spin offs: >> >> - the apt processor uses 20+ messages (Errors and warnings), some of >> them intersecting with runtime messages. It might be viable, to start >> pooling all messages used in org.junit in a jdk 1.5 enumeration. >> >> - as an afterthought, I wonder if we really need @RunWith. AFAICT, the >> proper runner can mostly infered from an other annotation, e. g. >> @SuiteClasses or @Parameters, leaving the rest to the default runner. >> >> - the patch contains a test, that runs apt on a isolated file, checking >> for results. This could be evolved into a pattern for testing apt >> processors. >> >> Hope this is of interest. >> >> Thomas >> >> ------------------------------------------------------------------------- >> Using Tomcat but need to do more? Need to support web services, security? >> Get stuff done quickly with pre-integrated technology to make your job >> easier >> Download IBM WebSphere Application Server v.1.0.1 based on Apache >> Geronimo >> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 >> _______________________________________________ >> Junit-devel mailing list >> Jun...@li... >> https://lists.sourceforge.net/lists/listinfo/junit-devel >> > |
From: Jochen H. <jo....@go...> - 2006-10-27 13:32:01
|
Hi Matthias, I completely agree with you. Maven - I assume you targeted Maven2 ;-) - is fine to setup and build more complex projects with lot of dependencies to external libraries etc. Compared with ANT, there is for JUnit no real benefit at the end. A restructuring following "standard" directory schemas as proposed below is in general a good idea, but requires a migration to SVN first (as you mentioned too). So I would propose: 1. Stay at the current ANT based build process 2. Migrate some day from CVS to SVN (it is up to the committers and work load, but not too hard using cvs2svn migration tools) 3. Restructure directory structure to a well known standard layout Meanwhile, the current build process can be beautified a litte bit, to ensure a more clean junit4x.jar with only the required resources at the end= . That is even possible with the current directory layout. Only me 2 cents of worth, Cheers, Jochen On 10/27/06, Matthias Schmidt <mat...@gm...> wrote: > > David, > > yes I have used Maven. Maven can do what we would like to do with JUnit > with just a few lines of XML: > - compile the sources > - build a junit.jar with the JUnit core > - build a src.jar > - build a test.jar for the tests > - create javadoc > - run unit tests (I know there is a plugin for 3.8.1 but I am not sure > about 4.x) > > But the downside is: To use maven, we would have to move the files. So it > would be good to move to Suversion before. The outline would have to look > like this: > junit > |-- pom.xml > `-- src > |-- main > | `-- java > | `-- org > | `-- junit > | `-- Assert.java > `-- test > `-- java > `-- org > `-- junit > `-- AssertionTest.java > > The pom.xml (Maven's equivalent to build.xml) is IMHO not as readable as = a > clean build.xml. Here is a short example from the Maven site: > > <project xmlns=3D"http://maven.apache.org/POM/4.0.0" xmlns:xsi=3D" > http://www.w3.org/2001/XMLSchema-instance" > xsi:schemaLocation=3D"http://maven.apache.org/POM/4.0.0 > http://maven.apache.org/maven-v4_0_0.xsd"> > <modelVersion>4.0.0</modelVersion> > <groupId>com.mycompany.app</groupId> > <artifactId>my-app</artifactId> > <packaging>jar</packaging> > <version>1.0-SNAPSHOT</version> > <name>Maven Quick Start Archetype</name> > <url>http://maven.apache.org</url> > <dependencies> > <dependency> > <groupId>junit</groupId> > <artifactId>junit</artifactId> > <version>3.8.1</version> > <scope>test</scope> > </dependency> > </dependencies> > </project> > > Another disadvantage is that Maven does not come bundled with every IDE. > And he last time I looked at the Maven Eclipse plugin, it was not nearly = as > good as the Ant support. > > I agree that in the end we only get the same junit.jar that we got from > Ant before. I tend to only use Maven in new projects, but not migrate fro= m > Ant to Maven. > > Any thoughts from anybody else? > > Matt > > -------- Original-Nachricht -------- > Datum: Tue, 24 Oct 2006 16:33:39 -0400 > Von: David Saff <sa...@mi...> > An: Matthias Schmidt <mat...@gm...> > Betreff: Re: [Junit-devel] Refactoring of ANT build (see patch 1581944) > > > Matthias, > > > > Have you used Maven? I've been intrigued in the past, but concerned > > that the incremental improvement in build structure wouldn't be worth > > the extra dependency. What's your take? > > > > David Saff > > > > Matthias Schmidt wrote: > > > Thomas, > > > > > > Then we could move to Maven. Maven does all you suggest automatically > > > (more or less ;-)). > > > > > > But you are right: Files would have to be moved for that. > > > > > > Regards, > > > Matt > > > > > > worodin schrieb: > > > > > >> Hey ho list! > > >> > > >> Is there any opinion regarding the ideas I mentioned in > > >> > > > https://sourceforge.net/tracker/?func=3Ddetail&atid=3D315278&aid=3D158194= 4&group_id=3D15278 > ? > > >> > > >> What I'm suggesting there is, moving into the direction of a layout, > > >> that has been prouven in many open source projects. > > >> > > >> A.) > > >> Arguments for separating sources from generated output (e. g. > classes) > > >> - much easier to do a clean > > >> - no need to to maintain .cvsignore, IDE view filters etc just to > have > > a > > >> nice and clean screen. > > >> - fewer messy exclusion filters in ant > > >> > > >> B.) > > >> Arguments for separating test from application sources: > > >> - fewer messy exclusion filters in ant > > >> - easier separation of sources, even if they are not in a *.test.* > > >> package and do not contain the infix *Test* e. g. for javadoc, jar. > > >> > > >> - Only drawback here: you need to navigate two trees (actually, I > don't > > >> see this as a drawback, but rather as a visual aid) > > >> > > >> A.) is easy to achieve with the current CVS layout, but B.) would > > >> require moving some things around. In CVS this would result in > loosing > > >> the change history. Now I'm remembering remotely somebody else > > >> suggesting to move to SVN. Doing so, would offer the following: > > >> > > >> - First, migrate to SVN first. SVN documentation states, that CVS > > >> history can be ported too. > > >> - Then start B.) SVN versions directories, keeping the history, when > > >> moving files. > > >> > > >> Let me know, what you think of it. > > >> > > >> > > >> Thomas > -- > Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! > Ideal f=FCr Modem und ISDN: http://www.gmx.net/de/go/smartsurfer > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronim= o > http://sel.as-us.falkag.net/sel?cmd=3Dlnk&kid=3D120709&bid=3D263057&dat= =3D121642 > _______________________________________________ > Junit-devel mailing list > Jun...@li... > https://lists.sourceforge.net/lists/listinfo/junit-devel > |
From: Matthias S. <mat...@gm...> - 2006-10-27 12:42:34
|
David, yes I have used Maven. Maven can do what we would like to do with JUnit with just a few lines of XML: - compile the sources - build a junit.jar with the JUnit core - build a src.jar - build a test.jar for the tests - create javadoc - run unit tests (I know there is a plugin for 3.8.1 but I am not sure about 4.x) But the downside is: To use maven, we would have to move the files. So it would be good to move to Suversion before. The outline would have to look like this: junit |-- pom.xml `-- src |-- main | `-- java | `-- org | `-- junit | `-- Assert.java `-- test `-- java `-- org `-- junit `-- AssertionTest.java The pom.xml (Maven's equivalent to build.xml) is IMHO not as readable as a clean build.xml. Here is a short example from the Maven site: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.mycompany.app</groupId> <artifactId>my-app</artifactId> <packaging>jar</packaging> <version>1.0-SNAPSHOT</version> <name>Maven Quick Start Archetype</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> </project> Another disadvantage is that Maven does not come bundled with every IDE. And he last time I looked at the Maven Eclipse plugin, it was not nearly as good as the Ant support. I agree that in the end we only get the same junit.jar that we got from Ant before. I tend to only use Maven in new projects, but not migrate from Ant to Maven. Any thoughts from anybody else? Matt -------- Original-Nachricht -------- Datum: Tue, 24 Oct 2006 16:33:39 -0400 Von: David Saff <sa...@mi...> An: Matthias Schmidt <mat...@gm...> Betreff: Re: [Junit-devel] Refactoring of ANT build (see patch 1581944) > Matthias, > > Have you used Maven? I've been intrigued in the past, but concerned > that the incremental improvement in build structure wouldn't be worth > the extra dependency. What's your take? > > David Saff > > Matthias Schmidt wrote: > > Thomas, > > > > Then we could move to Maven. Maven does all you suggest automatically > > (more or less ;-)). > > > > But you are right: Files would have to be moved for that. > > > > Regards, > > Matt > > > > worodin schrieb: > > > >> Hey ho list! > >> > >> Is there any opinion regarding the ideas I mentioned in > >> > https://sourceforge.net/tracker/?func=detail&atid=315278&aid=1581944&group_id=15278? > >> > >> What I'm suggesting there is, moving into the direction of a layout, > >> that has been prouven in many open source projects. > >> > >> A.) > >> Arguments for separating sources from generated output (e. g. classes) > >> - much easier to do a clean > >> - no need to to maintain .cvsignore, IDE view filters etc just to have > a > >> nice and clean screen. > >> - fewer messy exclusion filters in ant > >> > >> B.) > >> Arguments for separating test from application sources: > >> - fewer messy exclusion filters in ant > >> - easier separation of sources, even if they are not in a *.test.* > >> package and do not contain the infix *Test* e. g. for javadoc, jar. > >> > >> - Only drawback here: you need to navigate two trees (actually, I don't > >> see this as a drawback, but rather as a visual aid) > >> > >> A.) is easy to achieve with the current CVS layout, but B.) would > >> require moving some things around. In CVS this would result in loosing > >> the change history. Now I'm remembering remotely somebody else > >> suggesting to move to SVN. Doing so, would offer the following: > >> > >> - First, migrate to SVN first. SVN documentation states, that CVS > >> history can be ported too. > >> - Then start B.) SVN versions directories, keeping the history, when > >> moving files. > >> > >> Let me know, what you think of it. > >> > >> > >> Thomas -- Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer |
From: Fran H. <fra...@ie...> - 2006-10-26 02:58:45
|
I will be out of the office starting 23/10/2006 and will not return until 31/10/2006. If you have any support issues/queries please raise a 199 call and assign them to the appropriate support team listed below; CDR Support :- EIENR_ASCDRAPPS BARCODE - EIEDN_SSLAMFGBC Maxcim/Tolas - EIEDN_SSLAVXLIV Thanks alot, Fran. |
From: David S. <sa...@mi...> - 2006-10-24 20:33:55
|
Matthias, Have you used Maven? I've been intrigued in the past, but concerned that the incremental improvement in build structure wouldn't be worth the extra dependency. What's your take? David Saff Matthias Schmidt wrote: > Thomas, > > Then we could move to Maven. Maven does all you suggest automatically > (more or less ;-)). > > But you are right: Files would have to be moved for that. > > Regards, > Matt > > worodin schrieb: > >> Hey ho list! >> >> Is there any opinion regarding the ideas I mentioned in >> https://sourceforge.net/tracker/?func=detail&atid=315278&aid=1581944&group_id=15278? >> >> What I'm suggesting there is, moving into the direction of a layout, >> that has been prouven in many open source projects. >> >> A.) >> Arguments for separating sources from generated output (e. g. classes) >> - much easier to do a clean >> - no need to to maintain .cvsignore, IDE view filters etc just to have a >> nice and clean screen. >> - fewer messy exclusion filters in ant >> >> B.) >> Arguments for separating test from application sources: >> - fewer messy exclusion filters in ant >> - easier separation of sources, even if they are not in a *.test.* >> package and do not contain the infix *Test* e. g. for javadoc, jar. >> >> - Only drawback here: you need to navigate two trees (actually, I don't >> see this as a drawback, but rather as a visual aid) >> >> A.) is easy to achieve with the current CVS layout, but B.) would >> require moving some things around. In CVS this would result in loosing >> the change history. Now I'm remembering remotely somebody else >> suggesting to move to SVN. Doing so, would offer the following: >> >> - First, migrate to SVN first. SVN documentation states, that CVS >> history can be ported too. >> - Then start B.) SVN versions directories, keeping the history, when >> moving files. >> >> Let me know, what you think of it. >> >> >> Thomas >> >> ------------------------------------------------------------------------- >> Using Tomcat but need to do more? Need to support web services, security? >> Get stuff done quickly with pre-integrated technology to make your job easier >> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo >> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 >> _______________________________________________ >> Junit-devel mailing list >> Jun...@li... >> https://lists.sourceforge.net/lists/listinfo/junit-devel >> >> >> > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Junit-devel mailing list > Jun...@li... > https://lists.sourceforge.net/lists/listinfo/junit-devel > |
From: Matthias S. <mat...@gm...> - 2006-10-22 07:50:22
|
Thomas, Then we could move to Maven. Maven does all you suggest automatically (more or less ;-)). But you are right: Files would have to be moved for that. Regards, Matt worodin schrieb: > Hey ho list! > > Is there any opinion regarding the ideas I mentioned in > https://sourceforge.net/tracker/?func=detail&atid=315278&aid=1581944&group_id=15278? > > What I'm suggesting there is, moving into the direction of a layout, > that has been prouven in many open source projects. > > A.) > Arguments for separating sources from generated output (e. g. classes) > - much easier to do a clean > - no need to to maintain .cvsignore, IDE view filters etc just to have a > nice and clean screen. > - fewer messy exclusion filters in ant > > B.) > Arguments for separating test from application sources: > - fewer messy exclusion filters in ant > - easier separation of sources, even if they are not in a *.test.* > package and do not contain the infix *Test* e. g. for javadoc, jar. > > - Only drawback here: you need to navigate two trees (actually, I don't > see this as a drawback, but rather as a visual aid) > > A.) is easy to achieve with the current CVS layout, but B.) would > require moving some things around. In CVS this would result in loosing > the change history. Now I'm remembering remotely somebody else > suggesting to move to SVN. Doing so, would offer the following: > > - First, migrate to SVN first. SVN documentation states, that CVS > history can be ported too. > - Then start B.) SVN versions directories, keeping the history, when > moving files. > > Let me know, what you think of it. > > > Thomas > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Junit-devel mailing list > Jun...@li... > https://lists.sourceforge.net/lists/listinfo/junit-devel > > |
From: worodin <wo...@fr...> - 2006-10-21 23:41:30
|
Hey ho list! As a reference for this thread, pls take a look at https://sourceforge.net/tracker/?func=detail&atid=315278&aid=1581916&group_id=15278 and try the jar. E. g. executing a task like <exec executable="C:/dev/tool/sun/j2sdk/1.5.0_07/bin/apt.exe"> <arg line='-classpath ".;./junit4.1/junit-4.1.jar" -nocompile -d "." org/junit/tests/apt/*.java'/> </exec> against the test classes supplied in the patch would yield: [exec] org/junit/tests/apt/AllTests.java:41: The abstract test class org.junit.tests.apt.TestAfter can not be instanced by suite runner [exec] public class AllTests { [exec] ^ [exec] org/junit/tests/apt/AllTests.java:41: The abstract test class org.junit.tests.apt.TestAfterClass can not be instanced by suite runner [exec] public class AllTests { [exec] ^ [exec] org/junit/tests/apt/AllTests.java:41: The abstract test class org.junit.tests.apt.TestBefore can not be instanced by suite runner [exec] public class AllTests { [exec] ^ [exec] org/junit/tests/apt/AllTests.java:41: The abstract test class org.junit.tests.apt.TestBeforeClass can not be instanced by suite runner [exec] public class AllTests { [exec] ^ [exec] org/junit/tests/apt/AllTests.java:41: The abstract test class org.junit.tests.apt.Quiet can not be instanced by suite runner [exec] public class AllTests { [exec] ^ [exec] org/junit/tests/apt/EmptySuiteClasses.java:11: warning: Annotation @SuiteClasses was empty - nothing to test. [exec] public class EmptySuiteClasses {} [exec] ^ [exec] org/junit/tests/apt/NoSuiteClasses.java:8: warning: Classes annotated with @RunWith(Suite.class) should also be annotated with a non empty @SuiteClasses({}). The resulting test suite is empty. [exec] public class NoSuiteClasses {} [exec] ^ [exec] org/junit/tests/apt/NotThrowing.java:7: Checked Exception org.junit.tests.apt.NotThrowing.MyException will never be thrown, because it isn't declared for method notThrowing. This test will allways fail. [exec] @Test(expected=MyException.class) public void notThrowing() {} [exec] ^ [exec] org/junit/tests/apt/OrphanedSuite.java:7: warning: The annotation @SuiteClasses({...}) is only of use for classes also annotated with @RunWith(Suite.class). [exec] public class OrphanedSuite {} [exec] ^ [exec] org/junit/tests/apt/StaticTest.java:7: Methods annotated with org.junit.Test must not be static. [exec] @Test public static void staticTest() {} [exec] ^ [exec] org/junit/tests/apt/TestAfter.java:7: Methods annotated with org.junit.After need to return void. [exec] @After public int notVoid(Object o) {return 0;} [exec] ^ [exec] org/junit/tests/apt/TestAfter.java:7: Methods annotated with org.junit.After shouldn't have parameters. [exec] @After public int notVoid(Object o) {return 0;} [exec] ^ [exec] org/junit/tests/apt/TestAfterClass.java:7: Methods annotated with org.junit.AfterClass need to be public. [exec] @AfterClass void notPublic(Object o) {} [exec] ^ [exec] org/junit/tests/apt/TestAfterClass.java:7: Methods annotated with org.junit.AfterClass shouldn't have parameters. [exec] @AfterClass void notPublic(Object o) {} [exec] ^ [exec] org/junit/tests/apt/TestAfterClass.java:7: Methods annotated with org.junit.AfterClass need to be static. [exec] @AfterClass void notPublic(Object o) {} [exec] ^ [exec] org/junit/tests/apt/TestBefore.java:7: Methods annotated with org.junit.Before need to be public. [exec] @Before int notPublicNotVoid() {return 0;} [exec] ^ [exec] org/junit/tests/apt/TestBefore.java:7: Methods annotated with org.junit.Before need to return void. [exec] @Before int notPublicNotVoid() {return 0;} [exec] ^ [exec] org/junit/tests/apt/TestBeforeClass.java:7: Methods annotated with org.junit.BeforeClass need to be public. [exec] @BeforeClass int notPublicNotVoid(Object o) {return 0;} [exec] ^ [exec] org/junit/tests/apt/TestBeforeClass.java:7: Methods annotated with org.junit.BeforeClass need to return void. [exec] @BeforeClass int notPublicNotVoid(Object o) {return 0;} [exec] ^ [exec] org/junit/tests/apt/TestBeforeClass.java:7: Methods annotated with org.junit.BeforeClass shouldn't have parameters. [exec] @BeforeClass int notPublicNotVoid(Object o) {return 0;} [exec] ^ [exec] org/junit/tests/apt/TestBeforeClass.java:7: Methods annotated with org.junit.BeforeClass need to be static. [exec] @BeforeClass int notPublicNotVoid(Object o) {return 0;} [exec] ^ [exec] org/junit/tests/apt/TestHasParameters.java:7: Methods annotated with org.junit.Test shouldn't have parameters. [exec] @Test public void hasParameters(Object o) {} [exec] ^ [exec] org/junit/tests/apt/TestInheritedParameters.java:11: Methods annotated with org.junit.runners.Parameterized.Parameters are required to return java.util.Collection<java.lang.Object[]>. [exec] @Parameters public static Object data2() {return new Object();} [exec] ^ [exec] org/junit/tests/apt/TestNotPublic.java:7: Methods annotated with org.junit.Test need to be public. [exec] @Test void notPublic() {} [exec] ^ [exec] org/junit/tests/apt/TestNotVoid.java:7: Methods annotated with org.junit.Test need to return void. [exec] @Test public int notVoid() {return 0;} [exec] ^ [exec] org/junit/tests/apt/TestParameterizedWith2Constructors.java:15: Constructor competes with one allready seen at org/junit/tests/apt/TestParameterizedWith2Constructors.java:14 - classes annotated with @RunWith(Parameterized.class) require exactly one public constructor taking the parameters. [exec] public TestParameterizedWith2Constructors() {} [exec] ^ [exec] org/junit/tests/apt/TestParameterizedWith2Constructors.java:12: org.junit.tests.apt.TestParameterizedWith2Constructors contains 2 public constructors - classes annotated with @RunWith(Parameterized.class) require exactly one public constructor taking the parameters. [exec] public class TestParameterizedWith2Constructors { [exec] ^ [exec] org/junit/tests/apt/TestParameterizedWith2ParameterMethods.java:26: warning: Method annotated with @Parameters competes with one allready seen at org/junit/tests/apt/TestParameterizedWith2ParameterMethods.java:20 - as of Junit 4.1, only one of them will be used to retrieve test parameters. [exec] @Parameters public static Collection<Object[]> data2() { [exec] ^ [exec] org/junit/tests/apt/TestParameterizedWith2ParameterMethods.java:11: warning: There are 2 competing methods all annotated with @Parameters - as of Junit 4.1, only one of them will be used to retrieve test parameters. [exec] public class TestParameterizedWith2ParameterMethods { [exec] ^ [exec] org/junit/tests/apt/TestParameterizedWithNoParameterMethods.java:9: Class org.junit.tests.apt.TestParameterizedWithNoParameterMethods is not abstract, annotated as @RunWith(Parameterized.class), but there is no instance method annotated with @Parameters within the type hierarchy: There will be nothing to test. [exec] public class TestParameterizedWithNoParameterMethods { [exec] ^ [exec] org/junit/tests/apt/TestParameters.java:11: Methods annotated with org.junit.runners.Parameterized.Parameters are required to return java.util.Collection<java.lang.Object[]>. [exec] @Parameters public static Object data2() {return new Object();} [exec] ^ [exec] org/junit/tests/apt/SuiteCycle.java:25: The following classes annotated with @RunWith(Suite.class) form a loop: org.junit.tests.apt.SuiteCycle.ASuite -> org.junit.tests.apt.SuiteCycle.AnotherSuite - invoking any of them will result in a stack overflow at runtime. [exec] public static class ASuite {} [exec] ^ [exec] org/junit/tests/apt/SuiteCycle.java:25: Referenced suite org.junit.tests.apt.SuiteCycle.AnotherSuite is part of or references a loop of suits - invokation will cause a stack overflow at runtime. [exec] public static class ASuite {} [exec] ^ [exec] org/junit/tests/apt/SuiteCycle.java:21: Referenced suite org.junit.tests.apt.SuiteCycle.ASuite is part of or references a loop of suits - invokation will cause a stack overflow at runtime. [exec] public class SuiteCycle { [exec] ^ [exec] org/junit/tests/apt/AllTests.java:41: Referenced suite org.junit.tests.apt.SuiteCycle is part of or references a loop of suits - invokation will cause a stack overflow at runtime. [exec] public class AllTests { [exec] ^ [exec] org/junit/tests/apt/NoTestInSuiteClass.java:11: warning: Test case org.junit.tests.apt.NoTestInSuiteClass doesn't contain any test methods. [exec] public class NoTestInSuiteClass {} [exec] ^ [exec] org/junit/tests/apt/NoSuiteClasses.java:8: warning: Test case org.junit.tests.apt.NoSuiteClasses doesn't contain any test methods. [exec] public class NoSuiteClasses {} [exec] ^ [exec] org/junit/tests/apt/EmptySuiteClasses.java:11: warning: Test case org.junit.tests.apt.EmptySuiteClasses doesn't contain any test methods. [exec] public class EmptySuiteClasses {} [exec] ^ [exec] org/junit/tests/apt/ClassNotPublic.java:9: Class org.junit.tests.apt.ClassNotPublic has to be public in order to be instanced. [exec] class ClassNotPublic { [exec] ^ [exec] org/junit/tests/apt/NoValidConstructors.java:6: This test class requires a public no argument constructor. [exec] public class NoValidConstructors { [exec] ^ [exec] 32 errors [exec] 8 warnings [exec] Result: 1 As far as I can tell, the checks are pretty complete, but I'm open to suggestions. The processor might do with some refactoring, but hey, it's my first try at apt. I see several spin offs: - the apt processor uses 20+ messages (Errors and warnings), some of them intersecting with runtime messages. It might be viable, to start pooling all messages used in org.junit in a jdk 1.5 enumeration. - as an afterthought, I wonder if we really need @RunWith. AFAICT, the proper runner can mostly infered from an other annotation, e. g. @SuiteClasses or @Parameters, leaving the rest to the default runner. - the patch contains a test, that runs apt on a isolated file, checking for results. This could be evolved into a pattern for testing apt processors. Hope this is of interest. Thomas |
From: worodin <wo...@fr...> - 2006-10-21 21:00:25
|
Hey ho list! Is there any opinion regarding the ideas I mentioned in https://sourceforge.net/tracker/?func=detail&atid=315278&aid=1581944&group_id=15278? What I'm suggesting there is, moving into the direction of a layout, that has been prouven in many open source projects. A.) Arguments for separating sources from generated output (e. g. classes) - much easier to do a clean - no need to to maintain .cvsignore, IDE view filters etc just to have a nice and clean screen. - fewer messy exclusion filters in ant B.) Arguments for separating test from application sources: - fewer messy exclusion filters in ant - easier separation of sources, even if they are not in a *.test.* package and do not contain the infix *Test* e. g. for javadoc, jar. - Only drawback here: you need to navigate two trees (actually, I don't see this as a drawback, but rather as a visual aid) A.) is easy to achieve with the current CVS layout, but B.) would require moving some things around. In CVS this would result in loosing the change history. Now I'm remembering remotely somebody else suggesting to move to SVN. Doing so, would offer the following: - First, migrate to SVN first. SVN documentation states, that CVS history can be ported too. - Then start B.) SVN versions directories, keeping the history, when moving files. Let me know, what you think of it. Thomas |
From: David S. <ds...@us...> - 2006-10-18 20:36:15
|
Update of /cvsroot/junit/junit/org/junit/internal/runners In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv29935/org/junit/internal/runners Modified Files: Tag: saff_r41_runner_refactoring TestClassMethodsRunner.java TestEnvironment.java JavaTestInterpreter.java MethodValidator.java TestClassRunner.java Removed Files: Tag: saff_r41_runner_refactoring JavaMethod.java JavaMethodList.java JavaModelElement.java JavaClass.java Log Message: Moved model elements into their own package (although this leads to circularities), for easier review. Also introduced WrappedJavaModelElement Index: TestClassMethodsRunner.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/TestClassMethodsRunner.java,v retrieving revision 1.3.2.5 retrieving revision 1.3.2.6 diff -u -d -r1.3.2.5 -r1.3.2.6 --- TestClassMethodsRunner.java 18 Oct 2006 19:36:35 -0000 1.3.2.5 +++ TestClassMethodsRunner.java 18 Oct 2006 20:36:08 -0000 1.3.2.6 @@ -1,5 +1,7 @@ package org.junit.internal.runners; +import org.junit.internal.javamodel.JavaClass; +import org.junit.internal.javamodel.JavaMethodList; import org.junit.runner.Description; import org.junit.runner.Runner; import org.junit.runner.manipulation.Filter; Index: TestEnvironment.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/TestEnvironment.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -d -r1.1.2.2 -r1.1.2.3 --- TestEnvironment.java 18 Oct 2006 19:36:35 -0000 1.1.2.2 +++ TestEnvironment.java 18 Oct 2006 20:36:08 -0000 1.1.2.3 @@ -17,7 +17,7 @@ fNotifier= notifier; } - JavaTestInterpreter getInterpreter() { + public JavaTestInterpreter getInterpreter() { return fInterpreter; } Index: JavaTestInterpreter.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/JavaTestInterpreter.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -d -r1.1.2.4 -r1.1.2.5 --- JavaTestInterpreter.java 18 Oct 2006 19:36:35 -0000 1.1.2.4 +++ JavaTestInterpreter.java 18 Oct 2006 20:36:08 -0000 1.1.2.5 @@ -3,6 +3,8 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import org.junit.internal.javamodel.JavaClass; +import org.junit.internal.javamodel.JavaMethod; import org.junit.runner.Runner; public class JavaTestInterpreter { @@ -25,7 +27,7 @@ javaMethod.invoke(test); } - public Runner runnerFor(Class<?> klass) throws InitializationError { + public Runner buildRunner(Class<?> klass) throws InitializationError { MethodValidator methodValidator= new MethodValidator(klass); validate(methodValidator); methodValidator.assertValid(); @@ -36,7 +38,7 @@ methodValidator.validateAllMethods(); } - protected JavaMethod interpretJavaMethod(final JavaClass klass, Method method) { + public JavaMethod interpretJavaMethod(final JavaClass klass, Method method) { return new JavaMethod(klass, method); } } Index: MethodValidator.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/MethodValidator.java,v retrieving revision 1.3.2.3 retrieving revision 1.3.2.4 diff -u -d -r1.3.2.3 -r1.3.2.4 --- MethodValidator.java 18 Oct 2006 19:36:35 -0000 1.3.2.3 +++ MethodValidator.java 18 Oct 2006 20:36:08 -0000 1.3.2.4 @@ -11,6 +11,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import org.junit.internal.javamodel.JavaClass; public class MethodValidator { private final List<Throwable> fErrors= new ArrayList<Throwable>(); Index: TestClassRunner.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/TestClassRunner.java,v retrieving revision 1.2.2.4 retrieving revision 1.2.2.5 diff -u -d -r1.2.2.4 -r1.2.2.5 --- TestClassRunner.java 18 Oct 2006 19:36:35 -0000 1.2.2.4 +++ TestClassRunner.java 18 Oct 2006 20:36:08 -0000 1.2.2.5 @@ -1,5 +1,6 @@ package org.junit.internal.runners; +import org.junit.internal.javamodel.JavaClass; import org.junit.runner.Description; import org.junit.runner.Runner; import org.junit.runner.manipulation.Filter; @@ -21,12 +22,7 @@ public TestClassRunner(Class<?> klass, JavaTestInterpreter interpreter) throws InitializationError { fTestClass= klass; - fEnclosedRunner= interpreter.runnerFor(klass); - } - - // TODO: this is parallel to passed-in runner - protected void validate(MethodValidator methodValidator) { - methodValidator.validateAllMethods(); + fEnclosedRunner= interpreter.buildRunner(klass); } @Override --- JavaMethod.java DELETED --- --- JavaMethodList.java DELETED --- --- JavaModelElement.java DELETED --- --- JavaClass.java DELETED --- |
Update of /cvsroot/junit/junit/org/junit/tests In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv29935/org/junit/tests Modified Files: Tag: saff_r41_runner_refactoring ParameterizedTestMethodTest.java SortableTest.java TestMethodTest.java CustomRunnerTest.java Log Message: Moved model elements into their own package (although this leads to circularities), for easier review. Also introduced WrappedJavaModelElement Index: ParameterizedTestMethodTest.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/tests/ParameterizedTestMethodTest.java,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -d -r1.2.2.1 -r1.2.2.2 --- ParameterizedTestMethodTest.java 17 Oct 2006 19:10:20 -0000 1.2.2.1 +++ ParameterizedTestMethodTest.java 18 Oct 2006 20:36:08 -0000 1.2.2.2 @@ -1,6 +1,6 @@ package org.junit.tests; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; import java.util.Arrays; import java.util.Collection; @@ -14,7 +14,6 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.internal.runners.InitializationError; -import org.junit.internal.runners.JavaTestInterpreter; import org.junit.internal.runners.TestClassRunner; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -86,7 +85,7 @@ private List<Throwable> validateAllMethods(Class<?> clazz) { try { - new TestClassRunner(clazz, new JavaTestInterpreter()); + new TestClassRunner(clazz); } catch (InitializationError e) { return e.getCauses(); } Index: SortableTest.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/tests/SortableTest.java,v retrieving revision 1.5.2.1 retrieving revision 1.5.2.2 diff -u -d -r1.5.2.1 -r1.5.2.2 --- SortableTest.java 18 Oct 2006 18:22:14 -0000 1.5.2.1 +++ SortableTest.java 18 Oct 2006 20:36:08 -0000 1.5.2.2 @@ -170,7 +170,7 @@ TestClassRunner runner= new TestClassRunner(Unsortable.class, new JavaTestInterpreter() { @Override - public Runner runnerFor(Class<?> klass) + public Runner buildRunner(Class<?> klass) throws InitializationError { return new UnsortableRunner(klass); } Index: TestMethodTest.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/tests/TestMethodTest.java,v retrieving revision 1.3.2.1 retrieving revision 1.3.2.2 diff -u -d -r1.3.2.1 -r1.3.2.2 --- TestMethodTest.java 17 Oct 2006 19:10:20 -0000 1.3.2.1 +++ TestMethodTest.java 18 Oct 2006 20:36:08 -0000 1.3.2.2 @@ -1,7 +1,6 @@ package org.junit.tests; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import java.util.Collections; import java.util.List; @@ -15,7 +14,6 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.internal.runners.InitializationError; -import org.junit.internal.runners.JavaTestInterpreter; import org.junit.internal.runners.MethodValidator; import org.junit.internal.runners.TestClassRunner; import org.junit.runner.JUnitCore; @@ -87,7 +85,7 @@ private List<Throwable> validateAllMethods(Class<?> clazz) { try { - new TestClassRunner(clazz, new JavaTestInterpreter()); + new TestClassRunner(clazz); } catch (InitializationError e) { return e.getCauses(); } Index: CustomRunnerTest.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/tests/CustomRunnerTest.java,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -d -r1.2.2.1 -r1.2.2.2 --- CustomRunnerTest.java 17 Oct 2006 19:10:20 -0000 1.2.2.1 +++ CustomRunnerTest.java 18 Oct 2006 20:36:08 -0000 1.2.2.2 @@ -6,7 +6,7 @@ import org.junit.Assert; import org.junit.Test; -import org.junit.internal.runners.JavaMethod; +import org.junit.internal.javamodel.JavaMethod; import org.junit.internal.runners.JavaTestInterpreter; import org.junit.runner.JUnitCore; |
Update of /cvsroot/junit/junit/org/junit/internal/javamodel In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv29935/org/junit/internal/javamodel Added Files: Tag: saff_r41_runner_refactoring JavaModelElement.java JavaMethod.java JavaMethodList.java WrappedJavaModelElement.java JavaClass.java Log Message: Moved model elements into their own package (although this leads to circularities), for easier review. Also introduced WrappedJavaModelElement --- NEW FILE: JavaModelElement.java --- package org.junit.internal.javamodel; import org.junit.runner.Description; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunNotifier; public abstract class JavaModelElement { public abstract String getName(); public void addFailure(RunNotifier runNotifier, Throwable targetException) { runNotifier .fireTestFailure(new Failure(description(), targetException)); } protected abstract Description description(); } --- NEW FILE: JavaMethod.java --- /** * */ package org.junit.internal.javamodel; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.Test.None; import org.junit.internal.runners.MethodAnnotation; import org.junit.internal.runners.TestEnvironment; import org.junit.runner.Description; // TODO: check names of various "run" methods public class JavaMethod extends WrappedJavaModelElement { // TODO: push out private final Method fMethod; private final JavaClass fJavaClass; public JavaMethod(JavaClass javaClass, Method current) { fJavaClass= javaClass; fMethod= current; } public Annotation getAnnotation(MethodAnnotation methodAnnotation) { return fMethod.getAnnotation(methodAnnotation.getAnnotationClass()); } boolean isIgnored() { return fMethod.getAnnotation(Ignore.class) != null; } long getTimeout() { return getTestAnnotation().timeout(); } private Test getTestAnnotation() { return fMethod.getAnnotation(Test.class); } Class<? extends Throwable> expectedException() { Test annotation= getTestAnnotation(); if (annotation.expected() == None.class) return null; else return annotation.expected(); } boolean isUnexpected(Throwable exception) { return !expectedException().isAssignableFrom(exception.getClass()); } boolean expectsException() { return expectedException() != null; } public Object invoke(Object object) throws IllegalAccessException, InvocationTargetException { return fMethod.invoke(object); } @Override public String getName() { return fMethod.getName(); } // TODO: push out @Override public Description description() { return Description.createTestDescription(fJavaClass.getTestClass(), getName()); } // TODO: push out @Override public JavaClass getJavaClass() { return fJavaClass; } @Override public Class<? extends Annotation> getAfterAnnotation() { return After.class; } @Override public Class<? extends Annotation> getBeforeAnnotation() { return Before.class; } public void runWithoutBeforeAndAfter(TestEnvironment environment, Object test) { // TODO: is this envious of environment? try { environment.getInterpreter().executeMethodBody(test, this); if (expectsException()) addFailure(environment.getRunNotifier(), new AssertionError( "Expected exception: " + expectedException().getName())); } catch (InvocationTargetException e) { Throwable actual= e.getTargetException(); if (!expectsException()) addFailure(environment.getRunNotifier(), actual); else if (isUnexpected(actual)) { String message= "Unexpected exception, expected<" + expectedException().getName() + "> but was<" + actual.getClass().getName() + ">"; addFailure(environment.getRunNotifier(), new Exception(message, actual)); } } catch (Throwable e) { // TODO: DUP on environment.getRunNotifier addFailure(environment.getRunNotifier(), e); } } void invokeTestMethod(TestEnvironment testEnvironment) { Object test; try { test= getJavaClass().newInstance(); } catch (Exception e) { testEnvironment.getRunNotifier().testAborted(description(), e); return; } run(testEnvironment, test); } void runWithoutTimeout(final Object test, final TestEnvironment testEnvironment) { // TODO: is this envious now? Yes runWithBeforeAndAfter(new Runnable() { public void run() { runWithoutBeforeAndAfter(testEnvironment, test); } }, test, testEnvironment.getRunNotifier()); // TODO: ugly } void runWiteTimeout(long timeout, final Object test, final TestEnvironment testEnvironment) { ExecutorService service= Executors.newSingleThreadExecutor(); Callable<Object> callable= new Callable<Object>() { public Object call() throws Exception { runWithoutTimeout(test, testEnvironment); return null; } }; Future<Object> result= service.submit(callable); service.shutdown(); try { boolean terminated= service.awaitTermination(timeout, TimeUnit.MILLISECONDS); if (!terminated) service.shutdownNow(); result.get(timeout, TimeUnit.MILLISECONDS); // throws the exception // if one occurred // during the invocation } catch (TimeoutException e) { addFailure(testEnvironment.getRunNotifier(), new Exception(String .format("test timed out after %d milliseconds", timeout))); } catch (Exception e) { // TODO: DUP addFailure(testEnvironment.getRunNotifier(), e); } } void run(TestEnvironment environment, Object test) { if (isIgnored()) { environment.getRunNotifier().fireTestIgnored(description()); return; } environment.getRunNotifier().fireTestStarted(description()); try { long timeout= getTimeout(); if (timeout > 0) runWiteTimeout(timeout, test, environment); else runWithoutTimeout(test, environment); } finally { environment.getRunNotifier().fireTestFinished(description()); } } } --- NEW FILE: JavaMethodList.java --- package org.junit.internal.javamodel; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import java.util.List; import org.junit.internal.runners.TestEnvironment; import org.junit.runner.Description; import org.junit.runner.manipulation.Filter; import org.junit.runner.manipulation.NoTestsRemainException; import org.junit.runner.manipulation.Sorter; public class JavaMethodList extends JavaModelElement implements Iterable<JavaMethod> { private static final long serialVersionUID= 1L; private final JavaClass fJavaClass; private List<JavaMethod> fMethods= new ArrayList<JavaMethod>(); public JavaMethodList(JavaClass javaClass) { fJavaClass= javaClass; } public void filter(Filter filter) throws NoTestsRemainException { for (Iterator<JavaMethod> iter= fMethods.iterator(); iter.hasNext();) { JavaMethod method= iter.next(); if (!filter.shouldRun(method.description())) iter.remove(); } if (fMethods.isEmpty()) throw new NoTestsRemainException(); } public void filter(final Sorter sorter) { Collections.sort(fMethods, new Comparator<JavaMethod>() { public int compare(JavaMethod o1, JavaMethod o2) { return sorter.compare(o1.description(), o2.description()); } }); } @Override public String getName() { return String.format("%s methods", fJavaClass.getName()); } public Iterator<JavaMethod> iterator() { return fMethods.iterator(); } public void add(JavaMethod eachMethod) { fMethods.add(eachMethod); } public boolean isEmpty() { return fMethods.isEmpty(); } public void reverse() { Collections.reverse(fMethods); } @Override public Description description() { Description spec= Description.createSuiteDescription(fJavaClass .getName()); for (JavaMethod method : this) spec.addChild(method.description()); return spec; } public void run(TestEnvironment environment) { if (isEmpty()) // TODO: DUP environment.getRunNotifier().testAborted(description(), new Exception( "No runnable methods")); for (JavaMethod method : this) { method.invokeTestMethod(environment); } } } --- NEW FILE: WrappedJavaModelElement.java --- package org.junit.internal.javamodel; import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.util.List; import org.junit.internal.runners.FailedBefore; import org.junit.runner.notification.RunNotifier; public abstract class WrappedJavaModelElement extends JavaModelElement { public abstract Class<? extends Annotation> getBeforeAnnotation(); public abstract Class<? extends Annotation> getAfterAnnotation(); public abstract JavaClass getJavaClass(); void runAfters(Object test, RunNotifier runNotifier) { // TODO: train wreck for (Method after : getJavaClass().getMethods( getAfterAnnotation())) { try { after.invoke(test); } catch (Throwable e) { addFailure(runNotifier, e); } } } void runBefores(Object test, RunNotifier runNotifier) throws FailedBefore { try { List<Method> befores= getJavaClass().getMethods( getBeforeAnnotation()); // TODO: no auto-correct if wrong type on left side of new-style // for? for (Method before : befores) before.invoke(test); } catch (Throwable e) { addFailure(runNotifier, e); throw new FailedBefore(); } } public void runWithBeforeAndAfter(Runnable protectThis, Object test, RunNotifier runNotifier) { try { runBefores(test, runNotifier); protectThis.run(); } catch (FailedBefore e) { } finally { runAfters(test, runNotifier); } } } --- NEW FILE: JavaClass.java --- /** * */ package org.junit.internal.javamodel; import java.lang.annotation.Annotation; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; import org.junit.internal.runners.JavaTestInterpreter; import org.junit.internal.runners.MethodAnnotation; import org.junit.runner.Description; public class JavaClass extends WrappedJavaModelElement { // TODO: push out private final Class<?> fClass; public JavaClass(Class<?> type) { fClass= type; } public List<JavaClass> getSuperClasses() { ArrayList<JavaClass> results= new ArrayList<JavaClass>(); results.add(this); // TODO: this will not add parameterized superclasses (need to use // interpreter here?) if (fClass.getSuperclass() != null) results.addAll(new JavaClass(fClass.getSuperclass()) .getSuperClasses()); return results; } public List<Method> getMethods(MethodAnnotation methodAnnotation) { List<Method> results= new ArrayList<Method>(); for (JavaClass eachClass : getSuperClasses()) { for (Method eachMethod : eachClass.getDeclaredMethods()) { Annotation annotation= eachMethod .getAnnotation(methodAnnotation.getAnnotationClass()); if (annotation != null && !isShadowedBy(eachMethod, results)) results.add(eachMethod); } } if (methodAnnotation.runsTopToBottom()) Collections.reverse(results); return results; } private boolean isShadowedBy(Method target, Method previous) { if (!previous.getName().equals(target.getName())) return false; if (previous.getParameterTypes().length != target.getParameterTypes().length) return false; for (int i= 0; i < previous.getParameterTypes().length; i++) { if (!previous.getParameterTypes()[i].equals(target .getParameterTypes()[i])) return false; } return true; } boolean isShadowedBy(Method target, List<Method> results) { for (Method each : results) { if (isShadowedBy(target, each)) return true; } return false; } private Method[] getDeclaredMethods() { return fClass.getDeclaredMethods(); } public List<Method> getMethods(Class<? extends Annotation> type) { return getMethods(new MethodAnnotation(type)); } public Class getTestClass() { return fClass; } public void validateNoArgConstructor(List<Throwable> errors) { try { getTestClass().getConstructor(); } catch (Exception e) { errors.add(new Exception( "Test class should have public zero-argument constructor", e)); } } @Override public String getName() { return fClass.getName(); } protected Object newInstance() throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { return getTestClass().getConstructor().newInstance(); } @Override public Class<? extends Annotation> getAfterAnnotation() { return AfterClass.class; } @Override public Class<? extends Annotation> getBeforeAnnotation() { return BeforeClass.class; } @Override public JavaClass getJavaClass() { return this; } public JavaMethodList getTestMethods(JavaTestInterpreter javaTestInterpreter) { List<Method> methods= getMethods(Test.class); JavaMethodList list= new JavaMethodList(this); for (Method method : methods) { list.add(javaTestInterpreter.interpretJavaMethod(this, method)); } return list; } @Override protected Description description() { return Description.createSuiteDescription(fClass); } } |
From: David S. <ds...@us...> - 2006-10-18 20:36:12
|
Update of /cvsroot/junit/junit/org/junit/runners In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv29935/org/junit/runners Modified Files: Tag: saff_r41_runner_refactoring ParameterizedInterpreter.java Suite.java Log Message: Moved model elements into their own package (although this leads to circularities), for easier review. Also introduced WrappedJavaModelElement Index: ParameterizedInterpreter.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/runners/Attic/ParameterizedInterpreter.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -d -r1.1.2.3 -r1.1.2.4 --- ParameterizedInterpreter.java 18 Oct 2006 19:36:35 -0000 1.1.2.3 +++ ParameterizedInterpreter.java 18 Oct 2006 20:36:08 -0000 1.1.2.4 @@ -12,10 +12,10 @@ import java.util.Collection; import java.util.List; +import org.junit.internal.javamodel.JavaClass; +import org.junit.internal.javamodel.JavaMethod; import org.junit.internal.runners.CompositeRunner; import org.junit.internal.runners.InitializationError; -import org.junit.internal.runners.JavaClass; -import org.junit.internal.runners.JavaMethod; import org.junit.internal.runners.JavaTestInterpreter; import org.junit.internal.runners.MethodValidator; import org.junit.internal.runners.TestClassMethodsRunner; @@ -56,7 +56,7 @@ } @Override - protected JavaMethod interpretJavaMethod(final JavaClass klass, + public JavaMethod interpretJavaMethod(final JavaClass klass, Method method) { return new JavaMethod(klass, method) { @Override @@ -71,7 +71,7 @@ // TODO: pull interpreter back in? @Override - public Runner runnerFor(Class klass) throws InitializationError { + public Runner buildRunner(Class klass) throws InitializationError { CompositeRunner runner= new CompositeRunner(klass.getName()); int i= 0; for (final Object each : getParametersList(new JavaClass(klass))) { Index: Suite.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/runners/Suite.java,v retrieving revision 1.4.2.1 retrieving revision 1.4.2.2 diff -u -d -r1.4.2.1 -r1.4.2.2 --- Suite.java 18 Oct 2006 18:22:14 -0000 1.4.2.1 +++ Suite.java 18 Oct 2006 20:36:08 -0000 1.4.2.2 @@ -45,7 +45,7 @@ public Suite(Class<?> klass, final Class[] annotatedClasses) throws InitializationError { super(klass, new JavaTestInterpreter() { @Override - public Runner runnerFor(Class<?> klass) throws InitializationError { + public Runner buildRunner(Class<?> klass) throws InitializationError { return Request.classes(klass.getName(), annotatedClasses) .getRunner(); } |
From: David S. <ds...@us...> - 2006-10-18 20:36:07
|
Update of /cvsroot/junit/junit/org/junit/internal/javamodel In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv29582/org/junit/internal/javamodel Log Message: Directory /cvsroot/junit/junit/org/junit/internal/javamodel added to the repository --> Using per-directory sticky tag `saff_r41_runner_refactoring' |
Update of /cvsroot/junit/junit/org/junit/internal/runners In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv6163/org/junit/internal/runners Modified Files: Tag: saff_r41_runner_refactoring JavaMethod.java TestClassMethodsRunner.java JavaMethodList.java JavaTestInterpreter.java TestEnvironment.java JavaModelElement.java MethodValidator.java JavaClass.java TestClassRunner.java Removed Files: Tag: saff_r41_runner_refactoring PerTestNotifier.java TestMethodRunner.java Log Message: PerTestNotifier is gone Index: JavaMethod.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/JavaMethod.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -d -r1.1.2.4 -r1.1.2.5 --- JavaMethod.java 18 Oct 2006 18:22:14 -0000 1.1.2.4 +++ JavaMethod.java 18 Oct 2006 19:36:35 -0000 1.1.2.5 @@ -7,7 +7,12 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.junit.After; import org.junit.Before; @@ -15,7 +20,6 @@ import org.junit.Test; import org.junit.Test.None; import org.junit.runner.Description; -import org.junit.runner.notification.RunNotifier; // TODO: check names of various "run" methods @@ -30,28 +34,6 @@ fMethod= current; } - private boolean isShadowedBy(JavaMethod previousJavaMethod) { - Method previous= previousJavaMethod.fMethod; - if (!previous.getName().equals(fMethod.getName())) - return false; - if (previous.getParameterTypes().length != fMethod.getParameterTypes().length) - return false; - for (int i= 0; i < previous.getParameterTypes().length; i++) { - if (!previous.getParameterTypes()[i].equals(fMethod - .getParameterTypes()[i])) - return false; - } - return true; - } - - boolean isShadowedBy(List<JavaMethod> results) { - for (JavaMethod each : results) { - if (isShadowedBy(each)) - return true; - } - return false; - } - public Annotation getAnnotation(MethodAnnotation methodAnnotation) { return fMethod.getAnnotation(methodAnnotation.getAnnotationClass()); } @@ -94,30 +76,8 @@ return fMethod.getName(); } - void validateAsTestMethod(boolean isStatic, List<Throwable> errors) { - Method each= fMethod; - if (Modifier.isStatic(each.getModifiers()) != isStatic) { - String state= isStatic ? "should" : "should not"; - errors.add(new Exception("Method " + each.getName() + "() " + state - + " be static")); - } - if (!Modifier.isPublic(each.getDeclaringClass().getModifiers())) - errors - .add(new Exception("Class " - + each.getDeclaringClass().getName() - + " should be public")); - if (!Modifier.isPublic(each.getModifiers())) - errors.add(new Exception("Method " + each.getName() - + " should be public")); - if (each.getReturnType() != Void.TYPE) - errors.add(new Exception("Method " + each.getName() - + " should be void")); - if (each.getParameterTypes().length != 0) - errors.add(new Exception("Method " + each.getName() - + " should have no parameters")); - } - // TODO: push out + @Override public Description description() { return Description.createTestDescription(fJavaClass.getTestClass(), getName()); @@ -154,40 +114,93 @@ public void runWithoutBeforeAndAfter(TestEnvironment environment, Object test) { + // TODO: is this envious of environment? try { environment.getInterpreter().executeMethodBody(test, this); if (expectsException()) - environment - .addFailure(new AssertionError("Expected exception: " - + expectedException().getName())); + addFailure(environment.getRunNotifier(), new AssertionError( + "Expected exception: " + expectedException().getName())); } catch (InvocationTargetException e) { Throwable actual= e.getTargetException(); if (!expectsException()) - environment.addFailure(actual); + addFailure(environment.getRunNotifier(), actual); else if (isUnexpected(actual)) { String message= "Unexpected exception, expected<" + expectedException().getName() + "> but was<" + actual.getClass().getName() + ">"; - environment.addFailure(new Exception(message, actual)); + addFailure(environment.getRunNotifier(), new Exception(message, + actual)); } } catch (Throwable e) { - environment.addFailure(e); + // TODO: DUP on environment.getRunNotifier + addFailure(environment.getRunNotifier(), e); } } - void invokeTestMethod(RunNotifier notifier, JavaTestInterpreter interpreter) { + void invokeTestMethod(TestEnvironment testEnvironment) { Object test; try { test= getJavaClass().newInstance(); - } catch (InvocationTargetException e) { - notifier.testAborted(description(), e.getCause()); + } catch (Exception e) { + testEnvironment.getRunNotifier().testAborted(description(), e); return; + } + run(testEnvironment, test); + } + + void runWithoutTimeout(final Object test, + final TestEnvironment testEnvironment) { + // TODO: is this envious now? Yes + runWithBeforeAndAfter(new Runnable() { + public void run() { + runWithoutBeforeAndAfter(testEnvironment, test); + } + }, test, testEnvironment.getRunNotifier()); + // TODO: ugly + } + + void runWiteTimeout(long timeout, final Object test, + final TestEnvironment testEnvironment) { + ExecutorService service= Executors.newSingleThreadExecutor(); + Callable<Object> callable= new Callable<Object>() { + public Object call() throws Exception { + runWithoutTimeout(test, testEnvironment); + return null; + } + }; + Future<Object> result= service.submit(callable); + service.shutdown(); + try { + boolean terminated= service.awaitTermination(timeout, + TimeUnit.MILLISECONDS); + if (!terminated) + service.shutdownNow(); + result.get(timeout, TimeUnit.MILLISECONDS); // throws the exception + // if one occurred + // during the invocation + } catch (TimeoutException e) { + addFailure(testEnvironment.getRunNotifier(), new Exception(String + .format("test timed out after %d milliseconds", timeout))); } catch (Exception e) { - notifier.testAborted(description(), e); + // TODO: DUP + addFailure(testEnvironment.getRunNotifier(), e); + } + } + + void run(TestEnvironment environment, Object test) { + if (isIgnored()) { + environment.getRunNotifier().fireTestIgnored(description()); return; } - TestEnvironment testEnvironment= new TestEnvironment(interpreter, - new PerTestNotifier(notifier, description()), test); - testEnvironment.run(this); + environment.getRunNotifier().fireTestStarted(description()); + try { + long timeout= getTimeout(); + if (timeout > 0) + runWiteTimeout(timeout, test, environment); + else + runWithoutTimeout(test, environment); + } finally { + environment.getRunNotifier().fireTestFinished(description()); + } } } \ No newline at end of file Index: TestClassMethodsRunner.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/TestClassMethodsRunner.java,v retrieving revision 1.3.2.4 retrieving revision 1.3.2.5 diff -u -d -r1.3.2.4 -r1.3.2.5 --- TestClassMethodsRunner.java 18 Oct 2006 18:22:14 -0000 1.3.2.4 +++ TestClassMethodsRunner.java 18 Oct 2006 19:36:35 -0000 1.3.2.5 @@ -1,7 +1,5 @@ package org.junit.internal.runners; - -import org.junit.Test; import org.junit.runner.Description; import org.junit.runner.Runner; import org.junit.runner.manipulation.Filter; @@ -15,17 +13,13 @@ Sortable { private final JavaMethodList fTestMethods; - private final JavaClass fTestClass; - private final JavaTestInterpreter fInterpreter; // This assumes that some containing runner will perform validation of the // test methods public TestClassMethodsRunner(JavaClass klass, JavaTestInterpreter javaTestInterpreter) { - // TODO: DUP? - fTestClass= klass; - fTestMethods= klass.getMethods(Test.class, javaTestInterpreter); + fTestMethods= klass.getTestMethods(javaTestInterpreter); fInterpreter= javaTestInterpreter; } @@ -33,20 +27,12 @@ @Override public void run(RunNotifier notifier) { - if (fTestMethods.isEmpty()) - notifier.testAborted(getDescription(), new Exception( - "No runnable methods")); - for (JavaMethod method : fTestMethods) - method.invokeTestMethod(notifier, fInterpreter); + fTestMethods.run(new TestEnvironment(fInterpreter, notifier)); } @Override public Description getDescription() { - Description spec= Description.createSuiteDescription(fTestClass - .getName()); - for (JavaMethod method : fTestMethods) - spec.addChild(method.description()); - return spec; + return fTestMethods.description(); } public void filter(Filter filter) throws NoTestsRemainException { Index: JavaMethodList.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/JavaMethodList.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- JavaMethodList.java 18 Oct 2006 17:07:05 -0000 1.1.2.1 +++ JavaMethodList.java 18 Oct 2006 19:36:35 -0000 1.1.2.2 @@ -1,32 +1,101 @@ package org.junit.internal.runners; +import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; +import java.util.List; +import org.junit.runner.Description; import org.junit.runner.manipulation.Filter; import org.junit.runner.manipulation.NoTestsRemainException; import org.junit.runner.manipulation.Sorter; -public class JavaMethodList extends ArrayList<JavaMethod> { +public class JavaMethodList extends JavaModelElement implements + Iterable<JavaMethod> { private static final long serialVersionUID= 1L; + private final JavaClass fJavaClass; + + private List<JavaMethod> fMethods= new ArrayList<JavaMethod>(); + + public JavaMethodList(JavaClass javaClass) { + fJavaClass= javaClass; + } + void filter(Filter filter) throws NoTestsRemainException { - for (Iterator<JavaMethod> iter= iterator(); iter.hasNext();) { + for (Iterator<JavaMethod> iter= fMethods.iterator(); iter.hasNext();) { JavaMethod method= iter.next(); if (!filter.shouldRun(method.description())) iter.remove(); } - if (isEmpty()) + if (fMethods.isEmpty()) throw new NoTestsRemainException(); } void filter(final Sorter sorter) { - Collections.sort(this, new Comparator<JavaMethod>() { + Collections.sort(fMethods, new Comparator<JavaMethod>() { public int compare(JavaMethod o1, JavaMethod o2) { return sorter.compare(o1.description(), o2.description()); } }); } + + @Override + public Class<? extends Annotation> getAfterAnnotation() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Class<? extends Annotation> getBeforeAnnotation() { + // TODO Auto-generated method stub + return null; + } + + @Override + public JavaClass getJavaClass() { + return fJavaClass; + } + + @Override + public String getName() { + return String.format("%s methods", fJavaClass.getName()); + } + + public Iterator<JavaMethod> iterator() { + return fMethods.iterator(); + } + + public void add(JavaMethod eachMethod) { + fMethods.add(eachMethod); + } + + public boolean isEmpty() { + return fMethods.isEmpty(); + } + + public void reverse() { + Collections.reverse(fMethods); + } + + @Override + public Description description() { + Description spec= Description.createSuiteDescription(fJavaClass + .getName()); + for (JavaMethod method : this) + spec.addChild(method.description()); + return spec; + } + + void run(TestEnvironment environment) { + if (isEmpty()) + // TODO: DUP + environment.getRunNotifier().testAborted(description(), new Exception( + "No runnable methods")); + for (JavaMethod method : this) { + method.invokeTestMethod(environment); + } + } } Index: JavaTestInterpreter.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/JavaTestInterpreter.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -d -r1.1.2.3 -r1.1.2.4 --- JavaTestInterpreter.java 18 Oct 2006 18:22:14 -0000 1.1.2.3 +++ JavaTestInterpreter.java 18 Oct 2006 19:36:35 -0000 1.1.2.4 @@ -25,10 +25,6 @@ javaMethod.invoke(test); } - public JavaClass interpretJavaClass(Class<?> superclass) { - return new JavaClass(superclass); - } - public Runner runnerFor(Class<?> klass) throws InitializationError { MethodValidator methodValidator= new MethodValidator(klass); validate(methodValidator); Index: TestEnvironment.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/TestEnvironment.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- TestEnvironment.java 18 Oct 2006 17:07:05 -0000 1.1.2.1 +++ TestEnvironment.java 18 Oct 2006 19:36:35 -0000 1.1.2.2 @@ -3,126 +3,25 @@ */ package org.junit.internal.runners; -import java.lang.annotation.Annotation; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; + +import org.junit.runner.notification.RunNotifier; public class TestEnvironment { private final JavaTestInterpreter fInterpreter; - private final PerTestNotifier fNotifier; - - private final Object fTest; + final RunNotifier fNotifier; public TestEnvironment(JavaTestInterpreter interpreter, - PerTestNotifier notifier, Object test) { + RunNotifier notifier) { fInterpreter= interpreter; fNotifier= notifier; - fTest= test; - } - - void runAfters(Class<? extends Annotation> afterAnnotation, - JavaClass javaClass, Object test) { - List<JavaMethod> afters= javaClass.getMethods(afterAnnotation, - getInterpreter()); - for (JavaMethod after : afters) { - try { - after.invoke(test); - } catch (Throwable e) { - addFailure(e); - } - } - } - - public void runWithBeforeAndAfter(Runnable protectThis, - JavaModelElement element) { - // TODO: is this envious now? Yes - try { - runBefores(element, fTest); - protectThis.run(); - } catch (FailedBefore e) { - } finally { - runAfters(element.getAfterAnnotation(), element.getJavaClass(), fTest); - } - } - - private void runBefores(JavaModelElement element, Object test) throws FailedBefore { - // TODO: envious of environment? - try { - List<JavaMethod> befores= element.getJavaClass().getMethods( - element.getBeforeAnnotation(), getInterpreter()); - - // TODO: no auto-correct if wrong type on left side of new-style - // for? - for (JavaMethod before : befores) - before.invoke(test); - } catch (Throwable e) { - addFailure(e); - throw new FailedBefore(); - } - } - - void runWithoutTimeout(final JavaMethod javaMethod) { - runWithBeforeAndAfter(new Runnable() { - public void run() { - javaMethod.runWithoutBeforeAndAfter(TestEnvironment.this, fTest); - } - }, javaMethod); - } - - void runWithTimeout(long timeout, final JavaMethod method) { - ExecutorService service= Executors.newSingleThreadExecutor(); - Callable<Object> callable= new Callable<Object>() { - public Object call() throws Exception { - runWithoutTimeout(method); - return null; - } - }; - Future<Object> result= service.submit(callable); - service.shutdown(); - try { - boolean terminated= service.awaitTermination(timeout, - TimeUnit.MILLISECONDS); - if (!terminated) - service.shutdownNow(); - result.get(timeout, TimeUnit.MILLISECONDS); // throws the exception - // if one occurred - // during the invocation - } catch (TimeoutException e) { - addFailure(new Exception(String.format( - "test timed out after %d milliseconds", timeout))); - } catch (Exception e) { - addFailure(e); - } - } - - void addFailure(Throwable e) { - fNotifier.addFailure(e); - } - - void run(JavaMethod javaMethod) { - if (javaMethod.isIgnored()) { - fNotifier.fireTestIgnored(); - return; - } - fNotifier.fireTestStarted(); - try { - long timeout= javaMethod.getTimeout(); - if (timeout > 0) - runWithTimeout(timeout, javaMethod); - else - runWithoutTimeout(javaMethod); - } finally { - fNotifier.fireTestFinished(); - } } JavaTestInterpreter getInterpreter() { return fInterpreter; } + + public RunNotifier getRunNotifier() { + return fNotifier; + } } \ No newline at end of file Index: JavaModelElement.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/JavaModelElement.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -d -r1.1.2.2 -r1.1.2.3 --- JavaModelElement.java 18 Oct 2006 17:07:05 -0000 1.1.2.2 +++ JavaModelElement.java 18 Oct 2006 19:36:35 -0000 1.1.2.3 @@ -1,6 +1,12 @@ package org.junit.internal.runners; import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.List; + +import org.junit.runner.Description; +import org.junit.runner.notification.Failure; +import org.junit.runner.notification.RunNotifier; public abstract class JavaModelElement { public abstract String getName(); @@ -10,4 +16,48 @@ public abstract Class<? extends Annotation> getAfterAnnotation(); public abstract JavaClass getJavaClass(); + + public void addFailure(RunNotifier runNotifier, Throwable targetException) { + runNotifier.fireTestFailure(new Failure(description(), targetException)); + } + + protected abstract Description description(); + + void runAfters(Object test, RunNotifier runNotifier) { + // TODO: train wreck + for (Method after : getJavaClass().getMethods( + getAfterAnnotation())) { + try { + after.invoke(test); + } catch (Throwable e) { + addFailure(runNotifier, e); + } + } + } + + void runBefores(Object test, RunNotifier runNotifier) + throws FailedBefore { + try { + List<Method> befores= getJavaClass().getMethods( + getBeforeAnnotation()); + + // TODO: no auto-correct if wrong type on left side of new-style + // for? + for (Method before : befores) + before.invoke(test); + } catch (Throwable e) { + addFailure(runNotifier, e); + throw new FailedBefore(); + } + } + + void runWithBeforeAndAfter(Runnable protectThis, Object test, RunNotifier runNotifier) { + try { + runBefores(test, runNotifier); + protectThis.run(); + } catch (FailedBefore e) { + } finally { + runAfters(test, runNotifier); + } + } } Index: MethodValidator.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/MethodValidator.java,v retrieving revision 1.3.2.2 retrieving revision 1.3.2.3 diff -u -d -r1.3.2.2 -r1.3.2.3 --- MethodValidator.java 18 Oct 2006 17:07:05 -0000 1.3.2.2 +++ MethodValidator.java 18 Oct 2006 19:36:35 -0000 1.3.2.3 @@ -1,6 +1,8 @@ package org.junit.internal.runners; import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.List; @@ -49,9 +51,31 @@ private void validateTestMethods(Class<? extends Annotation> annotation, boolean isStatic) { - List<JavaMethod> methods= fJavaClass.getMethods(annotation, new JavaTestInterpreter()); - for (JavaMethod eachMethod : methods) { - eachMethod.validateAsTestMethod(isStatic, fErrors); + for (Method eachMethod : fJavaClass.getMethods(annotation)) { + validateAsTestMethod(eachMethod, isStatic, fErrors); + } + } + + + void validateAsTestMethod(Method each, boolean isStatic, List<Throwable> errors) { + if (Modifier.isStatic(each.getModifiers()) != isStatic) { + String state= isStatic ? "should" : "should not"; + errors.add(new Exception("Method " + each.getName() + "() " + state + + " be static")); } + if (!Modifier.isPublic(each.getDeclaringClass().getModifiers())) + errors + .add(new Exception("Class " + + each.getDeclaringClass().getName() + + " should be public")); + if (!Modifier.isPublic(each.getModifiers())) + errors.add(new Exception("Method " + each.getName() + + " should be public")); + if (each.getReturnType() != Void.TYPE) + errors.add(new Exception("Method " + each.getName() + + " should be void")); + if (each.getParameterTypes().length != 0) + errors.add(new Exception("Method " + each.getName() + + " should have no parameters")); } } Index: JavaClass.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/JavaClass.java,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -d -r1.1.2.4 -r1.1.2.5 --- JavaClass.java 18 Oct 2006 18:22:14 -0000 1.1.2.4 +++ JavaClass.java 18 Oct 2006 19:36:35 -0000 1.1.2.5 @@ -12,6 +12,8 @@ import org.junit.AfterClass; import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.Description; public class JavaClass extends JavaModelElement { // TODO: push out @@ -33,15 +35,13 @@ return results; } - public JavaMethodList getMethods(MethodAnnotation methodAnnotation, - JavaTestInterpreter interpreter) { - JavaMethodList results= new JavaMethodList(); + public List<Method> getMethods(MethodAnnotation methodAnnotation) { + List<Method> results= new ArrayList<Method>(); for (JavaClass eachClass : getSuperClasses()) { - for (JavaMethod eachMethod : eachClass - .getDeclaredMethods(interpreter)) { + for (Method eachMethod : eachClass.getDeclaredMethods()) { Annotation annotation= eachMethod - .getAnnotation(methodAnnotation); - if (annotation != null && !eachMethod.isShadowedBy(results)) + .getAnnotation(methodAnnotation.getAnnotationClass()); + if (annotation != null && !isShadowedBy(eachMethod, results)) results.add(eachMethod); } } @@ -50,18 +50,33 @@ return results; } - private List<JavaMethod> getDeclaredMethods(JavaTestInterpreter interpreter) { - Method[] declaredMethods= fClass.getDeclaredMethods(); - ArrayList<JavaMethod> javaMethods= new ArrayList<JavaMethod>(); - for (Method method : declaredMethods) { - javaMethods.add(interpreter.interpretJavaMethod(this, method)); + private boolean isShadowedBy(Method target, Method previous) { + if (!previous.getName().equals(target.getName())) + return false; + if (previous.getParameterTypes().length != target.getParameterTypes().length) + return false; + for (int i= 0; i < previous.getParameterTypes().length; i++) { + if (!previous.getParameterTypes()[i].equals(target + .getParameterTypes()[i])) + return false; } - return javaMethods; + return true; } - public JavaMethodList getMethods(Class<? extends Annotation> type, - JavaTestInterpreter interpreter) { - return getMethods(new MethodAnnotation(type), interpreter); + boolean isShadowedBy(Method target, List<Method> results) { + for (Method each : results) { + if (isShadowedBy(target, each)) + return true; + } + return false; + } + + private Method[] getDeclaredMethods() { + return fClass.getDeclaredMethods(); + } + + public List<Method> getMethods(Class<? extends Annotation> type) { + return getMethods(new MethodAnnotation(type)); } public Class getTestClass() { @@ -103,4 +118,18 @@ public JavaClass getJavaClass() { return this; } + + public JavaMethodList getTestMethods(JavaTestInterpreter javaTestInterpreter) { + List<Method> methods= getMethods(Test.class); + JavaMethodList list= new JavaMethodList(this); + for (Method method : methods) { + list.add(javaTestInterpreter.interpretJavaMethod(this, method)); + } + return list; + } + + @Override + protected Description description() { + return Description.createSuiteDescription(fClass); + } } \ No newline at end of file Index: TestClassRunner.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/TestClassRunner.java,v retrieving revision 1.2.2.3 retrieving revision 1.2.2.4 diff -u -d -r1.2.2.3 -r1.2.2.4 --- TestClassRunner.java 18 Oct 2006 18:22:14 -0000 1.2.2.3 +++ TestClassRunner.java 18 Oct 2006 19:36:35 -0000 1.2.2.4 @@ -14,8 +14,6 @@ private final Class<?> fTestClass; - private JavaTestInterpreter fInterpreter; - public TestClassRunner(Class<?> klass) throws InitializationError { this(klass, new JavaTestInterpreter()); } @@ -24,7 +22,6 @@ throws InitializationError { fTestClass= klass; fEnclosedRunner= interpreter.runnerFor(klass); - fInterpreter= interpreter; } // TODO: this is parallel to passed-in runner @@ -40,10 +37,8 @@ } }; - TestEnvironment environment= new TestEnvironment(fInterpreter, - new PerTestNotifier(notifier, getDescription()), null); - environment.runWithBeforeAndAfter(protectThis, new JavaClass( - getTestClass())); + new JavaClass(getTestClass()).runWithBeforeAndAfter(protectThis, null, + notifier); } @Override --- PerTestNotifier.java DELETED --- --- TestMethodRunner.java DELETED --- |
From: David S. <ds...@us...> - 2006-10-18 19:36:40
|
Update of /cvsroot/junit/junit/org/junit/runner/notification In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv6163/org/junit/runner/notification Modified Files: Tag: saff_r41_runner_refactoring Failure.java Log Message: PerTestNotifier is gone Index: Failure.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/runner/notification/Failure.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -d -r1.4 -r1.4.2.1 --- Failure.java 25 Aug 2006 14:43:03 -0000 1.4 +++ Failure.java 18 Oct 2006 19:36:35 -0000 1.4.2.1 @@ -2,6 +2,7 @@ import java.io.PrintWriter; import java.io.StringWriter; +import java.lang.reflect.InvocationTargetException; import org.junit.runner.Description; @@ -22,10 +23,18 @@ * @param thrownException the exception that was thrown while running the test */ public Failure(Description description, Throwable thrownException) { - fThrownException = thrownException; + fThrownException = findRootCause(thrownException); fDescription= description; } + private static Throwable findRootCause(Throwable thrownException) { + if (thrownException instanceof InvocationTargetException) { + InvocationTargetException ite= (InvocationTargetException) thrownException; + return findRootCause(ite.getTargetException()); + } + return thrownException; + } + /** * @return a user-understandable label for the test */ |
From: David S. <ds...@us...> - 2006-10-18 19:36:39
|
Update of /cvsroot/junit/junit/org/junit/runners In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv6163/org/junit/runners Modified Files: Tag: saff_r41_runner_refactoring ParameterizedInterpreter.java Log Message: PerTestNotifier is gone Index: ParameterizedInterpreter.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/runners/Attic/ParameterizedInterpreter.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -d -r1.1.2.2 -r1.1.2.3 --- ParameterizedInterpreter.java 18 Oct 2006 18:22:14 -0000 1.1.2.2 +++ ParameterizedInterpreter.java 18 Oct 2006 19:36:35 -0000 1.1.2.3 @@ -8,6 +8,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.Collection; import java.util.List; @@ -96,7 +97,7 @@ private Collection getParametersList(JavaClass javaClass) throws InitializationError { - JavaMethod parametersMethod= getParametersMethod(javaClass); + Method parametersMethod= getParametersMethod(javaClass); try { return (Collection) parametersMethod.invoke(null); } catch (Exception e) { @@ -104,14 +105,14 @@ } } - private JavaMethod getParametersMethod(JavaClass javaClass) + private Method getParametersMethod(JavaClass javaClass) throws InitializationError { // TODO: is this DUP? - List<JavaMethod> methods= javaClass.getMethods(Parameters.class, - new JavaTestInterpreter()); + List<Method> methods= javaClass.getMethods(Parameters.class); - for (JavaMethod each : methods) { - if (each.isStatic() && each.isPublic()) { + for (Method each : methods) { + int mods= each.getModifiers(); + if (Modifier.isStatic(mods) && Modifier.isPublic(mods)) { return each; } } |
From: David S. <ds...@us...> - 2006-10-18 18:22:21
|
Update of /cvsroot/junit/junit/org/junit/runners In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9576/org/junit/runners Modified Files: Tag: saff_r41_runner_refactoring ParameterizedInterpreter.java Parameterized.java Enclosed.java Suite.java Log Message: Parameterized works entirely with JavaTestInterpreter now Index: ParameterizedInterpreter.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/runners/Attic/ParameterizedInterpreter.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- ParameterizedInterpreter.java 18 Oct 2006 17:07:05 -0000 1.1.2.1 +++ ParameterizedInterpreter.java 18 Oct 2006 18:22:14 -0000 1.1.2.2 @@ -8,56 +8,115 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.Collection; +import java.util.List; +import org.junit.internal.runners.CompositeRunner; +import org.junit.internal.runners.InitializationError; import org.junit.internal.runners.JavaClass; import org.junit.internal.runners.JavaMethod; import org.junit.internal.runners.JavaTestInterpreter; +import org.junit.internal.runners.MethodValidator; +import org.junit.internal.runners.TestClassMethodsRunner; +import org.junit.runner.Runner; +import org.junit.runners.Parameterized.Parameters; class ParameterizedInterpreter extends JavaTestInterpreter { - private final Object fEach; + private static class ParameterizedJavaClass extends JavaClass { + private final Object[] fParameters; - private final int fNumber; + private final int fNumber; - ParameterizedInterpreter(Object each, int number) { - fEach= each; - fNumber= number; + private ParameterizedJavaClass(Class<?> type, Object[] parameters, + int number) { + super(type); + fParameters= parameters; + fNumber= number; + } + + // TODO: too many exceptions + @Override + protected Object newInstance() throws InstantiationException, + IllegalAccessException, InvocationTargetException, + NoSuchMethodException { + return getOnlyConstructor().newInstance(fParameters); + } + + @Override + public String getName() { + return String.format("[%s]", fNumber); + } + + private Constructor getOnlyConstructor() { + Constructor[] constructors= getTestClass().getConstructors(); + assertEquals(1, constructors.length); + return constructors[0]; + } } @Override - public JavaClass interpretJavaClass(Class<?> superclass) { - return new JavaClass(superclass) { - // TODO: too many exceptions - @Override - protected Object newInstance() - throws InstantiationException, - IllegalAccessException, InvocationTargetException, - NoSuchMethodException { - return getOnlyConstructor().newInstance( - (Object[]) fEach); - } - + protected JavaMethod interpretJavaMethod(final JavaClass klass, + Method method) { + return new JavaMethod(klass, method) { @Override public String getName() { - return String.format("[%s]", fNumber); + return String.format("%s%s", super.getName(), klass.getName()); } + }; + } - @Override - protected JavaMethod makeJavaMethod(Method method) { - return new JavaMethod(this, method) { - @Override - public String getName() { - return String.format("%s[%s]", super.getName(), - fNumber); - } - }; - } + // TODO: I think this now eagerly reads parameters, which was never the + // point. - private Constructor getOnlyConstructor() { - Constructor[] constructors= getTestClass() - .getConstructors(); - assertEquals(1, constructors.length); - return constructors[0]; + // TODO: pull interpreter back in? + @Override + public Runner runnerFor(Class klass) throws InitializationError { + CompositeRunner runner= new CompositeRunner(klass.getName()); + int i= 0; + for (final Object each : getParametersList(new JavaClass(klass))) { + if (each instanceof Object[]) { + runner + .add(new TestClassMethodsRunner( + new ParameterizedJavaClass(klass, + (Object[]) each, i++), this)); + } else + throw new InitializationError(String.format( + "%s.%s() must return a Collection of arrays.", klass + .getName(), getParametersMethod( + new JavaClass(klass)).getName())); + } + return runner; + } + + @Override + protected void validate(MethodValidator methodValidator) { + methodValidator.validateStaticMethods(); + methodValidator.validateInstanceMethods(); + } + + private Collection getParametersList(JavaClass javaClass) + throws InitializationError { + JavaMethod parametersMethod= getParametersMethod(javaClass); + try { + return (Collection) parametersMethod.invoke(null); + } catch (Exception e) { + throw new InitializationError(e); + } + } + + private JavaMethod getParametersMethod(JavaClass javaClass) + throws InitializationError { + // TODO: is this DUP? + List<JavaMethod> methods= javaClass.getMethods(Parameters.class, + new JavaTestInterpreter()); + + for (JavaMethod each : methods) { + if (each.isStatic() && each.isPublic()) { + return each; } - }; + } + throw new InitializationError( + "No public static parameters method on class " + + javaClass.getName()); } } \ No newline at end of file Index: Parameterized.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/runners/Parameterized.java,v retrieving revision 1.5.2.2 retrieving revision 1.5.2.3 diff -u -d -r1.5.2.2 -r1.5.2.3 --- Parameterized.java 18 Oct 2006 17:07:05 -0000 1.5.2.2 +++ Parameterized.java 18 Oct 2006 18:22:14 -0000 1.5.2.3 @@ -4,17 +4,10 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import org.junit.internal.runners.CompositeRunner; -import org.junit.internal.runners.JavaClass; -import org.junit.internal.runners.JavaMethod; -import org.junit.internal.runners.JavaTestInterpreter; -import org.junit.internal.runners.MethodValidator; -import org.junit.internal.runners.TestClassMethodsRunner; import org.junit.internal.runners.TestClassRunner; /** @@ -71,59 +64,6 @@ } public Parameterized(final Class<?> klass) throws Exception { - super(klass, buildCompositeRunner(new JavaClass(klass))); - } - - // TODO: I think this now eagerly reads parameters, which was never the - // point. - - // TODO: pull interpreter back in? - private static CompositeRunner buildCompositeRunner( - final JavaClass klass) throws Exception { - CompositeRunner runner= new CompositeRunner(klass.getName()); - int i= 0; - for (final Object each : getParametersList(klass)) { - if (each instanceof Object[]) { - final int parameterSetNumber= i++; - JavaTestInterpreter interpreter= new ParameterizedInterpreter( - each, parameterSetNumber); - runner - .add(new TestClassMethodsRunner(interpreter - .interpretJavaClass(klass.getTestClass()), - interpreter)); - } else - throw new Exception(String.format( - "%s.%s() must return a Collection of arrays.", klass - .getName(), getParametersMethod(klass) - .getName())); - } - return runner; - } - - @Override - protected void validate(MethodValidator methodValidator) { - methodValidator.validateStaticMethods(); - methodValidator.validateInstanceMethods(); - } - - // TODO: make non-static - static private Collection getParametersList(JavaClass javaClass) - throws IllegalAccessException, InvocationTargetException, Exception { - return (Collection) getParametersMethod(javaClass).invoke(null); - } - - static private JavaMethod getParametersMethod(JavaClass javaClass) - throws Exception { - // TODO: is this DUP? - List<JavaMethod> methods= javaClass.getMethods(Parameters.class, - new JavaTestInterpreter()); - - for (JavaMethod each : methods) { - if (each.isStatic() && each.isPublic()) { - return each; - } - } - throw new Exception("No public static parameters method on class " - + javaClass.getName()); + super(klass, new ParameterizedInterpreter()); } } Index: Enclosed.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/runners/Enclosed.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -d -r1.4 -r1.4.2.1 --- Enclosed.java 16 Mar 2006 22:09:12 -0000 1.4 +++ Enclosed.java 18 Oct 2006 18:22:14 -0000 1.4.2.1 @@ -2,6 +2,7 @@ import org.junit.internal.runners.InitializationError; + public class Enclosed extends Suite { public Enclosed(Class<?> klass) throws InitializationError { super(klass, klass.getClasses()); Index: Suite.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/runners/Suite.java,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -d -r1.4 -r1.4.2.1 --- Suite.java 25 Aug 2006 14:43:02 -0000 1.4 +++ Suite.java 18 Oct 2006 18:22:14 -0000 1.4.2.1 @@ -6,20 +6,24 @@ import java.lang.annotation.Target; import org.junit.internal.runners.InitializationError; +import org.junit.internal.runners.JavaTestInterpreter; import org.junit.internal.runners.TestClassRunner; import org.junit.runner.Request; +import org.junit.runner.Runner; /** - * Using <code>Suite</code> as a runner allows you to manually - * build a suite containing tests from many classes. It is the JUnit 4 equivalent of the JUnit 3.8.x - * static {@link junit.framework.Test} <code>suite()</code> method. To use it, annotate a class - * with <code>@RunWith(Suite.class)</code> and <code>SuiteClasses(TestClass1.class, ...)</code>. - * When you run this class, it will run all the tests in all the suite classes. + * Using <code>Suite</code> as a runner allows you to manually build a suite + * containing tests from many classes. It is the JUnit 4 equivalent of the JUnit + * 3.8.x static {@link junit.framework.Test} <code>suite()</code> method. To + * use it, annotate a class with <code>@RunWith(Suite.class)</code> and + * <code>SuiteClasses(TestClass1.class, ...)</code>. + * When you run this class, it will run all the tests in + * all the suite classes. */ public class Suite extends TestClassRunner { /** - * The <code>SuiteClasses</code> annotation specifies the classes to be run when a class - * annotated with <code>@RunWith(Suite.class)</code> is run. + * The <code>SuiteClasses</code> annotation specifies the classes to be + * run when a class annotated with <code>@RunWith(Suite.class)</code> is run. */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) @@ -36,15 +40,25 @@ /** * Internal use only. + * @throws InitializationError */ - public Suite(Class<?> klass, Class[] annotatedClasses) throws InitializationError { - super(klass, Request.classes(klass.getName(), annotatedClasses).getRunner()); + public Suite(Class<?> klass, final Class[] annotatedClasses) throws InitializationError { + super(klass, new JavaTestInterpreter() { + @Override + public Runner runnerFor(Class<?> klass) throws InitializationError { + return Request.classes(klass.getName(), annotatedClasses) + .getRunner(); + } + }); } - private static Class[] getAnnotatedClasses(Class<?> klass) throws InitializationError { + private static Class[] getAnnotatedClasses(Class<?> klass) + throws InitializationError { SuiteClasses annotation= klass.getAnnotation(SuiteClasses.class); if (annotation == null) - throw new InitializationError(String.format("class '%s' must have a SuiteClasses annotation", klass.getName())); + throw new InitializationError(String.format( + "class '%s' must have a SuiteClasses annotation", klass + .getName())); return annotation.value(); } } |
From: David S. <ds...@us...> - 2006-10-18 18:22:20
|
Update of /cvsroot/junit/junit/org/junit/tests In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9576/org/junit/tests Modified Files: Tag: saff_r41_runner_refactoring SortableTest.java ValidationTest.java Log Message: Parameterized works entirely with JavaTestInterpreter now Index: SortableTest.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/tests/SortableTest.java,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -d -r1.5 -r1.5.2.1 --- SortableTest.java 29 Jun 2006 23:06:45 -0000 1.5 +++ SortableTest.java 18 Oct 2006 18:22:14 -0000 1.5.2.1 @@ -1,6 +1,6 @@ package org.junit.tests; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; import java.util.Comparator; @@ -8,6 +8,7 @@ import org.junit.Test; import org.junit.internal.runners.EmptyDescription; import org.junit.internal.runners.InitializationError; +import org.junit.internal.runners.JavaTestInterpreter; import org.junit.internal.runners.TestClassRunner; import org.junit.runner.Description; import org.junit.runner.JUnitCore; @@ -27,7 +28,7 @@ } }; } - + private static Comparator<Description> backward() { return new Comparator<Description>() { public int compare(Description o1, Description o2) { @@ -38,88 +39,142 @@ public static class TestClassRunnerIsSortable { private static String log= ""; - + public static class SortMe { - @Test public void a() { log+= "a"; } - @Test public void b() { log+= "b"; } - @Test public void c() { log+= "c"; } + @Test + public void a() { + log+= "a"; + } + + @Test + public void b() { + log+= "b"; + } + + @Test + public void c() { + log+= "c"; + } } - - @Before public void resetLog() { + + @Before + public void resetLog() { log= ""; } - - @Test public void sortingForwardWorksOnTestClassRunner() { + + @Test + public void sortingForwardWorksOnTestClassRunner() { Request forward= Request.aClass(SortMe.class).sortWith(forward()); - + new JUnitCore().run(forward); assertEquals("abc", log); } - @Test public void sortingBackwardWorksOnTestClassRunner() { + @Test + public void sortingBackwardWorksOnTestClassRunner() { Request backward= Request.aClass(SortMe.class).sortWith(backward()); - + new JUnitCore().run(backward); assertEquals("cba", log); } - - @RunWith(Enclosed.class) + + @RunWith(Enclosed.class) public static class Enclosing { public static class A { - @Test public void a() { log+= "Aa"; } - @Test public void b() { log+= "Ab"; } - @Test public void c() { log+= "Ac"; } + @Test + public void a() { + log+= "Aa"; + } + + @Test + public void b() { + log+= "Ab"; + } + + @Test + public void c() { + log+= "Ac"; + } } + public static class B { - @Test public void a() { log+= "Ba"; } - @Test public void b() { log+= "Bb"; } - @Test public void c() { log+= "Bc"; } + @Test + public void a() { + log+= "Ba"; + } + + @Test + public void b() { + log+= "Bb"; + } + + @Test + public void c() { + log+= "Bc"; + } } } - @Test public void sortingForwardWorksOnSuite() { - Request forward= Request.aClass(Enclosing.class).sortWith(forward()); - + @Test + public void sortingForwardWorksOnSuite() { + Request forward= Request.aClass(Enclosing.class) + .sortWith(forward()); + new JUnitCore().run(forward); assertEquals("AaAbAcBaBbBc", log); } - @Test public void sortingBackwardWorksOnSuite() { - Request backward= Request.aClass(Enclosing.class).sortWith(backward()); - + @Test + public void sortingBackwardWorksOnSuite() { + Request backward= Request.aClass(Enclosing.class).sortWith( + backward()); + new JUnitCore().run(backward); assertEquals("BcBbBaAcAbAa", log); } } - + public static class UnsortableRunnersAreHandledWithoutCrashing { public static class UnsortableRunner extends Runner { public UnsortableRunner(Class<?> klass) { } - + @Override public Description getDescription() { return new EmptyDescription(); } - + @Override public void run(RunNotifier notifier) { } } - + @RunWith(UnsortableRunner.class) public static class Unsortable { - @Test public void a() {} + @Test + public void a() { + } } - - @Test public void unsortablesAreHandledWithoutCrashing() { - Request unsorted= Request.aClass(Unsortable.class).sortWith(forward()); + + @Test + public void unsortablesAreHandledWithoutCrashing() { + Request unsorted= Request.aClass(Unsortable.class).sortWith( + forward()); new JUnitCore().run(unsorted); } - - @Test public void testClassRunnerCanBeWrappedAroundUnsortable() throws InitializationError { - TestClassRunner runner= new TestClassRunner(Unsortable.class, new UnsortableRunner(Unsortable.class)); + + @Test + public void testClassRunnerCanBeWrappedAroundUnsortable() + throws InitializationError { + TestClassRunner runner= new TestClassRunner(Unsortable.class, + new JavaTestInterpreter() { + @Override + public Runner runnerFor(Class<?> klass) + throws InitializationError { + return new UnsortableRunner(klass); + } + }); runner.sort(new Sorter(forward())); } } Index: ValidationTest.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/tests/ValidationTest.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -d -r1.3 -r1.3.2.1 --- ValidationTest.java 29 Jun 2006 23:06:45 -0000 1.3 +++ ValidationTest.java 18 Oct 2006 18:22:14 -0000 1.3.2.1 @@ -1,15 +1,12 @@ package org.junit.tests; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; import org.junit.BeforeClass; import org.junit.Test; -import org.junit.internal.runners.EmptyDescription; import org.junit.internal.runners.InitializationError; +import org.junit.internal.runners.JavaTestInterpreter; import org.junit.internal.runners.TestClassRunner; -import org.junit.runner.Description; import org.junit.runner.Request; -import org.junit.runner.Runner; -import org.junit.runner.notification.RunNotifier; public class ValidationTest { public static class WrongBeforeClass { @@ -21,17 +18,7 @@ @Test(expected=InitializationError.class) public void testClassRunnerHandlesBeforeClassAndAfterClassValidation() throws InitializationError { - new TestClassRunner(WrongBeforeClass.class, new Runner() { - @Override - public Description getDescription() { - return new EmptyDescription(); - } - - @Override - public void run(RunNotifier notifier) { - // do nothing - } - }); + new TestClassRunner(WrongBeforeClass.class, new JavaTestInterpreter()); } @Test |
Update of /cvsroot/junit/junit/org/junit/internal/runners In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9576/org/junit/internal/runners Modified Files: Tag: saff_r41_runner_refactoring JavaMethod.java JavaTestInterpreter.java TestClassRunner.java JavaClass.java TestClassMethodsRunner.java Log Message: Parameterized works entirely with JavaTestInterpreter now Index: JavaMethod.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/JavaMethod.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -d -r1.1.2.3 -r1.1.2.4 --- JavaMethod.java 18 Oct 2006 17:07:05 -0000 1.1.2.3 +++ JavaMethod.java 18 Oct 2006 18:22:14 -0000 1.1.2.4 @@ -15,6 +15,9 @@ import org.junit.Test; import org.junit.Test.None; import org.junit.runner.Description; +import org.junit.runner.notification.RunNotifier; + +// TODO: check names of various "run" methods public class JavaMethod extends JavaModelElement { // TODO: push out @@ -149,24 +152,42 @@ return Before.class; } - public void runWithoutBeforeAndAfter(TestEnvironment environment, Object test) { + public void runWithoutBeforeAndAfter(TestEnvironment environment, + Object test) { try { environment.getInterpreter().executeMethodBody(test, this); if (expectsException()) - environment.addFailure(new AssertionError("Expected exception: " - + expectedException().getName())); + environment + .addFailure(new AssertionError("Expected exception: " + + expectedException().getName())); } catch (InvocationTargetException e) { Throwable actual= e.getTargetException(); if (!expectsException()) environment.addFailure(actual); else if (isUnexpected(actual)) { String message= "Unexpected exception, expected<" - + expectedException().getName() - + "> but was<" + actual.getClass().getName() + ">"; + + expectedException().getName() + "> but was<" + + actual.getClass().getName() + ">"; environment.addFailure(new Exception(message, actual)); } } catch (Throwable e) { environment.addFailure(e); } } + + void invokeTestMethod(RunNotifier notifier, JavaTestInterpreter interpreter) { + Object test; + try { + test= getJavaClass().newInstance(); + } catch (InvocationTargetException e) { + notifier.testAborted(description(), e.getCause()); + return; + } catch (Exception e) { + notifier.testAborted(description(), e); + return; + } + TestEnvironment testEnvironment= new TestEnvironment(interpreter, + new PerTestNotifier(notifier, description()), test); + testEnvironment.run(this); + } } \ No newline at end of file Index: JavaTestInterpreter.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/JavaTestInterpreter.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -d -r1.1.2.2 -r1.1.2.3 --- JavaTestInterpreter.java 18 Oct 2006 17:07:05 -0000 1.1.2.2 +++ JavaTestInterpreter.java 18 Oct 2006 18:22:14 -0000 1.1.2.3 @@ -1,18 +1,24 @@ package org.junit.internal.runners; import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.junit.runner.Runner; public class JavaTestInterpreter { - + public JavaTestInterpreter() { - + } // TODO: push out // TODO: be suspicious of everywhere this is constructed - - /* (non-Javadoc) - * @see org.junit.internal.runners.IJavaTestInterpreter#executeMethodBody(java.lang.Object, org.junit.internal.runners.JavaMethod) + + /* + * (non-Javadoc) + * + * @see org.junit.internal.runners.IJavaTestInterpreter#executeMethodBody(java.lang.Object, + * org.junit.internal.runners.JavaMethod) */ public void executeMethodBody(Object test, JavaMethod javaMethod) throws IllegalAccessException, InvocationTargetException { @@ -23,4 +29,18 @@ return new JavaClass(superclass); } + public Runner runnerFor(Class<?> klass) throws InitializationError { + MethodValidator methodValidator= new MethodValidator(klass); + validate(methodValidator); + methodValidator.assertValid(); + return new TestClassMethodsRunner(new JavaClass(klass), this); + } + + protected void validate(MethodValidator methodValidator) { + methodValidator.validateAllMethods(); + } + + protected JavaMethod interpretJavaMethod(final JavaClass klass, Method method) { + return new JavaMethod(klass, method); + } } Index: TestClassRunner.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/TestClassRunner.java,v retrieving revision 1.2.2.2 retrieving revision 1.2.2.3 diff -u -d -r1.2.2.2 -r1.2.2.3 --- TestClassRunner.java 18 Oct 2006 17:07:05 -0000 1.2.2.2 +++ TestClassRunner.java 18 Oct 2006 18:22:14 -0000 1.2.2.3 @@ -14,23 +14,17 @@ private final Class<?> fTestClass; + private JavaTestInterpreter fInterpreter; + public TestClassRunner(Class<?> klass) throws InitializationError { this(klass, new JavaTestInterpreter()); } public TestClassRunner(Class<?> klass, JavaTestInterpreter interpreter) throws InitializationError { - this(klass, new TestClassMethodsRunner(new JavaClass(klass), - interpreter)); - } - - public TestClassRunner(Class<?> klass, Runner runner) - throws InitializationError { fTestClass= klass; - fEnclosedRunner= runner; - MethodValidator methodValidator= new MethodValidator(klass); - validate(methodValidator); - methodValidator.assertValid(); + fEnclosedRunner= interpreter.runnerFor(klass); + fInterpreter= interpreter; } // TODO: this is parallel to passed-in runner @@ -46,9 +40,8 @@ } }; - TestEnvironment environment= new TestEnvironment( - new JavaTestInterpreter(), new PerTestNotifier(notifier, - getDescription()), null); + TestEnvironment environment= new TestEnvironment(fInterpreter, + new PerTestNotifier(notifier, getDescription()), null); environment.runWithBeforeAndAfter(protectThis, new JavaClass( getTestClass())); } Index: JavaClass.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/JavaClass.java,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -d -r1.1.2.3 -r1.1.2.4 --- JavaClass.java 18 Oct 2006 17:07:05 -0000 1.1.2.3 +++ JavaClass.java 18 Oct 2006 18:22:14 -0000 1.1.2.4 @@ -21,23 +21,24 @@ fClass= type; } - public List<JavaClass> getSuperClasses(JavaTestInterpreter interpreter) { + public List<JavaClass> getSuperClasses() { ArrayList<JavaClass> results= new ArrayList<JavaClass>(); results.add(this); // TODO: this will not add parameterized superclasses (need to use // interpreter here?) if (fClass.getSuperclass() != null) - results.addAll(interpreter.interpretJavaClass( - fClass.getSuperclass()).getSuperClasses(interpreter)); + results.addAll(new JavaClass(fClass.getSuperclass()) + .getSuperClasses()); return results; } public JavaMethodList getMethods(MethodAnnotation methodAnnotation, JavaTestInterpreter interpreter) { JavaMethodList results= new JavaMethodList(); - for (JavaClass eachClass : getSuperClasses(interpreter)) { - for (JavaMethod eachMethod : eachClass.getDeclaredMethods()) { + for (JavaClass eachClass : getSuperClasses()) { + for (JavaMethod eachMethod : eachClass + .getDeclaredMethods(interpreter)) { Annotation annotation= eachMethod .getAnnotation(methodAnnotation); if (annotation != null && !eachMethod.isShadowedBy(results)) @@ -49,19 +50,15 @@ return results; } - private List<JavaMethod> getDeclaredMethods() { + private List<JavaMethod> getDeclaredMethods(JavaTestInterpreter interpreter) { Method[] declaredMethods= fClass.getDeclaredMethods(); ArrayList<JavaMethod> javaMethods= new ArrayList<JavaMethod>(); for (Method method : declaredMethods) { - javaMethods.add(makeJavaMethod(method)); + javaMethods.add(interpreter.interpretJavaMethod(this, method)); } return javaMethods; } - protected JavaMethod makeJavaMethod(Method method) { - return new JavaMethod(this, method); - } - public JavaMethodList getMethods(Class<? extends Annotation> type, JavaTestInterpreter interpreter) { return getMethods(new MethodAnnotation(type), interpreter); Index: TestClassMethodsRunner.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/TestClassMethodsRunner.java,v retrieving revision 1.3.2.3 retrieving revision 1.3.2.4 diff -u -d -r1.3.2.3 -r1.3.2.4 --- TestClassMethodsRunner.java 18 Oct 2006 17:07:05 -0000 1.3.2.3 +++ TestClassMethodsRunner.java 18 Oct 2006 18:22:14 -0000 1.3.2.4 @@ -1,6 +1,5 @@ package org.junit.internal.runners; -import java.lang.reflect.InvocationTargetException; import org.junit.Test; import org.junit.runner.Description; @@ -38,7 +37,7 @@ notifier.testAborted(getDescription(), new Exception( "No runnable methods")); for (JavaMethod method : fTestMethods) - invokeTestMethod(method, notifier); + method.invokeTestMethod(notifier, fInterpreter); } @Override @@ -50,22 +49,6 @@ return spec; } - private void invokeTestMethod(JavaMethod method, RunNotifier notifier) { - Object test; - try { - test= method.getJavaClass().newInstance(); - } catch (InvocationTargetException e) { - notifier.testAborted(method.description(), e.getCause()); - return; - } catch (Exception e) { - notifier.testAborted(method.description(), e); - return; - } - TestEnvironment testEnvironment= new TestEnvironment(fInterpreter, - new PerTestNotifier(notifier, method.description()), test); - testEnvironment.run(method); - } - public void filter(Filter filter) throws NoTestsRemainException { fTestMethods.filter(filter); } |
Update of /cvsroot/junit/junit/org/junit/internal/runners In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv7311/org/junit/internal/runners Modified Files: Tag: saff_r41_runner_refactoring JavaMethod.java TestClassMethodsRunner.java ErrorReportingRunner.java MethodAnnotation.java PerTestNotifier.java TestMethodRunner.java JavaTestInterpreter.java JavaModelElement.java MethodValidator.java JavaClass.java TestClassRunner.java Added Files: Tag: saff_r41_runner_refactoring JavaMethodList.java TestEnvironment.java FailedBefore.java Removed Files: Tag: saff_r41_runner_refactoring BeforeAndAfterRunner.java Log Message: BeforeAndAfterRunner is no more --- NEW FILE: JavaMethodList.java --- package org.junit.internal.runners; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; import org.junit.runner.manipulation.Filter; import org.junit.runner.manipulation.NoTestsRemainException; import org.junit.runner.manipulation.Sorter; public class JavaMethodList extends ArrayList<JavaMethod> { private static final long serialVersionUID= 1L; void filter(Filter filter) throws NoTestsRemainException { for (Iterator<JavaMethod> iter= iterator(); iter.hasNext();) { JavaMethod method= iter.next(); if (!filter.shouldRun(method.description())) iter.remove(); } if (isEmpty()) throw new NoTestsRemainException(); } void filter(final Sorter sorter) { Collections.sort(this, new Comparator<JavaMethod>() { public int compare(JavaMethod o1, JavaMethod o2) { return sorter.compare(o1.description(), o2.description()); } }); } } --- NEW FILE: TestEnvironment.java --- /** * */ package org.junit.internal.runners; import java.lang.annotation.Annotation; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; public class TestEnvironment { private final JavaTestInterpreter fInterpreter; private final PerTestNotifier fNotifier; private final Object fTest; public TestEnvironment(JavaTestInterpreter interpreter, PerTestNotifier notifier, Object test) { fInterpreter= interpreter; fNotifier= notifier; fTest= test; } void runAfters(Class<? extends Annotation> afterAnnotation, JavaClass javaClass, Object test) { List<JavaMethod> afters= javaClass.getMethods(afterAnnotation, getInterpreter()); for (JavaMethod after : afters) { try { after.invoke(test); } catch (Throwable e) { addFailure(e); } } } public void runWithBeforeAndAfter(Runnable protectThis, JavaModelElement element) { // TODO: is this envious now? Yes try { runBefores(element, fTest); protectThis.run(); } catch (FailedBefore e) { } finally { runAfters(element.getAfterAnnotation(), element.getJavaClass(), fTest); } } private void runBefores(JavaModelElement element, Object test) throws FailedBefore { // TODO: envious of environment? try { List<JavaMethod> befores= element.getJavaClass().getMethods( element.getBeforeAnnotation(), getInterpreter()); // TODO: no auto-correct if wrong type on left side of new-style // for? for (JavaMethod before : befores) before.invoke(test); } catch (Throwable e) { addFailure(e); throw new FailedBefore(); } } void runWithoutTimeout(final JavaMethod javaMethod) { runWithBeforeAndAfter(new Runnable() { public void run() { javaMethod.runWithoutBeforeAndAfter(TestEnvironment.this, fTest); } }, javaMethod); } void runWithTimeout(long timeout, final JavaMethod method) { ExecutorService service= Executors.newSingleThreadExecutor(); Callable<Object> callable= new Callable<Object>() { public Object call() throws Exception { runWithoutTimeout(method); return null; } }; Future<Object> result= service.submit(callable); service.shutdown(); try { boolean terminated= service.awaitTermination(timeout, TimeUnit.MILLISECONDS); if (!terminated) service.shutdownNow(); result.get(timeout, TimeUnit.MILLISECONDS); // throws the exception // if one occurred // during the invocation } catch (TimeoutException e) { addFailure(new Exception(String.format( "test timed out after %d milliseconds", timeout))); } catch (Exception e) { addFailure(e); } } void addFailure(Throwable e) { fNotifier.addFailure(e); } void run(JavaMethod javaMethod) { if (javaMethod.isIgnored()) { fNotifier.fireTestIgnored(); return; } fNotifier.fireTestStarted(); try { long timeout= javaMethod.getTimeout(); if (timeout > 0) runWithTimeout(timeout, javaMethod); else runWithoutTimeout(javaMethod); } finally { fNotifier.fireTestFinished(); } } JavaTestInterpreter getInterpreter() { return fInterpreter; } } --- NEW FILE: FailedBefore.java --- package org.junit.internal.runners; public class FailedBefore extends Exception { private static final long serialVersionUID= 1L; } Index: JavaMethod.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/JavaMethod.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -d -r1.1.2.2 -r1.1.2.3 --- JavaMethod.java 17 Oct 2006 19:06:09 -0000 1.1.2.2 +++ JavaMethod.java 18 Oct 2006 17:07:05 -0000 1.1.2.3 @@ -9,15 +9,21 @@ import java.lang.reflect.Modifier; import java.util.List; +import org.junit.After; +import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.Test.None; +import org.junit.runner.Description; public class JavaMethod extends JavaModelElement { // TODO: push out private final Method fMethod; - public JavaMethod(Method current) { + private final JavaClass fJavaClass; + + public JavaMethod(JavaClass javaClass, Method current) { + fJavaClass= javaClass; fMethod= current; } @@ -25,8 +31,7 @@ Method previous= previousJavaMethod.fMethod; if (!previous.getName().equals(fMethod.getName())) return false; - if (previous.getParameterTypes().length != fMethod - .getParameterTypes().length) + if (previous.getParameterTypes().length != fMethod.getParameterTypes().length) return false; for (int i= 0; i < previous.getParameterTypes().length; i++) { if (!previous.getParameterTypes()[i].equals(fMethod @@ -69,16 +74,16 @@ } boolean isUnexpected(Throwable exception) { - return ! expectedException().isAssignableFrom(exception.getClass()); + return !expectedException().isAssignableFrom(exception.getClass()); } boolean expectsException() { return expectedException() != null; } - void invoke(Object object) throws IllegalAccessException, + public Object invoke(Object object) throws IllegalAccessException, InvocationTargetException { - fMethod.invoke(object); + return fMethod.invoke(object); } @Override @@ -90,12 +95,14 @@ Method each= fMethod; if (Modifier.isStatic(each.getModifiers()) != isStatic) { String state= isStatic ? "should" : "should not"; - errors.add(new Exception("Method " + each.getName() + "() " - + state + " be static")); + errors.add(new Exception("Method " + each.getName() + "() " + state + + " be static")); } if (!Modifier.isPublic(each.getDeclaringClass().getModifiers())) - errors.add(new Exception("Class " + each.getDeclaringClass().getName() - + " should be public")); + errors + .add(new Exception("Class " + + each.getDeclaringClass().getName() + + " should be public")); if (!Modifier.isPublic(each.getModifiers())) errors.add(new Exception("Method " + each.getName() + " should be public")); @@ -107,25 +114,59 @@ + " should have no parameters")); } - void runUnprotected(JavaTestInterpreter javaTestInterpreter, Object test, PerTestNotifier perTestNotifier) { + // TODO: push out + public Description description() { + return Description.createTestDescription(fJavaClass.getTestClass(), + getName()); + } + + public boolean isStatic() { + return Modifier.isStatic(getModifiers()); + } + + // TODO: sort methods + private int getModifiers() { + return fMethod.getModifiers(); + } + + public boolean isPublic() { + return Modifier.isPublic(getModifiers()); + } + + // TODO: push out + @Override + public JavaClass getJavaClass() { + return fJavaClass; + } + + @Override + public Class<? extends Annotation> getAfterAnnotation() { + return After.class; + } + + @Override + public Class<? extends Annotation> getBeforeAnnotation() { + return Before.class; + } + + public void runWithoutBeforeAndAfter(TestEnvironment environment, Object test) { try { - javaTestInterpreter.executeMethodBody(test, this); + environment.getInterpreter().executeMethodBody(test, this); if (expectsException()) - perTestNotifier.addFailure(new AssertionError( - "Expected exception: " - + expectedException().getName())); + environment.addFailure(new AssertionError("Expected exception: " + + expectedException().getName())); } catch (InvocationTargetException e) { Throwable actual= e.getTargetException(); if (!expectsException()) - perTestNotifier.addFailure(actual); + environment.addFailure(actual); else if (isUnexpected(actual)) { String message= "Unexpected exception, expected<" + expectedException().getName() + "> but was<" + actual.getClass().getName() + ">"; - perTestNotifier.addFailure(new Exception(message, actual)); + environment.addFailure(new Exception(message, actual)); } } catch (Throwable e) { - perTestNotifier.addFailure(e); + environment.addFailure(e); } } } \ No newline at end of file Index: TestClassMethodsRunner.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/TestClassMethodsRunner.java,v retrieving revision 1.3.2.2 retrieving revision 1.3.2.3 diff -u -d -r1.3.2.2 -r1.3.2.3 --- TestClassMethodsRunner.java 17 Oct 2006 19:07:09 -0000 1.3.2.2 +++ TestClassMethodsRunner.java 18 Oct 2006 17:07:05 -0000 1.3.2.3 @@ -1,11 +1,6 @@ package org.junit.internal.runners; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Collections; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; import org.junit.Test; import org.junit.runner.Description; @@ -15,110 +10,67 @@ import org.junit.runner.manipulation.NoTestsRemainException; import org.junit.runner.manipulation.Sortable; import org.junit.runner.manipulation.Sorter; -import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunNotifier; -public class TestClassMethodsRunner extends Runner implements Filterable, Sortable { - private final List<JavaMethod> fTestMethods; +public class TestClassMethodsRunner extends Runner implements Filterable, + Sortable { + private final JavaMethodList fTestMethods; + private final JavaClass fTestClass; + private final JavaTestInterpreter fInterpreter; - // This assumes that some containing runner will perform validation of the test methods - public TestClassMethodsRunner(JavaClass klass, JavaTestInterpreter javaTestInterpreter) { - + // This assumes that some containing runner will perform validation of the + // test methods + public TestClassMethodsRunner(JavaClass klass, + JavaTestInterpreter javaTestInterpreter) { // TODO: DUP? fTestClass= klass; - fTestMethods= klass.getTestMethods(Test.class); + fTestMethods= klass.getMethods(Test.class, javaTestInterpreter); fInterpreter= javaTestInterpreter; } // TODO: rename method to element? - + @Override public void run(RunNotifier notifier) { if (fTestMethods.isEmpty()) - testAborted(notifier, getDescription(), new Exception("No runnable methods")); + notifier.testAborted(getDescription(), new Exception( + "No runnable methods")); for (JavaMethod method : fTestMethods) invokeTestMethod(method, notifier); } - private void testAborted(RunNotifier notifier, Description description, Throwable cause) { - // TODO: duped! - // TODO: envious - notifier.fireTestStarted(description); - notifier.fireTestFailure(new Failure(description, cause)); - notifier.fireTestFinished(description); - } - @Override public Description getDescription() { - Description spec= Description.createSuiteDescription(getName()); + Description spec= Description.createSuiteDescription(fTestClass + .getName()); for (JavaMethod method : fTestMethods) - spec.addChild(methodDescription(method)); + spec.addChild(method.description()); return spec; } - protected Description methodDescription(Method method) { - return methodDescription(new JavaMethod(method)); - } - - protected String getName() { - return getTestClass().getName(); - } - - protected Object createTest() throws Exception { - return getTestClass().newTestObject(); - } - private void invokeTestMethod(JavaMethod method, RunNotifier notifier) { Object test; try { - test= createTest(); + test= method.getJavaClass().newInstance(); } catch (InvocationTargetException e) { - testAborted(notifier, methodDescription(method), e.getCause()); - return; + notifier.testAborted(method.description(), e.getCause()); + return; } catch (Exception e) { - testAborted(notifier, methodDescription(method), e); + notifier.testAborted(method.description(), e); return; } - createMethodRunner(test, method, notifier).run(); - } - - private TestMethodRunner createMethodRunner(Object test, JavaMethod method, RunNotifier notifier) { - return new TestMethodRunner(test, method, notifier, methodDescription(method), fInterpreter); - } - - protected String testName(JavaModelElement method) { - return method.getName(); - } - - private Description methodDescription(JavaMethod method) { - return describe(method, getTestClass()); - } - - private Description describe(JavaMethod method, JavaClass testClass) { - return Description.createTestDescription(testClass.getTestClass(), testName(method)); + TestEnvironment testEnvironment= new TestEnvironment(fInterpreter, + new PerTestNotifier(notifier, method.description()), test); + testEnvironment.run(method); } public void filter(Filter filter) throws NoTestsRemainException { - for (Iterator<JavaMethod> iter= fTestMethods.iterator(); iter.hasNext();) { - JavaMethod method= iter.next(); - if (!filter.shouldRun(methodDescription(method))) - iter.remove(); - } - if (fTestMethods.isEmpty()) - throw new NoTestsRemainException(); + fTestMethods.filter(filter); } public void sort(final Sorter sorter) { - Collections.sort(fTestMethods, new Comparator<JavaMethod>() { - public int compare(JavaMethod o1, JavaMethod o2) { - return sorter.compare(methodDescription(o1), methodDescription(o2)); - } - }); - } - - protected JavaClass getTestClass() { - return fTestClass; + fTestMethods.filter(sorter); } } \ No newline at end of file Index: ErrorReportingRunner.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/ErrorReportingRunner.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -d -r1.3 -r1.3.2.1 --- ErrorReportingRunner.java 25 Aug 2006 14:01:36 -0000 1.3 +++ ErrorReportingRunner.java 18 Oct 2006 17:07:05 -0000 1.3.2.1 @@ -3,7 +3,6 @@ import org.junit.runner.Description; import org.junit.runner.Runner; import org.junit.runner.notification.RunNotifier; -import org.junit.runner.notification.Failure; public class ErrorReportingRunner extends Runner { private final Description fDescription; @@ -20,11 +19,8 @@ return fDescription; } - // TODO: this is duplicated in TestClassMethodsRunner @Override public void run(RunNotifier notifier) { - notifier.fireTestStarted(fDescription); - notifier.fireTestFailure(new Failure(fDescription, fCause)); - notifier.fireTestFinished(fDescription); + notifier.testAborted(fDescription, fCause); } } \ No newline at end of file Index: MethodAnnotation.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/MethodAnnotation.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- MethodAnnotation.java 26 Sep 2006 16:51:39 -0000 1.1.2.1 +++ MethodAnnotation.java 18 Oct 2006 17:07:05 -0000 1.1.2.2 @@ -7,12 +7,12 @@ import org.junit.RunSuperclassMethodsFirst; -final class MethodAnnotation { +public class MethodAnnotation { // TODO: push out // TODO: package too big? private final Class<? extends Annotation> fAnnotation; - MethodAnnotation(Class<? extends Annotation> annotation) { + public MethodAnnotation(Class<? extends Annotation> annotation) { fAnnotation= annotation; } Index: PerTestNotifier.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/PerTestNotifier.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- PerTestNotifier.java 17 Oct 2006 19:03:52 -0000 1.1.2.1 +++ PerTestNotifier.java 18 Oct 2006 17:07:05 -0000 1.1.2.2 @@ -1,12 +1,14 @@ package org.junit.internal.runners; +import java.lang.reflect.InvocationTargetException; + import org.junit.runner.Description; import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunNotifier; public class PerTestNotifier { // TODO: push out - + private final RunNotifier fNotifier; private final Description fDescription; @@ -17,6 +19,11 @@ } public void addFailure(Throwable targetException) { + if (targetException instanceof InvocationTargetException) { + InvocationTargetException i= (InvocationTargetException) targetException; + addFailure(i.getTargetException()); + return; + } fNotifier.fireTestFailure(new Failure(fDescription, targetException)); } Index: TestMethodRunner.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/TestMethodRunner.java,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -d -r1.2.2.1 -r1.2.2.2 --- TestMethodRunner.java 17 Oct 2006 19:08:09 -0000 1.2.2.1 +++ TestMethodRunner.java 18 Oct 2006 17:07:05 -0000 1.2.2.2 @@ -1,83 +1,18 @@ package org.junit.internal.runners; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import org.junit.After; -import org.junit.Before; -import org.junit.runner.Description; -import org.junit.runner.notification.RunNotifier; - -public class TestMethodRunner extends BeforeAndAfterRunner { - private final Object fTest; +public class TestMethodRunner { private final JavaMethod fJavaMethod; - private final JavaTestInterpreter fInterpreter; + private final TestEnvironment fEnvironment; - public TestMethodRunner(Object test, JavaMethod method, - RunNotifier notifier, Description description, - JavaTestInterpreter interpreter) { - super(test.getClass(), Before.class, After.class, test, - new PerTestNotifier(notifier, description)); - fTest= test; + public TestMethodRunner(JavaMethod method, TestEnvironment environment) { + fEnvironment= environment; fJavaMethod= method; - fInterpreter= interpreter; } public void run() { - if (fJavaMethod.isIgnored()) { - fPerTestNotifier.fireTestIgnored(); - return; - } - fPerTestNotifier.fireTestStarted(); - try { - long timeout= fJavaMethod.getTimeout(); - if (timeout > 0) - runWithTimeout(timeout); - else - runMethod(); - } finally { - fPerTestNotifier.fireTestFinished(); - } - } - - private void runWithTimeout(long timeout) { - ExecutorService service= Executors.newSingleThreadExecutor(); - Callable<Object> callable= new Callable<Object>() { - public Object call() throws Exception { - runMethod(); - return null; - } - }; - Future<Object> result= service.submit(callable); - service.shutdown(); - try { - boolean terminated= service.awaitTermination(timeout, - TimeUnit.MILLISECONDS); - if (!terminated) - service.shutdownNow(); - result.get(timeout, TimeUnit.MILLISECONDS); // throws the exception - // if one occurred - // during the invocation - } catch (TimeoutException e) { - fPerTestNotifier.addFailure(new Exception(String.format( - "test timed out after %d milliseconds", timeout))); - } catch (Exception e) { - fPerTestNotifier.addFailure(e); - } - } - - private void runMethod() { - runProtected(); - } - - @Override - protected void runUnprotected() { - fJavaMethod.runUnprotected(fInterpreter, fTest, fPerTestNotifier); + fEnvironment.run(fJavaMethod); } } Index: JavaTestInterpreter.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/JavaTestInterpreter.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- JavaTestInterpreter.java 17 Oct 2006 19:00:57 -0000 1.1.2.1 +++ JavaTestInterpreter.java 18 Oct 2006 17:07:05 -0000 1.1.2.2 @@ -3,8 +3,13 @@ import java.lang.reflect.InvocationTargetException; public class JavaTestInterpreter { + + public JavaTestInterpreter() { + + } // TODO: push out + // TODO: be suspicious of everywhere this is constructed /* (non-Javadoc) * @see org.junit.internal.runners.IJavaTestInterpreter#executeMethodBody(java.lang.Object, org.junit.internal.runners.JavaMethod) @@ -14,4 +19,8 @@ javaMethod.invoke(test); } + public JavaClass interpretJavaClass(Class<?> superclass) { + return new JavaClass(superclass); + } + } Index: JavaModelElement.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/JavaModelElement.java,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -d -r1.1.2.1 -r1.1.2.2 --- JavaModelElement.java 17 Oct 2006 19:06:09 -0000 1.1.2.1 +++ JavaModelElement.java 18 Oct 2006 17:07:05 -0000 1.1.2.2 @@ -1,5 +1,13 @@ package org.junit.internal.runners; +import java.lang.annotation.Annotation; + public abstract class JavaModelElement { public abstract String getName(); + + public abstract Class<? extends Annotation> getBeforeAnnotation(); + + public abstract Class<? extends Annotation> getAfterAnnotation(); + + public abstract JavaClass getJavaClass(); } Index: MethodValidator.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/MethodValidator.java,v retrieving revision 1.3.2.1 retrieving revision 1.3.2.2 diff -u -d -r1.3.2.1 -r1.3.2.2 --- MethodValidator.java 17 Oct 2006 19:06:32 -0000 1.3.2.1 +++ MethodValidator.java 18 Oct 2006 17:07:05 -0000 1.3.2.2 @@ -49,7 +49,7 @@ private void validateTestMethods(Class<? extends Annotation> annotation, boolean isStatic) { - List<JavaMethod> methods= fJavaClass.getTestMethods(annotation); + List<JavaMethod> methods= fJavaClass.getMethods(annotation, new JavaTestInterpreter()); for (JavaMethod eachMethod : methods) { eachMethod.validateAsTestMethod(isStatic, fErrors); } Index: JavaClass.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/Attic/JavaClass.java,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -d -r1.1.2.2 -r1.1.2.3 --- JavaClass.java 17 Oct 2006 19:06:09 -0000 1.1.2.2 +++ JavaClass.java 18 Oct 2006 17:07:05 -0000 1.1.2.3 @@ -10,6 +10,9 @@ import java.util.Collections; import java.util.List; +import org.junit.AfterClass; +import org.junit.BeforeClass; + public class JavaClass extends JavaModelElement { // TODO: push out private final Class<?> fClass; @@ -18,22 +21,26 @@ fClass= type; } - public List<JavaClass> getSuperClasses() { + public List<JavaClass> getSuperClasses(JavaTestInterpreter interpreter) { ArrayList<JavaClass> results= new ArrayList<JavaClass>(); - Class<?> current= fClass; - while (current != null) { - results.add(new JavaClass(current)); - current= current.getSuperclass(); - } + results.add(this); + + // TODO: this will not add parameterized superclasses (need to use + // interpreter here?) + if (fClass.getSuperclass() != null) + results.addAll(interpreter.interpretJavaClass( + fClass.getSuperclass()).getSuperClasses(interpreter)); return results; } - List<JavaMethod> getTestMethods(MethodAnnotation methodAnnotation) { - List<JavaMethod> results= new ArrayList<JavaMethod>(); - for (JavaClass eachClass : getSuperClasses()) { + public JavaMethodList getMethods(MethodAnnotation methodAnnotation, + JavaTestInterpreter interpreter) { + JavaMethodList results= new JavaMethodList(); + for (JavaClass eachClass : getSuperClasses(interpreter)) { for (JavaMethod eachMethod : eachClass.getDeclaredMethods()) { - Annotation annotation= eachMethod.getAnnotation(methodAnnotation); - if (annotation != null && ! eachMethod.isShadowedBy(results)) + Annotation annotation= eachMethod + .getAnnotation(methodAnnotation); + if (annotation != null && !eachMethod.isShadowedBy(results)) results.add(eachMethod); } } @@ -46,13 +53,18 @@ Method[] declaredMethods= fClass.getDeclaredMethods(); ArrayList<JavaMethod> javaMethods= new ArrayList<JavaMethod>(); for (Method method : declaredMethods) { - javaMethods.add(new JavaMethod(method)); + javaMethods.add(makeJavaMethod(method)); } return javaMethods; } - List<JavaMethod> getTestMethods(Class<? extends Annotation> type) { - return getTestMethods(new MethodAnnotation(type)); + protected JavaMethod makeJavaMethod(Method method) { + return new JavaMethod(this, method); + } + + public JavaMethodList getMethods(Class<? extends Annotation> type, + JavaTestInterpreter interpreter) { + return getMethods(new MethodAnnotation(type), interpreter); } public Class getTestClass() { @@ -63,7 +75,9 @@ try { getTestClass().getConstructor(); } catch (Exception e) { - errors.add(new Exception("Test class should have public zero-argument constructor", e)); + errors.add(new Exception( + "Test class should have public zero-argument constructor", + e)); } } @@ -72,9 +86,24 @@ return fClass.getName(); } - Object newTestObject() - throws InstantiationException, IllegalAccessException, - InvocationTargetException, NoSuchMethodException { + protected Object newInstance() throws InstantiationException, + IllegalAccessException, InvocationTargetException, + NoSuchMethodException { return getTestClass().getConstructor().newInstance(); } + + @Override + public Class<? extends Annotation> getAfterAnnotation() { + return AfterClass.class; + } + + @Override + public Class<? extends Annotation> getBeforeAnnotation() { + return BeforeClass.class; + } + + @Override + public JavaClass getJavaClass() { + return this; + } } \ No newline at end of file Index: TestClassRunner.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/internal/runners/TestClassRunner.java,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -d -r1.2.2.1 -r1.2.2.2 --- TestClassRunner.java 17 Oct 2006 19:07:40 -0000 1.2.2.1 +++ TestClassRunner.java 18 Oct 2006 17:07:05 -0000 1.2.2.2 @@ -1,7 +1,5 @@ package org.junit.internal.runners; -import org.junit.AfterClass; -import org.junit.BeforeClass; import org.junit.runner.Description; import org.junit.runner.Runner; import org.junit.runner.manipulation.Filter; @@ -15,13 +13,15 @@ protected final Runner fEnclosedRunner; private final Class<?> fTestClass; - + public TestClassRunner(Class<?> klass) throws InitializationError { this(klass, new JavaTestInterpreter()); } - - public TestClassRunner(Class<?> klass, JavaTestInterpreter interpreter) throws InitializationError { - this(klass, new TestClassMethodsRunner(new JavaClass(klass), interpreter)); + + public TestClassRunner(Class<?> klass, JavaTestInterpreter interpreter) + throws InitializationError { + this(klass, new TestClassMethodsRunner(new JavaClass(klass), + interpreter)); } public TestClassRunner(Class<?> klass, Runner runner) @@ -40,16 +40,17 @@ @Override public void run(final RunNotifier notifier) { - BeforeAndAfterRunner runner= new BeforeAndAfterRunner(getTestClass(), - BeforeClass.class, AfterClass.class, null, new PerTestNotifier(notifier, - getDescription())) { - @Override - protected void runUnprotected() { + Runnable protectThis= new Runnable() { + public void run() { fEnclosedRunner.run(notifier); } }; - runner.runProtected(); + TestEnvironment environment= new TestEnvironment( + new JavaTestInterpreter(), new PerTestNotifier(notifier, + getDescription()), null); + environment.runWithBeforeAndAfter(protectThis, new JavaClass( + getTestClass())); } @Override --- BeforeAndAfterRunner.java DELETED --- |
From: David S. <ds...@us...> - 2006-10-18 17:07:10
|
Update of /cvsroot/junit/junit/org/junit/tests In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv7311/org/junit/tests Modified Files: Tag: saff_r41_runner_refactoring InitializationErrorForwardCompatibilityTest.java UserStopTest.java Log Message: BeforeAndAfterRunner is no more Index: InitializationErrorForwardCompatibilityTest.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/tests/InitializationErrorForwardCompatibilityTest.java,v retrieving revision 1.3.2.1 retrieving revision 1.3.2.2 diff -u -d -r1.3.2.1 -r1.3.2.2 --- InitializationErrorForwardCompatibilityTest.java 17 Oct 2006 19:10:20 -0000 1.3.2.1 +++ InitializationErrorForwardCompatibilityTest.java 18 Oct 2006 17:07:05 -0000 1.3.2.2 @@ -1,8 +1,6 @@ package org.junit.tests; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import junit.framework.AssertionFailedError; import junit.framework.JUnit4TestAdapter; import junit.framework.TestListener; @@ -10,7 +8,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.internal.runners.EmptyDescription; -import org.junit.internal.runners.JavaTestInterpreter; import org.junit.internal.runners.TestClassRunner; import org.junit.runner.Description; import org.junit.runner.RunWith; @@ -95,7 +92,7 @@ public static class InitializesWithError extends TestClassRunner { public InitializesWithError(Class<?> klass) throws Exception { - super(klass, new JavaTestInterpreter()); + super(klass); throw new Exception(); } } Index: UserStopTest.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/tests/UserStopTest.java,v retrieving revision 1.2.2.1 retrieving revision 1.2.2.2 diff -u -d -r1.2.2.1 -r1.2.2.2 --- UserStopTest.java 17 Oct 2006 19:10:20 -0000 1.2.2.1 +++ UserStopTest.java 18 Oct 2006 17:07:05 -0000 1.2.2.2 @@ -2,10 +2,6 @@ import org.junit.Before; import org.junit.Test; -import org.junit.internal.runners.JavaMethod; -import org.junit.internal.runners.JavaTestInterpreter; -import org.junit.internal.runners.TestMethodRunner; -import org.junit.runner.Description; import org.junit.runner.Request; import org.junit.runner.notification.RunNotifier; import org.junit.runner.notification.StoppedByUserException; @@ -13,26 +9,25 @@ public class UserStopTest { private RunNotifier fNotifier; - @Before public void createNotifier() { + @Before + public void createNotifier() { fNotifier= new RunNotifier(); - fNotifier.pleaseStop(); - } - - @Test(expected=StoppedByUserException.class) public void userStop() { - fNotifier.fireTestStarted(null); + fNotifier.pleaseStop(); } - @Test(expected=StoppedByUserException.class) public void stopMethodRunner() throws Exception { - // TODO: is this a good test? - new TestMethodRunner(this, new JavaMethod(OneTest.class.getMethod("foo")), fNotifier, - Description.createTestDescription(OneTest.class, "foo"), new JavaTestInterpreter()).run(); + @Test(expected= StoppedByUserException.class) + public void userStop() { + fNotifier.fireTestStarted(null); } public static class OneTest { - @Test public void foo() {} + @Test + public void foo() { + } } - - @Test(expected=StoppedByUserException.class) public void stopClassRunner() throws Exception { + + @Test(expected= StoppedByUserException.class) + public void stopClassRunner() throws Exception { Request.aClass(OneTest.class).getRunner().run(fNotifier); } } |
From: David S. <ds...@us...> - 2006-10-18 17:07:10
|
Update of /cvsroot/junit/junit/org/junit/runner/notification In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv7311/org/junit/runner/notification Modified Files: Tag: saff_r41_runner_refactoring RunNotifier.java Log Message: BeforeAndAfterRunner is no more Index: RunNotifier.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/runner/notification/RunNotifier.java,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -d -r1.5 -r1.5.2.1 --- RunNotifier.java 25 Aug 2006 14:43:02 -0000 1.5 +++ RunNotifier.java 18 Oct 2006 17:07:05 -0000 1.5.2.1 @@ -142,4 +142,10 @@ public void addFirstListener(RunListener listener) { fListeners.add(0, listener); } + + public void testAborted(Description description, Throwable cause) { + fireTestStarted(description); + fireTestFailure(new Failure(description, cause)); + fireTestFinished(description); + } } \ No newline at end of file |
From: David S. <ds...@us...> - 2006-10-18 17:07:10
|
Update of /cvsroot/junit/junit/org/junit/runners In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv7311/org/junit/runners Modified Files: Tag: saff_r41_runner_refactoring Parameterized.java Added Files: Tag: saff_r41_runner_refactoring ParameterizedInterpreter.java Log Message: BeforeAndAfterRunner is no more --- NEW FILE: ParameterizedInterpreter.java --- /** * */ package org.junit.runners; import static org.junit.Assert.*; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import org.junit.internal.runners.JavaClass; import org.junit.internal.runners.JavaMethod; import org.junit.internal.runners.JavaTestInterpreter; class ParameterizedInterpreter extends JavaTestInterpreter { private final Object fEach; private final int fNumber; ParameterizedInterpreter(Object each, int number) { fEach= each; fNumber= number; } @Override public JavaClass interpretJavaClass(Class<?> superclass) { return new JavaClass(superclass) { // TODO: too many exceptions @Override protected Object newInstance() throws InstantiationException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { return getOnlyConstructor().newInstance( (Object[]) fEach); } @Override public String getName() { return String.format("[%s]", fNumber); } @Override protected JavaMethod makeJavaMethod(Method method) { return new JavaMethod(this, method) { @Override public String getName() { return String.format("%s[%s]", super.getName(), fNumber); } }; } private Constructor getOnlyConstructor() { Constructor[] constructors= getTestClass() .getConstructors(); assertEquals(1, constructors.length); return constructors[0]; } }; } } Index: Parameterized.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/runners/Parameterized.java,v retrieving revision 1.5.2.1 retrieving revision 1.5.2.2 diff -u -d -r1.5.2.1 -r1.5.2.2 --- Parameterized.java 17 Oct 2006 19:08:40 -0000 1.5.2.1 +++ Parameterized.java 18 Oct 2006 17:07:05 -0000 1.5.2.2 @@ -1,58 +1,61 @@ package org.junit.runners; -import static org.junit.Assert.*; - -import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Collection; import java.util.List; import org.junit.internal.runners.CompositeRunner; import org.junit.internal.runners.JavaClass; -import org.junit.internal.runners.JavaModelElement; +import org.junit.internal.runners.JavaMethod; import org.junit.internal.runners.JavaTestInterpreter; import org.junit.internal.runners.MethodValidator; import org.junit.internal.runners.TestClassMethodsRunner; import org.junit.internal.runners.TestClassRunner; -/** <p>The custom runner <code>Parameterized</code> implements parameterized +/** + * <p> + * The custom runner <code>Parameterized</code> implements parameterized * tests. When running a parameterized test class, instances are created for the - * cross-product of the test methods and the test data elements.</p> + * cross-product of the test methods and the test data elements. + * </p> * * For example, to test a Fibonacci function, write: + * * <pre> - * @RunWith(Parameterized.class) + * @RunWith(Parameterized.class) * public class FibonacciTest { - * @Parameters - * public static Collection<Object[]> data() { - * return Arrays.asList(new Object[][] { { 0, 0 }, { 1, 1 }, { 2, 1 }, - * { 3, 2 }, { 4, 3 }, { 5, 5 }, { 6, 8 } }); - * } - * - * private int fInput; - * private int fExpected; - * - * public FibonacciTest(int input, int expected) { - * fInput= input; - * fExpected= expected; - * } - * - * @Test public void test() { - * assertEquals(fExpected, Fibonacci.compute(fInput)); - * } + * @Parameters + * public static Collection<Object[]> data() { + * return Arrays.asList(new Object[][] { { 0, 0 }, { 1, 1 }, { 2, 1 }, + * { 3, 2 }, { 4, 3 }, { 5, 5 }, { 6, 8 } }); + * } + * + * private int fInput; + * + * private int fExpected; + * + * public FibonacciTest(int input, int expected) { + * fInput= input; + * fExpected= expected; + * } + * + * @Test + * public void test() { + * assertEquals(fExpected, Fibonacci.compute(fInput)); + * } * } * </pre> * - * <p>Each instance of <code>FibonacciTest</code> will be constructed using the two-argument - * constructor and the data values in the <code>@Parameters</code> method.</p> + * <p> + * Each instance of <code>FibonacciTest</code> will be constructed using the + * two-argument constructor and the data values in the + * <code>@Parameters</code> method. + * </p> */ public class Parameterized extends TestClassRunner { @Retention(RetentionPolicy.RUNTIME) @@ -67,87 +70,60 @@ return results; } - // TODO: single-class this extension - - private static class TestClassRunnerForParameters extends TestClassMethodsRunner { - private final Object[] fParameters; - - private final int fParameterSetNumber; + public Parameterized(final Class<?> klass) throws Exception { + super(klass, buildCompositeRunner(new JavaClass(klass))); + } - private final Constructor fConstructor; + // TODO: I think this now eagerly reads parameters, which was never the + // point. - private TestClassRunnerForParameters(JavaClass klass, Object[] parameters, int i) { - super(klass, new JavaTestInterpreter()); - fParameters= parameters; - fParameterSetNumber= i; - fConstructor= getOnlyConstructor(); + // TODO: pull interpreter back in? + private static CompositeRunner buildCompositeRunner( + final JavaClass klass) throws Exception { + CompositeRunner runner= new CompositeRunner(klass.getName()); + int i= 0; + for (final Object each : getParametersList(klass)) { + if (each instanceof Object[]) { + final int parameterSetNumber= i++; + JavaTestInterpreter interpreter= new ParameterizedInterpreter( + each, parameterSetNumber); + runner + .add(new TestClassMethodsRunner(interpreter + .interpretJavaClass(klass.getTestClass()), + interpreter)); + } else + throw new Exception(String.format( + "%s.%s() must return a Collection of arrays.", klass + .getName(), getParametersMethod(klass) + .getName())); } + return runner; + } - @Override - protected Object createTest() throws Exception { - return fConstructor.newInstance(fParameters); - } - - @Override - protected String getName() { - return String.format("[%s]", fParameterSetNumber); - } - - @Override - protected String testName(final JavaModelElement method) { - return String.format("%s[%s]", method.getName(), fParameterSetNumber); - } + @Override + protected void validate(MethodValidator methodValidator) { + methodValidator.validateStaticMethods(); + methodValidator.validateInstanceMethods(); + } - private Constructor getOnlyConstructor() { - Constructor[] constructors= getTestClass().getTestClass().getConstructors(); - assertEquals(1, constructors.length); - return constructors[0]; - } + // TODO: make non-static + static private Collection getParametersList(JavaClass javaClass) + throws IllegalAccessException, InvocationTargetException, Exception { + return (Collection) getParametersMethod(javaClass).invoke(null); } - - // TODO: I think this now eagerly reads parameters, which was never the point. - - public static class RunAllParameterMethods extends CompositeRunner { - private final JavaClass fKlass; - public RunAllParameterMethods(JavaClass klass) throws Exception { - super(klass.getName()); - fKlass= klass; - int i= 0; - for (final Object each : getParametersList()) { - if (each instanceof Object[]) - super.add(new TestClassRunnerForParameters(klass, (Object[])each, i++)); - else - throw new Exception(String.format("%s.%s() must return a Collection of arrays.", fKlass.getName(), getParametersMethod().getName())); - } - } + static private JavaMethod getParametersMethod(JavaClass javaClass) + throws Exception { + // TODO: is this DUP? + List<JavaMethod> methods= javaClass.getMethods(Parameters.class, + new JavaTestInterpreter()); - private Collection getParametersList() throws IllegalAccessException, InvocationTargetException, Exception { - return (Collection) getParametersMethod().invoke(null); - } - - private Method getParametersMethod() throws Exception { - for (Method each : fKlass.getTestClass().getMethods()) { - if (Modifier.isStatic(each.getModifiers())) { - Annotation[] annotations= each.getAnnotations(); - for (Annotation annotation : annotations) { - if (annotation.annotationType() == Parameters.class) - return each; - } - } + for (JavaMethod each : methods) { + if (each.isStatic() && each.isPublic()) { + return each; } - throw new Exception("No public static parameters method on class " - + getName()); } - } - - public Parameterized(final Class<?> klass) throws Exception { - super(klass, new RunAllParameterMethods(new JavaClass(klass))); - } - - @Override - protected void validate(MethodValidator methodValidator) { - methodValidator.validateStaticMethods(); - methodValidator.validateInstanceMethods(); + throw new Exception("No public static parameters method on class " + + javaClass.getName()); } } |
From: David S. <ds...@us...> - 2006-10-17 19:10:25
|
Update of /cvsroot/junit/junit/org/junit/tests In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv19803/org/junit/tests Modified Files: Tag: saff_r41_runner_refactoring InitializationErrorForwardCompatibilityTest.java ParameterizedTestMethodTest.java TestMethodTest.java UserStopTest.java CustomRunnerTest.java Log Message: InterpretWith allows a delegation-style, rather than inheritance-style, extension mechanism Index: InitializationErrorForwardCompatibilityTest.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/tests/InitializationErrorForwardCompatibilityTest.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -d -r1.3 -r1.3.2.1 --- InitializationErrorForwardCompatibilityTest.java 29 Jun 2006 23:06:45 -0000 1.3 +++ InitializationErrorForwardCompatibilityTest.java 17 Oct 2006 19:10:20 -0000 1.3.2.1 @@ -10,6 +10,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.internal.runners.EmptyDescription; +import org.junit.internal.runners.JavaTestInterpreter; import org.junit.internal.runners.TestClassRunner; import org.junit.runner.Description; import org.junit.runner.RunWith; @@ -94,7 +95,7 @@ public static class InitializesWithError extends TestClassRunner { public InitializesWithError(Class<?> klass) throws Exception { - super(klass); + super(klass, new JavaTestInterpreter()); throw new Exception(); } } Index: ParameterizedTestMethodTest.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/tests/ParameterizedTestMethodTest.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -d -r1.2 -r1.2.2.1 --- ParameterizedTestMethodTest.java 15 Feb 2006 22:55:29 -0000 1.2 +++ ParameterizedTestMethodTest.java 17 Oct 2006 19:10:20 -0000 1.2.2.1 @@ -14,6 +14,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.internal.runners.InitializationError; +import org.junit.internal.runners.JavaTestInterpreter; import org.junit.internal.runners.TestClassRunner; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; @@ -85,7 +86,7 @@ private List<Throwable> validateAllMethods(Class<?> clazz) { try { - new TestClassRunner(clazz); + new TestClassRunner(clazz, new JavaTestInterpreter()); } catch (InitializationError e) { return e.getCauses(); } Index: TestMethodTest.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/tests/TestMethodTest.java,v retrieving revision 1.3 retrieving revision 1.3.2.1 diff -u -d -r1.3 -r1.3.2.1 --- TestMethodTest.java 27 Apr 2006 22:11:51 -0000 1.3 +++ TestMethodTest.java 17 Oct 2006 19:10:20 -0000 1.3.2.1 @@ -15,6 +15,7 @@ import org.junit.Ignore; import org.junit.Test; import org.junit.internal.runners.InitializationError; +import org.junit.internal.runners.JavaTestInterpreter; import org.junit.internal.runners.MethodValidator; import org.junit.internal.runners.TestClassRunner; import org.junit.runner.JUnitCore; @@ -86,7 +87,7 @@ private List<Throwable> validateAllMethods(Class<?> clazz) { try { - new TestClassRunner(clazz); + new TestClassRunner(clazz, new JavaTestInterpreter()); } catch (InitializationError e) { return e.getCauses(); } Index: UserStopTest.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/tests/UserStopTest.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -d -r1.2 -r1.2.2.1 --- UserStopTest.java 15 Feb 2006 22:55:29 -0000 1.2 +++ UserStopTest.java 17 Oct 2006 19:10:20 -0000 1.2.2.1 @@ -2,6 +2,8 @@ import org.junit.Before; import org.junit.Test; +import org.junit.internal.runners.JavaMethod; +import org.junit.internal.runners.JavaTestInterpreter; import org.junit.internal.runners.TestMethodRunner; import org.junit.runner.Description; import org.junit.runner.Request; @@ -21,8 +23,9 @@ } @Test(expected=StoppedByUserException.class) public void stopMethodRunner() throws Exception { - new TestMethodRunner(this, OneTest.class.getMethod("foo"), fNotifier, - Description.createTestDescription(OneTest.class, "foo")).run(); + // TODO: is this a good test? + new TestMethodRunner(this, new JavaMethod(OneTest.class.getMethod("foo")), fNotifier, + Description.createTestDescription(OneTest.class, "foo"), new JavaTestInterpreter()).run(); } public static class OneTest { Index: CustomRunnerTest.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/tests/CustomRunnerTest.java,v retrieving revision 1.2 retrieving revision 1.2.2.1 diff -u -d -r1.2 -r1.2.2.1 --- CustomRunnerTest.java 15 Feb 2006 22:55:29 -0000 1.2 +++ CustomRunnerTest.java 17 Oct 2006 19:10:20 -0000 1.2.2.1 @@ -1,39 +1,23 @@ package org.junit.tests; +import static org.junit.Assert.*; + import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import org.junit.Assert; import org.junit.Test; -import org.junit.internal.runners.InitializationError; -import org.junit.internal.runners.TestClassMethodsRunner; -import org.junit.internal.runners.TestClassRunner; -import org.junit.internal.runners.TestMethodRunner; +import org.junit.internal.runners.JavaMethod; +import org.junit.internal.runners.JavaTestInterpreter; import org.junit.runner.JUnitCore; -import org.junit.runner.RunWith; -import org.junit.runner.notification.RunNotifier; - -import static org.junit.Assert.*; // TODO: better factoring here public class CustomRunnerTest { - public static class CustomRunner extends TestClassRunner { - public CustomRunner(Class<?> klass) throws InitializationError { - super(klass, new TestClassMethodsRunner(klass) { - @Override - protected TestMethodRunner createMethodRunner(Object test, Method method, RunNotifier notifier) { - return new TestMethodRunner(test, method, notifier, - methodDescription(method)) { - @Override - protected void executeMethodBody() - throws IllegalAccessException, - InvocationTargetException { - super.executeMethodBody(); - assertGlobalStateIsValid(); - } - }; - } - }); + public static class CustomInterpreter extends JavaTestInterpreter { + @Override + public void executeMethodBody(Object test, JavaMethod javaMethod) + throws IllegalAccessException, InvocationTargetException { + super.executeMethodBody(test, javaMethod); + assertGlobalStateIsValid(); } } @@ -41,7 +25,7 @@ Assert.fail(); } - @RunWith(CustomRunner.class) + @InterpretWith(CustomInterpreter.class) public static class UsesGlobalState { @Test public void foo() { |
From: David S. <ds...@us...> - 2006-10-17 19:08:45
|
Update of /cvsroot/junit/junit/org/junit/runners In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv18989/org/junit/runners Modified Files: Tag: saff_r41_runner_refactoring Parameterized.java Log Message: Uses Java model, but no significant changes yet Index: Parameterized.java =================================================================== RCS file: /cvsroot/junit/junit/org/junit/runners/Parameterized.java,v retrieving revision 1.5 retrieving revision 1.5.2.1 diff -u -d -r1.5 -r1.5.2.1 --- Parameterized.java 25 Aug 2006 14:43:02 -0000 1.5 +++ Parameterized.java 17 Oct 2006 19:08:40 -0000 1.5.2.1 @@ -1,6 +1,6 @@ package org.junit.runners; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.*; import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; @@ -16,6 +16,9 @@ import java.util.List; import org.junit.internal.runners.CompositeRunner; +import org.junit.internal.runners.JavaClass; +import org.junit.internal.runners.JavaModelElement; +import org.junit.internal.runners.JavaTestInterpreter; import org.junit.internal.runners.MethodValidator; import org.junit.internal.runners.TestClassMethodsRunner; import org.junit.internal.runners.TestClassRunner; @@ -73,8 +76,8 @@ private final Constructor fConstructor; - private TestClassRunnerForParameters(Class<?> klass, Object[] parameters, int i) { - super(klass); + private TestClassRunnerForParameters(JavaClass klass, Object[] parameters, int i) { + super(klass, new JavaTestInterpreter()); fParameters= parameters; fParameterSetNumber= i; fConstructor= getOnlyConstructor(); @@ -91,12 +94,12 @@ } @Override - protected String testName(final Method method) { + protected String testName(final JavaModelElement method) { return String.format("%s[%s]", method.getName(), fParameterSetNumber); } private Constructor getOnlyConstructor() { - Constructor[] constructors= getTestClass().getConstructors(); + Constructor[] constructors= getTestClass().getTestClass().getConstructors(); assertEquals(1, constructors.length); return constructors[0]; } @@ -105,9 +108,9 @@ // TODO: I think this now eagerly reads parameters, which was never the point. public static class RunAllParameterMethods extends CompositeRunner { - private final Class<?> fKlass; + private final JavaClass fKlass; - public RunAllParameterMethods(Class<?> klass) throws Exception { + public RunAllParameterMethods(JavaClass klass) throws Exception { super(klass.getName()); fKlass= klass; int i= 0; @@ -124,7 +127,7 @@ } private Method getParametersMethod() throws Exception { - for (Method each : fKlass.getMethods()) { + for (Method each : fKlass.getTestClass().getMethods()) { if (Modifier.isStatic(each.getModifiers())) { Annotation[] annotations= each.getAnnotations(); for (Annotation annotation : annotations) { @@ -139,7 +142,7 @@ } public Parameterized(final Class<?> klass) throws Exception { - super(klass, new RunAllParameterMethods(klass)); + super(klass, new RunAllParameterMethods(new JavaClass(klass))); } @Override |