Thread: [P-unit-devel] SF.net SVN: p-unit: [5] trunk/punit
Status: Beta
Brought to you by:
zhanghuangzhu
|
From: <zha...@us...> - 2007-05-08 00:25:33
|
Revision: 5
http://p-unit.svn.sourceforge.net/p-unit/?rev=5&view=rev
Author: zhanghuangzhu
Date: 2007-05-07 17:25:32 -0700 (Mon, 07 May 2007)
Log Message:
-----------
Andrew Zhang: Watcher/Util classes and test cases.
Modified Paths:
--------------
trunk/punit.test/.classpath
Added Paths:
-----------
trunk/punit/Copyright.txt
trunk/punit/punit.license.txt
trunk/punit/src/org/
trunk/punit/src/org/punit/
trunk/punit/src/org/punit/util/
trunk/punit/src/org/punit/util/MemoryUtil.java
trunk/punit/src/org/punit/util/ThreadUtil.java
trunk/punit/src/org/punit/watcher/
trunk/punit/src/org/punit/watcher/MemoryWatcher.java
trunk/punit/src/org/punit/watcher/TimeWatcher.java
trunk/punit/src/org/punit/watcher/Watcher.java
trunk/punit.test/Copyright.txt
trunk/punit.test/punit.license.txt
trunk/punit.test/src/tests/
trunk/punit.test/src/tests/api/
trunk/punit.test/src/tests/api/org/
trunk/punit.test/src/tests/api/org/punit/
trunk/punit.test/src/tests/api/org/punit/watcher/
trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java
trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java
Added: trunk/punit/Copyright.txt
===================================================================
--- trunk/punit/Copyright.txt (rev 0)
+++ trunk/punit/Copyright.txt 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,5 @@
+Copyright (C) 2007 reserved
+
+Author: Andrew Zhang
+
+Mail: zha...@gm...
\ No newline at end of file
Added: trunk/punit/punit.license.txt
===================================================================
--- trunk/punit/punit.license.txt (rev 0)
+++ trunk/punit/punit.license.txt 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,341 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+ a) You must cause the modified files to carry prominent notices
+ stating that you changed the files and the date of any change.
+
+ b) You must cause any work that you distribute or publish, that in
+ whole or in part contains or is derived from the Program or any
+ part thereof, to be licensed as a whole at no charge to all third
+ parties under the terms of this License.
+
+ c) If the modified program normally reads commands interactively
+ when run, you must cause it, when started running for such
+ interactive use in the most ordinary way, to print or display an
+ announcement including an appropriate copyright notice and a
+ notice that there is no warranty (or else, saying that you provide
+ a warranty) and that users may redistribute the program under
+ these conditions, and telling the user how to view a copy of this
+ License. (Exception: if the Program itself is interactive but
+ does not normally print such an announcement, your work based on
+ the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole. If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works. But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+ 3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+ a) Accompany it with the complete corresponding machine-readable
+ source code, which must be distributed under the terms of Sections
+ 1 and 2 above on a medium customarily used for software interchange; or,
+
+ b) Accompany it with a written offer, valid for at least three
+ years, to give any third party, for a charge no more than your
+ cost of physically performing source distribution, a complete
+ machine-readable copy of the corresponding source code, to be
+ distributed under the terms of Sections 1 and 2 above on a medium
+ customarily used for software interchange; or,
+
+ c) Accompany it with the information you received as to the offer
+ to distribute corresponding source code. (This alternative is
+ allowed only for noncommercial distribution and only if you
+ received the program in object code or executable form with such
+ an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it. For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable. However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+ 4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License. Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+ 5. You are not required to accept this License, since you have not
+signed it. However, nothing else grants you permission to modify or
+distribute the Program or its derivative works. These actions are
+prohibited by law if you do not accept this License. Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+ 6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions. You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+ 7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all. For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices. Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+ 8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded. In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+ 9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number. If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation. If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+ 10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission. For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this. Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+ NO WARRANTY
+
+ 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+ 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ <one line to give the program's name and a brief idea of what it does.>
+ Copyright (C) <year> <name of author>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+ Gnomovision version 69, Copyright (C) year name of author
+ Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary. Here is a sample; alter the names:
+
+ Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+ `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+ <signature of Ty Coon>, 1 April 1989
+ Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs. If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library. If this is what you want to do, use the GNU Library General
+Public License instead of this License.
+
Added: trunk/punit/src/org/punit/util/MemoryUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/MemoryUtil.java (rev 0)
+++ trunk/punit/src/org/punit/util/MemoryUtil.java 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,15 @@
+package org.punit.util;
+
+public class MemoryUtil {
+
+ private static Runtime _runtime = Runtime.getRuntime();
+
+ public static long usedMemory() {
+ return _runtime.totalMemory() - _runtime.freeMemory();
+ }
+
+ public static void clear() {
+ System.gc();
+ System.runFinalization();
+ }
+}
Added: trunk/punit/src/org/punit/util/ThreadUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ThreadUtil.java (rev 0)
+++ trunk/punit/src/org/punit/util/ThreadUtil.java 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,11 @@
+package org.punit.util;
+
+public class ThreadUtil {
+ public static void sleepIgnoreInterruption(long millis) {
+ try {
+ Thread.sleep(millis);
+ } catch (InterruptedException e) {
+
+ }
+ }
+}
Added: trunk/punit/src/org/punit/watcher/MemoryWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/MemoryWatcher.java (rev 0)
+++ trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,43 @@
+package org.punit.watcher;
+
+import org.punit.util.*;
+
+public class MemoryWatcher implements Watcher {
+
+ private long _startUsedMemory;
+
+ private long _maxUsedMemory;
+
+ private boolean _stop;
+
+ public void start() {
+ _stop = false;
+ MemoryUtil.clear();
+ _maxUsedMemory = _startUsedMemory = MemoryUtil.usedMemory();
+ new MemoryWatcherThread().start();
+ }
+
+ public void stop() {
+ _stop = true;
+ monitorMemory();
+ }
+
+ public Object value() {
+ return _maxUsedMemory - _startUsedMemory ;
+ }
+
+ private void monitorMemory() {
+ long usedMemory = MemoryUtil.usedMemory();
+ if(usedMemory > _maxUsedMemory) {
+ _maxUsedMemory = usedMemory;
+ }
+ }
+ private class MemoryWatcherThread extends Thread {
+ public void run() {
+ while(!_stop) {
+ monitorMemory();
+ ThreadUtil.sleepIgnoreInterruption(10);
+ }
+ }
+ }
+}
Added: trunk/punit/src/org/punit/watcher/TimeWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/TimeWatcher.java (rev 0)
+++ trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,39 @@
+/*
+This file is part of the PolePosition database benchmark
+http://www.polepos.org
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public
+License along with this program; if not, write to the Free
+Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+MA 02111-1307, USA. */
+
+package org.punit.watcher;
+
+public class TimeWatcher implements Watcher {
+
+ private long _startTime;
+
+ private long _endTime;
+
+ public void start() {
+ _startTime = System.nanoTime();
+ }
+
+ public void stop() {
+ _endTime = System.nanoTime();
+ }
+
+ public Object value() {
+ return (_endTime - _startTime)/1000000;
+ }
+}
Added: trunk/punit/src/org/punit/watcher/Watcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/Watcher.java (rev 0)
+++ trunk/punit/src/org/punit/watcher/Watcher.java 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,11 @@
+package org.punit.watcher;
+
+public interface Watcher {
+
+ public void start();
+
+ public void stop();
+
+ public Object value();
+
+}
Modified: trunk/punit.test/.classpath
===================================================================
--- trunk/punit.test/.classpath 2007-05-07 22:23:07 UTC (rev 4)
+++ trunk/punit.test/.classpath 2007-05-08 00:25:32 UTC (rev 5)
@@ -3,5 +3,6 @@
<classpathentry path="src" kind="src"/>
<classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/>
<classpathentry path="/punit" combineaccessrules="false" kind="src"/>
+ <classpathentry path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1" kind="con"/>
<classpathentry path="bin" kind="output"/>
</classpath>
Added: trunk/punit.test/Copyright.txt
===================================================================
--- trunk/punit.test/Copyright.txt (rev 0)
+++ trunk/punit.test/Copyright.txt 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,5 @@
+Copyright (C) 2007 reserved
+
+Author: Andrew Zhang
+
+Mail: zha...@gm...
\ No newline at end of file
Added: trunk/punit.test/punit.license.txt
===================================================================
--- trunk/punit.test/punit.license.txt (rev 0)
+++ trunk/punit.test/punit.license.txt 2007-05-08 00:25:32 UTC (rev 5)
@@ -0,0 +1,341 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The licenses for most software are designed to take away your
+freedom to share and change it. By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users. This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it. (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.) You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+ To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have. You must make sure that they, too, receive or can get the
+source code. And you must show them these terms so they know their
+rights.
+
+ We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+ Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software. If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+ Finally, any free program is threatened constantly by software
+patents. We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary. To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ GNU GENERAL PUBLIC LICENSE
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+ 0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License. The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language. (Hereinafter, translation is included without limitation in
+the term "modification".) Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope. The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+ 1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+ 2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy a...
[truncated message content] |
|
From: <zha...@us...> - 2007-05-08 18:49:52
|
Revision: 6
http://p-unit.svn.sourceforge.net/p-unit/?rev=6&view=rev
Author: zhanghuangzhu
Date: 2007-05-08 11:49:54 -0700 (Tue, 08 May 2007)
Log Message:
-----------
Andrew Zhang: Stubs for implementation and test code.
Added Paths:
-----------
trunk/punit/src/org/punit/TestResult.java
trunk/punit/src/org/punit/runner/
trunk/punit/src/org/punit/runner/Competitive.java
trunk/punit/src/org/punit/runner/Concurrent.java
trunk/punit/src/org/punit/runner/PUnitRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit.test/src/tests/sample/
trunk/punit.test/src/tests/sample/testcase/
trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java
trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java
trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java
trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java
Added: trunk/punit/src/org/punit/TestResult.java
===================================================================
--- trunk/punit/src/org/punit/TestResult.java (rev 0)
+++ trunk/punit/src/org/punit/TestResult.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,5 @@
+package org.punit;
+
+public interface TestResult {
+
+}
Added: trunk/punit/src/org/punit/runner/Competitive.java
===================================================================
--- trunk/punit/src/org/punit/runner/Competitive.java (rev 0)
+++ trunk/punit/src/org/punit/runner/Competitive.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,6 @@
+package org.punit.runner;
+
+public interface Competitive {
+ public Class testInterface();
+ public Class[] implmentators();
+}
Added: trunk/punit/src/org/punit/runner/Concurrent.java
===================================================================
--- trunk/punit/src/org/punit/runner/Concurrent.java (rev 0)
+++ trunk/punit/src/org/punit/runner/Concurrent.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,5 @@
+package org.punit.runner;
+
+public interface Concurrent {
+ public int concurrentCount();
+}
Added: trunk/punit/src/org/punit/runner/PUnitRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/PUnitRunner.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,11 @@
+package org.punit.runner;
+
+import org.punit.*;
+
+public class PUnitRunner implements Runner {
+
+ public TestResult run(Class clazz) {
+ throw new UnsupportedOperationException();
+ }
+
+}
Added: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/Runner.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,7 @@
+package org.punit.runner;
+
+import org.punit.*;
+
+public interface Runner {
+ public TestResult run(Class clazz);
+}
Added: trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,27 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+
+public class CompetitiveTestSample implements Competitive {
+
+ public static void main(String[] args) {
+ new PUnitRunner().run(CompetitiveTestSample.class);
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+ public Class[] implmentators() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Class testInterface() {
+ throw new UnsupportedOperationException();
+ }
+
+}
Added: trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,23 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+
+public class ConcurrentTestSample implements Concurrent {
+
+ public static void main(String[] args) {
+ new PUnitRunner().run(ConcurrentTestSample.class);
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+ public int concurrentCount() {
+ return 10;
+ }
+
+}
Added: trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,21 @@
+package tests.sample.testcase;
+
+import junit.framework.*;
+
+import org.punit.runner.*;
+
+public class JUnitTestSample extends TestCase {
+
+ public static void main(String[] args) {
+ new PUnitRunner().run(JUnitTestSample.class);
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+}
Added: trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java 2007-05-08 18:49:54 UTC (rev 6)
@@ -0,0 +1,19 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+
+public class SimpleTestSample {
+
+ public static void main(String[] args) {
+ new PUnitRunner().run(SimpleTestSample.class);
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-09 06:49:48
|
Revision: 7
http://p-unit.svn.sourceforge.net/p-unit/?rev=7&view=rev
Author: zhanghuangzhu
Date: 2007-05-08 23:49:48 -0700 (Tue, 08 May 2007)
Log Message:
-----------
Andrew Zhang:
1. Defined Parameterizable interface, and move all interface to type package.
2. Defined TestResult as a sub interface of j.u.Collection.
Modified Paths:
--------------
trunk/punit/src/org/punit/TestResult.java
trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java
trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java
Added Paths:
-----------
trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
trunk/punit/src/org/punit/type/
trunk/punit/src/org/punit/type/Competitive.java
trunk/punit/src/org/punit/type/Concurrent.java
trunk/punit/src/org/punit/type/Parameter.java
trunk/punit/src/org/punit/type/Parameterizable.java
trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java
Removed Paths:
-------------
trunk/punit/src/org/punit/runner/Competitive.java
trunk/punit/src/org/punit/runner/Concurrent.java
Modified: trunk/punit/src/org/punit/TestResult.java
===================================================================
--- trunk/punit/src/org/punit/TestResult.java 2007-05-08 18:49:54 UTC (rev 6)
+++ trunk/punit/src/org/punit/TestResult.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -1,5 +1,7 @@
package org.punit;
-public interface TestResult {
+import java.util.*;
+public interface TestResult extends Collection {
+
}
Deleted: trunk/punit/src/org/punit/runner/Competitive.java
===================================================================
--- trunk/punit/src/org/punit/runner/Competitive.java 2007-05-08 18:49:54 UTC (rev 6)
+++ trunk/punit/src/org/punit/runner/Competitive.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -1,6 +0,0 @@
-package org.punit.runner;
-
-public interface Competitive {
- public Class testInterface();
- public Class[] implmentators();
-}
Deleted: trunk/punit/src/org/punit/runner/Concurrent.java
===================================================================
--- trunk/punit/src/org/punit/runner/Concurrent.java 2007-05-08 18:49:54 UTC (rev 6)
+++ trunk/punit/src/org/punit/runner/Concurrent.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -1,5 +0,0 @@
-package org.punit.runner;
-
-public interface Concurrent {
- public int concurrentCount();
-}
Added: trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -0,0 +1,11 @@
+package org.punit.runner;
+
+import org.punit.*;
+
+public class PUnitConcurrentRunner implements Runner {
+
+ public TestResult run(Class clazz) {
+ throw new UnsupportedOperationException();
+ }
+
+}
Copied: trunk/punit/src/org/punit/type/Competitive.java (from rev 6, trunk/punit/src/org/punit/runner/Competitive.java)
===================================================================
--- trunk/punit/src/org/punit/type/Competitive.java (rev 0)
+++ trunk/punit/src/org/punit/type/Competitive.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -0,0 +1,6 @@
+package org.punit.type;
+
+public interface Competitive {
+ public Class testInterface();
+ public Class[] implmentators();
+}
Copied: trunk/punit/src/org/punit/type/Concurrent.java (from rev 6, trunk/punit/src/org/punit/runner/Concurrent.java)
===================================================================
--- trunk/punit/src/org/punit/type/Concurrent.java (rev 0)
+++ trunk/punit/src/org/punit/type/Concurrent.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface Concurrent {
+ public int concurrentCount();
+}
Added: trunk/punit/src/org/punit/type/Parameter.java
===================================================================
--- trunk/punit/src/org/punit/type/Parameter.java (rev 0)
+++ trunk/punit/src/org/punit/type/Parameter.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface Parameter {
+
+}
Added: trunk/punit/src/org/punit/type/Parameterizable.java
===================================================================
--- trunk/punit/src/org/punit/type/Parameterizable.java (rev 0)
+++ trunk/punit/src/org/punit/type/Parameterizable.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface Parameterizable {
+ Parameter [] paramters();
+}
Modified: trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java 2007-05-08 18:49:54 UTC (rev 6)
+++ trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -1,6 +1,7 @@
package tests.sample.testcase;
import org.punit.runner.*;
+import org.punit.type.*;
public class CompetitiveTestSample implements Competitive {
Modified: trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java 2007-05-08 18:49:54 UTC (rev 6)
+++ trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -1,6 +1,7 @@
package tests.sample.testcase;
import org.punit.runner.*;
+import org.punit.type.*;
public class ConcurrentTestSample implements Concurrent {
Added: trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java 2007-05-09 06:49:48 UTC (rev 7)
@@ -0,0 +1,32 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+public class ParameterizableTestSample implements Parameterizable {
+
+ public static void main(String[] args) {
+ new PUnitRunner().run(ParameterizableTestSample.class);
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+ public Class[] implmentators() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Class testInterface() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Parameter[] paramters() {
+ throw new UnsupportedOperationException();
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-09 19:47:23
|
Revision: 8
http://p-unit.svn.sourceforge.net/p-unit/?rev=8&view=rev
Author: zhanghuangzhu
Date: 2007-05-09 12:47:22 -0700 (Wed, 09 May 2007)
Log Message:
-----------
Andrew Zhang: defined VMComparable interface
Added Paths:
-----------
trunk/punit/src/org/punit/type/VM.java
trunk/punit/src/org/punit/type/VMComparable.java
trunk/punit.test/src/tests/sample/testcase/VMTestSample.java
Added: trunk/punit/src/org/punit/type/VM.java
===================================================================
--- trunk/punit/src/org/punit/type/VM.java (rev 0)
+++ trunk/punit/src/org/punit/type/VM.java 2007-05-09 19:47:22 UTC (rev 8)
@@ -0,0 +1,21 @@
+package org.punit.type;
+
+public class VM {
+ private String _vmPath;
+
+ private String _vmName;
+
+ public VM(String path, String name) {
+ super();
+ _vmPath = path;
+ _vmName = name;
+ }
+
+ public String vmName() {
+ return _vmName;
+ }
+
+ public String vmPath() {
+ return _vmPath;
+ }
+}
Added: trunk/punit/src/org/punit/type/VMComparable.java
===================================================================
--- trunk/punit/src/org/punit/type/VMComparable.java (rev 0)
+++ trunk/punit/src/org/punit/type/VMComparable.java 2007-05-09 19:47:22 UTC (rev 8)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface VMComparable {
+public VM[] vms();
+}
Added: trunk/punit.test/src/tests/sample/testcase/VMTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/VMTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/VMTestSample.java 2007-05-09 19:47:22 UTC (rev 8)
@@ -0,0 +1,32 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+public class VMTestSample implements VMComparable {
+
+ public static void main(String[] args) {
+ new PUnitRunner().run(VMTestSample.class);
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+ public Class[] implmentators() {
+ throw new UnsupportedOperationException();
+ }
+
+ public Class testInterface() {
+ throw new UnsupportedOperationException();
+ }
+
+ public VM[] vms() {
+ throw new UnsupportedOperationException();
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-09 19:57:20
|
Revision: 9
http://p-unit.svn.sourceforge.net/p-unit/?rev=9&view=rev
Author: zhanghuangzhu
Date: 2007-05-09 12:57:21 -0700 (Wed, 09 May 2007)
Log Message:
-----------
Andrew Zhang: defined Test interface.
Added Paths:
-----------
trunk/punit/src/org/punit/type/Alphabetical.java
trunk/punit/src/org/punit/type/Test.java
trunk/punit.test/src/tests/sample/testcase/PUnitTestSample.java
Added: trunk/punit/src/org/punit/type/Alphabetical.java
===================================================================
--- trunk/punit/src/org/punit/type/Alphabetical.java (rev 0)
+++ trunk/punit/src/org/punit/type/Alphabetical.java 2007-05-09 19:57:21 UTC (rev 9)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface Alphabetical {
+
+}
Added: trunk/punit/src/org/punit/type/Test.java
===================================================================
--- trunk/punit/src/org/punit/type/Test.java (rev 0)
+++ trunk/punit/src/org/punit/type/Test.java 2007-05-09 19:57:21 UTC (rev 9)
@@ -0,0 +1,9 @@
+package org.punit.type;
+
+public interface Test {
+
+ public void setUpBeforeWatchers();
+
+ public void tearDownAfterWatchers();
+
+}
Added: trunk/punit.test/src/tests/sample/testcase/PUnitTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/PUnitTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/PUnitTestSample.java 2007-05-09 19:57:21 UTC (rev 9)
@@ -0,0 +1,28 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+public class PUnitTestSample implements Test {
+
+ public static void main(String[] args) {
+ new PUnitRunner().run(PUnitTestSample.class);
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+ public void setUpBeforeWatchers() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void tearDownAfterWatchers() {
+ throw new UnsupportedOperationException();
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-09 22:29:41
|
Revision: 11
http://p-unit.svn.sourceforge.net/p-unit/?rev=11&view=rev
Author: zhanghuangzhu
Date: 2007-05-09 15:29:40 -0700 (Wed, 09 May 2007)
Log Message:
-----------
Andrew Zhang: implemented buildTestClasses in PUnitRunner.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/PUnitRunner.java
trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java
trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java
Added Paths:
-----------
trunk/punit/src/org/punit/exception/
trunk/punit/src/org/punit/exception/ReflectionException.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
trunk/punit.test/src/tests/api/org/punit/all/
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/runner/
trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java
trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java
trunk/punit.test/src/tests/util/
trunk/punit.test/src/tests/util/AssertUtil.java
Added: trunk/punit/src/org/punit/exception/ReflectionException.java
===================================================================
--- trunk/punit/src/org/punit/exception/ReflectionException.java (rev 0)
+++ trunk/punit/src/org/punit/exception/ReflectionException.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -0,0 +1,10 @@
+package org.punit.exception;
+
+public class ReflectionException extends RuntimeException {
+
+ private static final long serialVersionUID = -5498831354775690972L;
+
+ public ReflectionException(Throwable e) {
+ super(e);
+ }
+}
Modified: trunk/punit/src/org/punit/runner/PUnitRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitRunner.java 2007-05-09 20:09:16 UTC (rev 10)
+++ trunk/punit/src/org/punit/runner/PUnitRunner.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -1,11 +1,46 @@
package org.punit.runner;
+import java.util.*;
+
import org.punit.*;
+import org.punit.type.*;
+import org.punit.util.*;
public class PUnitRunner implements Runner {
public TestResult run(Class clazz) {
+ List testClasses = buildTestClasses(clazz);
throw new UnsupportedOperationException();
}
+ protected List buildTestClasses(Class clazz) {
+ List testClasses = new ArrayList();
+ buildTestClasses(testClasses, clazz);
+ return testClasses;
+ }
+
+ private void buildTestClasses(List testClasses, Class clazz) {
+ if(isTestSuite(clazz)) {
+ buildTestClassFromTestSuite(testClasses, clazz);
+ } else {
+ buildTestClassesFromClass(testClasses, clazz);
+ }
+ }
+
+ private void buildTestClassFromTestSuite(List testClasses, Class clazz) {
+ TestSuite testSuite = (TestSuite) ReflectionUtil.newInstance(clazz);
+ Class[] suite = testSuite.suite();
+ for(int i = 0; i < suite.length; ++i) {
+ buildTestClasses(testClasses, suite[i]);
+ }
+ }
+
+ private void buildTestClassesFromClass(List testClasses, Class clazz) {
+ testClasses.add(clazz);
+ }
+
+ private boolean isTestSuite(Class clazz) {
+ return TestSuite.class.isAssignableFrom(clazz);
+ }
+
}
Added: trunk/punit/src/org/punit/util/ReflectionUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ReflectionUtil.java (rev 0)
+++ trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -0,0 +1,17 @@
+package org.punit.util;
+
+import java.lang.reflect.*;
+
+import org.punit.exception.*;
+
+public class ReflectionUtil {
+ public static Object newInstance(Class clazz) {
+ try {
+ Constructor constructor = clazz.getDeclaredConstructor(new Class[] {});
+ constructor.setAccessible(true);
+ return constructor.newInstance();
+ } catch (Exception e) {
+ throw new ReflectionException(e);
+ }
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -0,0 +1,17 @@
+package tests.api.org.punit.all;
+
+import junit.framework.*;
+import tests.api.org.punit.runner.*;
+import tests.api.org.punit.watcher.*;
+
+public class AllTests {
+ public static Test suite() {
+ TestSuite suite = new TestSuite("Test for tests.api.org.punit");
+ //$JUnit-BEGIN$
+ suite.addTestSuite(PUnitRunnerTest.class);
+ suite.addTestSuite(MemoryWatcherTest.class);
+ suite.addTestSuite(TimeWatcherTest.class);
+ //$JUnit-END$
+ return suite;
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -0,0 +1,78 @@
+package tests.api.org.punit.runner;
+
+import java.util.*;
+
+import junit.framework.*;
+
+import org.punit.runner.*;
+
+import tests.util.*;
+
+public class PUnitRunnerTest extends TestCase {
+
+ private MockPUnitRunner _runner;
+
+ protected void setUp() throws Exception {
+ _runner = new MockPUnitRunner();
+ }
+
+ public void testBuildTestClasses1() {
+ List list = _runner.publicBuildTestClasses(Test1.class);
+ AssertUtil.assertArray(list.toArray(), new Class[] { Test1.class });
+ }
+
+ public void testBuildTestClasses2() {
+ List list = _runner.publicBuildTestClasses(MorkTestSuite1.class);
+ AssertUtil.assertArray(list.toArray(), new Class[] { Test1.class,
+ Test2.class, Test3.class });
+ }
+
+ public void testBuildTestClasses3() {
+ List list = _runner.publicBuildTestClasses(MorkTestSuite2.class);
+ AssertUtil.assertArray(list.toArray(), new Class[] { Test4.class,
+ Test1.class, Test2.class, Test3.class, Test5.class });
+ }
+
+ private static class MockPUnitRunner extends PUnitRunner {
+ public List publicBuildTestClasses(Class clazz) {
+ return super.buildTestClasses(clazz);
+ }
+ }
+
+ private static class MorkTestSuite1 implements org.punit.type.TestSuite {
+ public Class[] suite() {
+ return new Class[] { Test1.class, Test2.class, Test3.class,
+
+ };
+ }
+ }
+
+ private static class MorkTestSuite2 implements org.punit.type.TestSuite {
+ public Class[] suite() {
+ return new Class[] { Test4.class, MorkTestSuite1.class,
+ Test5.class,
+
+ };
+ }
+ }
+
+ private static class Test1 {
+
+ }
+
+ private static class Test2 {
+
+ }
+
+ private static class Test3 {
+
+ }
+
+ private static class Test4 {
+
+ }
+
+ private static class Test5 {
+
+ }
+}
Modified: trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java 2007-05-09 20:09:16 UTC (rev 10)
+++ trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -5,14 +5,16 @@
import org.punit.watcher.*;
public class MemoryWatcherTest extends TestCase {
+
private MemoryWatcher _watcher;
+
+ private static final int MEMORY_CONSUMPTION = 1024*1024;
protected void setUp() throws Exception {
_watcher = new MemoryWatcher();
}
public void test() throws Exception {
- final int MEMORY_CONSUMPTION = 1024*1024*10;
_watcher.start();
byte[] data = new byte[MEMORY_CONSUMPTION];
for(int i = 0; i < data.length; ++i) {
Modified: trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java 2007-05-09 20:09:16 UTC (rev 10)
+++ trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -5,6 +5,7 @@
import org.punit.watcher.*;
public class TimeWatcherTest extends TestCase {
+ private static final int SLEEP_TIME = 500;
private TimeWatcher _watcher;
protected void setUp() throws Exception {
@@ -13,13 +14,13 @@
public void test() throws Exception {
_watcher.start();
- Thread.sleep(1000);
+ Thread.sleep(SLEEP_TIME);
_watcher.stop();
Long value = (Long) _watcher.value();
long timeElapsed = value.longValue();
// The following assertions are not safe in theory, but it works
// practically.
- assertTrue(timeElapsed < 1500);
- assertTrue(timeElapsed > 500);
+ assertTrue(timeElapsed < SLEEP_TIME * 1.2);
+ assertTrue(timeElapsed > SLEEP_TIME * 0.8);
}
}
Added: trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -0,0 +1,9 @@
+package tests.sample.testcase;
+
+import org.punit.type.*;
+
+public class PUnitTestSuiteSample implements TestSuite {
+ public Class[] suite() {
+ throw new UnsupportedOperationException();
+ }
+}
Added: trunk/punit.test/src/tests/util/AssertUtil.java
===================================================================
--- trunk/punit.test/src/tests/util/AssertUtil.java (rev 0)
+++ trunk/punit.test/src/tests/util/AssertUtil.java 2007-05-09 22:29:40 UTC (rev 11)
@@ -0,0 +1,12 @@
+package tests.util;
+
+import java.util.*;
+
+import junit.framework.*;
+
+public class AssertUtil {
+
+ public static void assertArray(Object[] array1, Object[] array2) {
+ Assert.assertTrue(Arrays.equals(array1, array2));
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-10 16:22:28
|
Revision: 12
http://p-unit.svn.sourceforge.net/p-unit/?rev=12&view=rev
Author: zhanghuangzhu
Date: 2007-05-10 09:22:27 -0700 (Thu, 10 May 2007)
Log Message:
-----------
Andrew Zhang: first step to implement the runner.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
trunk/punit/src/org/punit/runner/PUnitRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/type/Test.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java
trunk/punit.test/src/tests/util/AssertUtil.java
Added Paths:
-----------
trunk/punit/src/org/punit/builder/
trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java
trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java
trunk/punit/src/org/punit/builder/TestMethodBuilder.java
trunk/punit/src/org/punit/builder/TestSuiteBuilder.java
trunk/punit/src/org/punit/result/
trunk/punit/src/org/punit/result/ConcurrentException.java
trunk/punit/src/org/punit/result/TestResult.java
trunk/punit/src/org/punit/result/TestResultItem.java
trunk/punit/src/org/punit/result/TestResultItemImpl.java
trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java
trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java
trunk/punit/src/org/punit/runner/TestMethodRunner.java
trunk/punit/src/org/punit/type/Comparable.java
trunk/punit/src/org/punit/type/Version.java
trunk/punit/src/org/punit/type/VersionCompetitive.java
trunk/punit.test/src/tests/api/org/punit/builder/
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestSuiteBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/util/
trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java
trunk/punit.test/src/tests/sample/testcase/VersionCompetitiveTestSample.java
trunk/punit.test/src/tests/util/CodeRunner.java
Removed Paths:
-------------
trunk/punit/src/org/punit/TestResult.java
trunk/punit/src/org/punit/type/Competitive.java
trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java
trunk/punit.test/src/tests/sample/testcase/PUnitTestSample.java
Deleted: trunk/punit/src/org/punit/TestResult.java
===================================================================
--- trunk/punit/src/org/punit/TestResult.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit/src/org/punit/TestResult.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,7 +0,0 @@
-package org.punit;
-
-import java.util.*;
-
-public interface TestResult extends Collection {
-
-}
Added: trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java (rev 0)
+++ trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,55 @@
+package org.punit.builder;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class PUnitTestMethodBuilder implements TestMethodBuilder {
+
+ public Object[] buildTestMethods(Class testClass) {
+ Method[] methods = testClass.getDeclaredMethods();
+ Collection testMethods;
+ if (isAlphabetical(testClass)) {
+ testMethods = new TreeSet(new AlphabeticalMethodNameComparator());
+ } else {
+ testMethods = new ArrayList();
+ }
+ for (int i = 0; i < methods.length; ++i) {
+ Method method = methods[i];
+ if (isTestMethod(method)) {
+ testMethods.add(method);
+ }
+ }
+ return testMethods.toArray();
+ }
+
+ private boolean isAlphabetical(Class testClass) {
+ return Alphabetical.class.isAssignableFrom(testClass);
+ }
+
+ /**
+ * Returns true if this method is regarded as a test method. Might be
+ * overriden by the subclass for convenience.
+ *
+ * By default, returns true if the method is public and not static, and
+ * starts with "test".
+ *
+ * @param method
+ * @return true if it is a test method
+ */
+ protected boolean isTestMethod(Method method) {
+ String name = method.getName();
+ return ReflectionUtil.isPublic(method)
+ && !ReflectionUtil.isStatic(method) && name.startsWith("test");
+ }
+
+ private static class AlphabeticalMethodNameComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ Method m1 = (Method) o1;
+ Method m2 = (Method) o2;
+ return m1.getName().compareTo(m2.getName());
+ }
+ }
+}
Added: trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java (rev 0)
+++ trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,41 @@
+package org.punit.builder;
+
+import java.util.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class PUnitTestSuiteBuilder implements TestSuiteBuilder {
+ public Object[] buildTestClasses(Class clazz) {
+ List testClasses = new ArrayList();
+ buildTestClasses(testClasses, clazz);
+ return testClasses.toArray();
+ }
+
+ private void buildTestClasses(List testClasses, Class clazz) {
+ if(isTestSuite(clazz)) {
+ buildTestClassFromTestSuite(testClasses, clazz);
+ } else {
+ buildTestClassesFromClass(testClasses, clazz);
+ }
+ }
+
+ private void buildTestClassFromTestSuite(List testClasses, Class clazz) {
+ TestSuite testSuite = (TestSuite) ReflectionUtil.newInstance(clazz);
+ Class[] suite = testSuite.suite();
+ for(int i = 0; i < suite.length; ++i) {
+ buildTestClasses(testClasses, suite[i]);
+ }
+ }
+
+ private void buildTestClassesFromClass(List testClasses, Class clazz) {
+ String name = null;
+ testClasses.add(clazz);
+ }
+
+
+ private boolean isTestSuite(Class clazz) {
+ return TestSuite.class.isAssignableFrom(clazz);
+ }
+
+}
Added: trunk/punit/src/org/punit/builder/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/TestMethodBuilder.java (rev 0)
+++ trunk/punit/src/org/punit/builder/TestMethodBuilder.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,13 @@
+package org.punit.builder;
+
+public interface TestMethodBuilder {
+ /**
+ * Builds the test methods from the test class. Returns a list of methods.
+ * The real return type should be Method[]. It returns Object[] for java 1.4
+ * compatibility.
+ *
+ * @param clazz
+ * @return
+ */
+ public Object[] buildTestMethods(Class testClass);
+}
Added: trunk/punit/src/org/punit/builder/TestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/TestSuiteBuilder.java (rev 0)
+++ trunk/punit/src/org/punit/builder/TestSuiteBuilder.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,12 @@
+package org.punit.builder;
+
+public interface TestSuiteBuilder {
+ /**
+ * Builds the test suite. Returns a list of test classes. The real return
+ * type should be Class[]. It returns Object[] for java 1.4 compatibility.
+ *
+ * @param clazz
+ * @return
+ */
+ public Object[] buildTestClasses(Class testSutie);
+}
Added: trunk/punit/src/org/punit/result/ConcurrentException.java
===================================================================
--- trunk/punit/src/org/punit/result/ConcurrentException.java (rev 0)
+++ trunk/punit/src/org/punit/result/ConcurrentException.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,13 @@
+package org.punit.result;
+
+import java.util.*;
+
+public class ConcurrentException extends RuntimeException {
+ private Vector _throwables;
+ public void add(Throwable t) {
+ _throwables.add(t);
+ }
+ public int size() {
+ return _throwables.size();
+ }
+}
Copied: trunk/punit/src/org/punit/result/TestResult.java (from rev 7, trunk/punit/src/org/punit/TestResult.java)
===================================================================
--- trunk/punit/src/org/punit/result/TestResult.java (rev 0)
+++ trunk/punit/src/org/punit/result/TestResult.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,6 @@
+package org.punit.result;
+
+
+public interface TestResult {
+ public TestResultItem [] result();
+}
Added: trunk/punit/src/org/punit/result/TestResultItem.java
===================================================================
--- trunk/punit/src/org/punit/result/TestResultItem.java (rev 0)
+++ trunk/punit/src/org/punit/result/TestResultItem.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,11 @@
+package org.punit.result;
+
+public interface TestResultItem {
+
+ public abstract int id();
+
+ public abstract String[] names();
+
+ public abstract long[] values();
+
+}
\ No newline at end of file
Added: trunk/punit/src/org/punit/result/TestResultItemImpl.java
===================================================================
--- trunk/punit/src/org/punit/result/TestResultItemImpl.java (rev 0)
+++ trunk/punit/src/org/punit/result/TestResultItemImpl.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,31 @@
+package org.punit.result;
+
+public class TestResultItemImpl implements TestResultItem {
+ private int id;
+
+ private String[] names;
+
+ private long[] values;
+
+ private Throwable throwable;
+
+
+ public TestResultItemImpl(int id, String[] names, long[] values, Throwable throwable) {
+ this.id = id;
+ this.names = names;
+ this.values = values;
+ this.throwable = throwable;
+ }
+
+ public int id() {
+ return id;
+ }
+
+ public String[] names() {
+ return names;
+ }
+
+ public long[] values() {
+ return values;
+ }
+}
Added: trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,106 @@
+package org.punit.runner;
+
+import java.lang.reflect.*;
+
+import org.punit.exception.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
+
+public abstract class AbstractTestMethodRunner implements TestMethodRunner {
+
+ protected final Watcher[] _watchers;
+
+ protected Object _testInstance;
+
+ protected Method _method;
+
+ protected Class _class;
+
+ protected Method _tearDownMethod;
+
+ protected Method _setUpMethod;
+
+ public AbstractTestMethodRunner(Watcher[] watchers) {
+ _watchers = watchers;
+ }
+
+ public Object[] run(Class clazz, Method method) throws Throwable {
+ try {
+ init(clazz, method);
+ setUp();
+ setUpBeforeWatchers();
+ startWatchers();
+ runImpl();
+ } finally {
+ stopWatchers();
+ tearDown();
+ }
+ return watchersValues();
+ }
+
+ protected abstract void runImpl() throws Throwable;
+
+ protected final void init(Class clazz, Method method) {
+ _testInstance = ReflectionUtil.newInstance(clazz);
+ _class = clazz;
+ _method = method;
+ _method.setAccessible(true);
+ }
+
+ /**
+ * Subclass could override this method to do some custom setup before
+ * watchers start.
+ *
+ */
+ protected void setUpBeforeWatchers() {
+
+ }
+
+ protected void setUp() throws Throwable {
+ _setUpMethod = ReflectionUtil.getMethod(_testInstance.getClass(),
+ "setUp", new Class[] {});
+ if (_setUpMethod != null) {
+ _setUpMethod.setAccessible(true);
+ try {
+ ReflectionUtil.invokeMethod(_setUpMethod, _testInstance,
+ new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+ }
+
+ protected void tearDown() throws Throwable {
+ _tearDownMethod = ReflectionUtil.getMethod(_testInstance.getClass(),
+ "tearDown", new Class[] {});
+ if (_tearDownMethod != null) {
+ _tearDownMethod.setAccessible(true);
+ try {
+ ReflectionUtil.invokeMethod(_tearDownMethod, _testInstance,
+ new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+ }
+
+ protected final void startWatchers() {
+ for (int i = 0; i < _watchers.length; ++i) {
+ _watchers[i].start();
+ }
+ }
+
+ protected final void stopWatchers() {
+ for (int i = 0; i < _watchers.length; ++i) {
+ _watchers[i].stop();
+ }
+ }
+
+ protected final Object[] watchersValues() {
+ Object[] values = new Object[_watchers.length];
+ for (int i = 0; i < _watchers.length; ++i) {
+ values[i] = _watchers[i].value();
+ }
+ return values;
+ }
+}
Added: trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,67 @@
+package org.punit.runner;
+
+import org.punit.exception.*;
+import org.punit.result.*;
+import org.punit.type.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
+
+public class ConcurrentTestMethodRunner extends AbstractTestMethodRunner {
+ TestMethodThread[] _threads;
+
+ ConcurrentException _concurrentException = new ConcurrentException();
+
+ public ConcurrentTestMethodRunner(Watcher[] watchers) {
+ super(watchers);
+ }
+
+ protected void runImpl() throws Throwable {
+ startThreads();
+ joinThreads();
+ if(_concurrentException.size() > 0) {
+ throw _concurrentException;
+ }
+ }
+
+ private void startThreads() {
+ for (int i = 0; i < _threads.length; ++i) {
+ _threads[i].start();
+ }
+ }
+
+ private void joinThreads() {
+ for (int i = 0; i < _threads.length; ++i) {
+ try {
+ _threads[i].join();
+ } catch (InterruptedException e) {
+ _concurrentException.add(e);
+ }
+ }
+ }
+
+ /**
+ * @Override
+ */
+ protected void setUpBeforeWatchers() {
+ Concurrent concurrentTestInstance = (Concurrent) _testInstance;
+ int threadCount = concurrentTestInstance.concurrentCount();
+ _threads = new TestMethodThread[threadCount];
+ for (int i = 0; i < _threads.length; ++i) {
+ _threads[i] = new TestMethodThread();
+ }
+ }
+
+ private class TestMethodThread extends Thread {
+ // TODO: exception hanlding
+ public void run() {
+ try {
+ ReflectionUtil.invokeMethod(_method, _testInstance,
+ new Object[] {});
+ } catch (ReflectionException e) {
+ _concurrentException.add(e.getCause());
+ } catch (Throwable t) {
+ _concurrentException.add(t);
+ }
+ }
+ }
+}
Modified: trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,6 +1,6 @@
package org.punit.runner;
-import org.punit.*;
+import org.punit.result.*;
public class PUnitConcurrentRunner implements Runner {
Modified: trunk/punit/src/org/punit/runner/PUnitRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitRunner.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit/src/org/punit/runner/PUnitRunner.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,46 +1,49 @@
package org.punit.runner;
-import java.util.*;
+import java.lang.reflect.*;
-import org.punit.*;
-import org.punit.type.*;
-import org.punit.util.*;
+import org.punit.builder.*;
+import org.punit.result.*;
public class PUnitRunner implements Runner {
+ private TestSuiteBuilder _testSuiteBuiler;
+
+ private TestMethodBuilder _testMethodBuilder;
+
+ private TestMethodRunner _testMethodRunner;
- public TestResult run(Class clazz) {
- List testClasses = buildTestClasses(clazz);
- throw new UnsupportedOperationException();
+ public PUnitRunner() {
+ this(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder());
}
- protected List buildTestClasses(Class clazz) {
- List testClasses = new ArrayList();
- buildTestClasses(testClasses, clazz);
- return testClasses;
+ public PUnitRunner(TestSuiteBuilder testSuiteBuiler, TestMethodBuilder testMethodBuilder) {
+ _testSuiteBuiler = testSuiteBuiler;
+ _testMethodBuilder = testMethodBuilder;
}
- private void buildTestClasses(List testClasses, Class clazz) {
- if(isTestSuite(clazz)) {
- buildTestClassFromTestSuite(testClasses, clazz);
- } else {
- buildTestClassesFromClass(testClasses, clazz);
+ public TestResult run(Class clazz) {
+ Object[] testClasses = _testSuiteBuiler.buildTestClasses(clazz);
+ for (int i = 0; i < testClasses.length; ++i) {
+ runTestClass((Class)testClasses[i]);
}
+ throw new UnsupportedOperationException();
}
- private void buildTestClassFromTestSuite(List testClasses, Class clazz) {
- TestSuite testSuite = (TestSuite) ReflectionUtil.newInstance(clazz);
- Class[] suite = testSuite.suite();
- for(int i = 0; i < suite.length; ++i) {
- buildTestClasses(testClasses, suite[i]);
+ private void runTestClass(Class clazz) {
+ Object[] testMethods = buildTestMethod(clazz);
+ for(int i = 0; i < testMethods.length; ++i) {
+ Method method = (Method) testMethods[i];
+ runTestMethod(clazz, method);
}
- }
+ throw new UnsupportedOperationException();
+ }
- private void buildTestClassesFromClass(List testClasses, Class clazz) {
- testClasses.add(clazz);
+ private void runTestMethod(Class clazz, Method method) {
+
}
- private boolean isTestSuite(Class clazz) {
- return TestSuite.class.isAssignableFrom(clazz);
+ private Object[] buildTestMethod(Class testClass) {
+ return _testMethodBuilder.buildTestMethods(testClass);
}
}
Modified: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit/src/org/punit/runner/Runner.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,6 +1,7 @@
package org.punit.runner;
import org.punit.*;
+import org.punit.result.*;
public interface Runner {
public TestResult run(Class clazz);
Added: trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,22 @@
+package org.punit.runner;
+
+import org.punit.exception.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
+
+public class SoloTestMethodRunner extends AbstractTestMethodRunner {
+
+ public SoloTestMethodRunner(Watcher[] watchers) {
+ super(watchers);
+ }
+
+ protected void runImpl() throws Throwable {
+ try {
+ ReflectionUtil
+ .invokeMethod(_method, _testInstance, new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+
+}
Added: trunk/punit/src/org/punit/runner/TestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/TestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/TestMethodRunner.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,14 @@
+package org.punit.runner;
+
+import java.lang.reflect.*;
+
+public interface TestMethodRunner {
+ /**
+ * Runs the test method, and returns the watcher values.
+ * @param clazz
+ * @param method
+ * @return
+ */
+ public Object[] run(Class clazz, Method method) throws Throwable;
+
+}
Added: trunk/punit/src/org/punit/type/Comparable.java
===================================================================
--- trunk/punit/src/org/punit/type/Comparable.java (rev 0)
+++ trunk/punit/src/org/punit/type/Comparable.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,17 @@
+package org.punit.type;
+
+public interface Comparable {
+ /**
+ * returns an id of the test scenario. It may be possible that several tests
+ * return the same id, which means they are competing against the same
+ * scenario.
+ * @return id
+ */
+ public int id();
+
+ /**
+ * Returns the name of this test.
+ * @return
+ */
+ public String name();
+}
Deleted: trunk/punit/src/org/punit/type/Competitive.java
===================================================================
--- trunk/punit/src/org/punit/type/Competitive.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit/src/org/punit/type/Competitive.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,6 +0,0 @@
-package org.punit.type;
-
-public interface Competitive {
- public Class testInterface();
- public Class[] implmentators();
-}
Modified: trunk/punit/src/org/punit/type/Test.java
===================================================================
--- trunk/punit/src/org/punit/type/Test.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit/src/org/punit/type/Test.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -3,7 +3,11 @@
public interface Test {
public void setUpBeforeWatchers();
+
+ public void setUpAfterWatchers();
+ public void tearDownBeforeWatchers();
+
public void tearDownAfterWatchers();
}
Added: trunk/punit/src/org/punit/type/Version.java
===================================================================
--- trunk/punit/src/org/punit/type/Version.java (rev 0)
+++ trunk/punit/src/org/punit/type/Version.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,21 @@
+package org.punit.type;
+
+public class Version {
+
+ private String _resourcePath;
+
+ private String _versionName;
+
+ public Version(String path, String name) {
+ _resourcePath = path;
+ _versionName = name;
+ }
+
+ public String resourcePath() {
+ return _resourcePath;
+ }
+
+ public String versionName() {
+ return _versionName;
+ }
+}
Added: trunk/punit/src/org/punit/type/VersionCompetitive.java
===================================================================
--- trunk/punit/src/org/punit/type/VersionCompetitive.java (rev 0)
+++ trunk/punit/src/org/punit/type/VersionCompetitive.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface VersionCompetitive {
+ public Version[] versions();
+}
Modified: trunk/punit/src/org/punit/util/ReflectionUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -5,6 +5,7 @@
import org.punit.exception.*;
public class ReflectionUtil {
+
public static Object newInstance(Class clazz) {
try {
Constructor constructor = clazz.getDeclaredConstructor(new Class[] {});
@@ -14,4 +15,39 @@
throw new ReflectionException(e);
}
}
+
+ public static Method getMethod(Class clazz, String methodName, Class[] params) {
+ try {
+ return clazz.getDeclaredMethod(methodName, params);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ public static Object invokeMethod(Method method, Object instance, Object[] params) throws ReflectionException {
+ try {
+ return method.invoke(instance, params);
+ } catch (IllegalArgumentException e) {
+ throw new ReflectionException(e);
+ } catch (IllegalAccessException e) {
+ throw new ReflectionException(e);
+ } catch (InvocationTargetException e) {
+ throw new ReflectionException(e.getTargetException());
+ }
+ }
+
+ public static boolean isPublic(Method method) {
+ int modifier = method.getModifiers();
+ return isBitSet(modifier, Modifier.PUBLIC);
+ }
+
+ public static boolean isStatic(Method method) {
+ int modifier = method.getModifiers();
+ return isBitSet(modifier, Modifier.STATIC);
+ }
+
+ private static boolean isBitSet(int value, int expectedBit) {
+ return (value & expectedBit) != 0;
+
+ }
}
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,15 +1,20 @@
package tests.api.org.punit.all;
import junit.framework.*;
+import tests.api.org.punit.builder.*;
import tests.api.org.punit.runner.*;
+import tests.api.org.punit.util.*;
import tests.api.org.punit.watcher.*;
public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("Test for tests.api.org.punit");
//$JUnit-BEGIN$
+ suite.addTestSuite(MemoryWatcherTest.class);
suite.addTestSuite(PUnitRunnerTest.class);
- suite.addTestSuite(MemoryWatcherTest.class);
+ suite.addTestSuite(PUnitTestMethodBuilderTest.class);
+ suite.addTestSuite(PUnitTestSuiteBuilderTest.class);
+ suite.addTestSuite(ReflectionUtilTest.class);
suite.addTestSuite(TimeWatcherTest.class);
//$JUnit-END$
return suite;
Added: trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,65 @@
+package tests.api.org.punit.builder;
+
+import java.lang.reflect.*;
+
+import junit.framework.*;
+
+import org.punit.builder.*;
+import org.punit.type.*;
+
+import tests.util.*;
+
+public class PUnitTestMethodBuilderTest extends TestCase {
+ private PUnitTestMethodBuilder _testMethodBuidler;
+
+ protected void setUp() throws Exception {
+ _testMethodBuidler = new PUnitTestMethodBuilder();
+ }
+
+ public void testBuildTestMethods1() {
+ Object[] methods = _testMethodBuidler.buildTestMethods(Test1.class);
+ String[] names = toMethodNameArray(methods);
+ AssertUtil.assertArrayContent(names, new String[] { "test1", "test2", "testa", "testb" });
+ }
+
+ public void testBuildTestMethods2() {
+ Object[] methods = _testMethodBuidler.buildTestMethods(Test2.class);
+ String[] names = toMethodNameArray(methods);
+ AssertUtil.assertArrayContent(names, new String[] { "test1", "test2", "testa", "testb" });
+ }
+
+ public void testBuildTestMethods3() {
+ Object[] methods = _testMethodBuidler.buildTestMethods(Test3.class);
+ String[] names = toMethodNameArray(methods);
+ AssertUtil.assertArray(names, new String[] { "test1", "test2", "testa", "testb" });
+ }
+
+ private String[] toMethodNameArray(Object[] methods) {
+ String[] names = new String [methods.length];
+ for(int i = 0; i < methods.length; ++i) {
+ names[i] = ((Method)methods[i]).getName();
+ }
+ return names;
+ }
+
+ private static class Test1 {
+ public void test1() {}
+ public void test2() {}
+ public void testa() {}
+ public void testb() {}
+ }
+
+ private static class Test2 {
+ public void test2() {}
+ public void test1() {}
+ public void testb() {}
+ public void testa() {}
+ }
+
+ private static class Test3 implements Alphabetical {
+ public void test2() {}
+ public void test1() {}
+ public void testb() {}
+ public void testa() {}
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestSuiteBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestSuiteBuilderTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestSuiteBuilderTest.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -0,0 +1,70 @@
+package tests.api.org.punit.builder;
+
+import junit.framework.*;
+
+import org.punit.builder.*;
+
+import tests.util.*;
+
+public class PUnitTestSuiteBuilderTest extends TestCase {
+ private PUnitTestSuiteBuilder _testSuiteBuidler;
+
+ protected void setUp() throws Exception {
+ _testSuiteBuidler = new PUnitTestSuiteBuilder();
+ }
+
+ public void testBuildTestClasses1() {
+ Object[] classes = _testSuiteBuidler.buildTestClasses(Test1.class);
+ AssertUtil.assertArray(classes, new Class[] { Test1.class });
+ }
+
+ public void testBuildTestClasses2() {
+ Object[] classes = _testSuiteBuidler.buildTestClasses(MorkTestSuite1.class);
+ AssertUtil.assertArray(classes, new Class[] { Test1.class,
+ Test2.class, Test3.class });
+ }
+
+ public void testBuildTestClasses3() {
+ Object[] classes = _testSuiteBuidler.buildTestClasses(MorkTestSuite2.class);
+ AssertUtil.assertArray(classes, new Class[] { Test4.class,
+ Test1.class, Test2.class, Test3.class, Test5.class });
+ }
+
+ private static class MorkTestSuite1 implements org.punit.type.TestSuite {
+ public Class[] suite() {
+ return new Class[] { Test1.class, Test2.class, Test3.class,
+
+ };
+ }
+ }
+
+ private static class MorkTestSuite2 implements org.punit.type.TestSuite {
+ public Class[] suite() {
+ return new Class[] { Test4.class, MorkTestSuite1.class,
+ Test5.class,
+
+ };
+ }
+ }
+
+ private static class Test1 {
+
+ }
+
+ private static class Test2 {
+
+ }
+
+ private static class Test3 {
+
+ }
+
+ private static class Test4 {
+
+ }
+
+ private static class Test5 {
+
+ }
+
+}
Modified: trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java 2007-05-09 22:29:40 UTC (rev 11)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java 2007-05-10 16:22:27 UTC (rev 12)
@@ -1,78 +1,9 @@
package tests.api.org.punit.runner;
-import java.util.*;
-
import junit.framework.*;
-import org.punit.runner.*;
-
-import tests.util.*;
-
public class PUnitRunnerTest extends TestCase {
+ public void test() {
- private MockPUnitRunner _runner;
-
- protected void setUp() throws Exception {
- _runner = new MockPUnitRunner();
}
-
- public void testBuildTestClasses1() {
- List list = _runner.publicBuild...
[truncated message content] |
|
From: <zha...@us...> - 2007-05-10 17:59:06
|
Revision: 14
http://p-unit.svn.sourceforge.net/p-unit/?rev=14&view=rev
Author: zhanghuangzhu
Date: 2007-05-10 10:59:07 -0700 (Thu, 10 May 2007)
Log Message:
-----------
Andrew Zhang: continue to implement the runner.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/util/ReflectionUtil.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java
Added Paths:
-----------
trunk/punit/src/org/punit/exception/ConcurrentException.java
trunk/punit/src/org/punit/type/PUnitTest.java
trunk/punit/src/org/punit/util/Visitor.java
trunk/punit/src/org/punit/util/VisitorUtil.java
trunk/punit.test/src/tests/api/org/punit/exception/
trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java
Removed Paths:
-------------
trunk/punit/src/org/punit/result/ConcurrentException.java
trunk/punit/src/org/punit/type/Test.java
Copied: trunk/punit/src/org/punit/exception/ConcurrentException.java (from rev 12, trunk/punit/src/org/punit/result/ConcurrentException.java)
===================================================================
--- trunk/punit/src/org/punit/exception/ConcurrentException.java (rev 0)
+++ trunk/punit/src/org/punit/exception/ConcurrentException.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -0,0 +1,35 @@
+package org.punit.exception;
+
+import java.util.*;
+
+import org.punit.util.*;
+
+public class ConcurrentException extends RuntimeException {
+ private static final long serialVersionUID = 1253114975237734895L;
+
+ private Vector _throwables = new Vector();
+
+ public void add(Throwable t) {
+ _throwables.add(t);
+ }
+
+ public int size() {
+ return _throwables.size();
+ }
+
+ public String getMessage() {
+ GetMessageVisitor visitor = new GetMessageVisitor();
+ VisitorUtil.traverse(_throwables.iterator(), visitor);
+ return visitor.sb.toString();
+ }
+
+ static class GetMessageVisitor implements Visitor {
+ final StringBuffer sb = new StringBuffer();
+
+ public void visit(Object obj) {
+ sb.append(((Throwable) obj));
+ sb.append("\n");
+ }
+
+ }
+}
Deleted: trunk/punit/src/org/punit/result/ConcurrentException.java
===================================================================
--- trunk/punit/src/org/punit/result/ConcurrentException.java 2007-05-10 16:53:45 UTC (rev 13)
+++ trunk/punit/src/org/punit/result/ConcurrentException.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -1,13 +0,0 @@
-package org.punit.result;
-
-import java.util.*;
-
-public class ConcurrentException extends RuntimeException {
- private Vector _throwables;
- public void add(Throwable t) {
- _throwables.add(t);
- }
- public int size() {
- return _throwables.size();
- }
-}
Modified: trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java 2007-05-10 16:53:45 UTC (rev 13)
+++ trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -3,6 +3,7 @@
import java.lang.reflect.*;
import org.punit.exception.*;
+import org.punit.type.*;
import org.punit.util.*;
import org.punit.watcher.*;
@@ -27,13 +28,14 @@
public Object[] run(Class clazz, Method method) throws Throwable {
try {
init(clazz, method);
- setUp();
setUpBeforeWatchers();
startWatchers();
+ setUpAfterWatchers();
runImpl();
} finally {
+ tearDownBeforeWatchers();
stopWatchers();
- tearDown();
+ tearDownAfterWatchers();
}
return watchersValues();
}
@@ -45,22 +47,42 @@
_class = clazz;
_method = method;
_method.setAccessible(true);
+ _setUpMethod = ReflectionUtil.getMethodAndSetAccessible(_testInstance
+ .getClass(), "setUp", new Class[] {});
+ _tearDownMethod = ReflectionUtil.getMethodAndSetAccessible(
+ _testInstance.getClass(), "tearDown", new Class[] {});
}
- /**
- * Subclass could override this method to do some custom setup before
- * watchers start.
- *
- */
- protected void setUpBeforeWatchers() {
+ private void setUpBeforeWatchers() {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).setUpBeforeWatchers();
+ }
+ }
+ private void setUpAfterWatchers() throws Throwable {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).setUpAfterWatchers();
+ } else {
+ setUp();
+ }
}
- protected void setUp() throws Throwable {
- _setUpMethod = ReflectionUtil.getMethod(_testInstance.getClass(),
- "setUp", new Class[] {});
+ private void tearDownBeforeWatchers() throws Throwable {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).tearDownBeforeWatchers();
+ } else {
+ tearDown();
+ }
+ }
+
+ private void tearDownAfterWatchers() {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).tearDownAfterWatchers();
+ }
+ }
+
+ private void setUp() throws Throwable {
if (_setUpMethod != null) {
- _setUpMethod.setAccessible(true);
try {
ReflectionUtil.invokeMethod(_setUpMethod, _testInstance,
new Object[] {});
@@ -70,11 +92,8 @@
}
}
- protected void tearDown() throws Throwable {
- _tearDownMethod = ReflectionUtil.getMethod(_testInstance.getClass(),
- "tearDown", new Class[] {});
+ private void tearDown() throws Throwable {
if (_tearDownMethod != null) {
- _tearDownMethod.setAccessible(true);
try {
ReflectionUtil.invokeMethod(_tearDownMethod, _testInstance,
new Object[] {});
@@ -103,4 +122,8 @@
}
return values;
}
+
+ private boolean isPUnitTest() {
+ return PUnitTest.class.isAssignableFrom(_class);
+ }
}
Copied: trunk/punit/src/org/punit/type/PUnitTest.java (from rev 12, trunk/punit/src/org/punit/type/Test.java)
===================================================================
--- trunk/punit/src/org/punit/type/PUnitTest.java (rev 0)
+++ trunk/punit/src/org/punit/type/PUnitTest.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -0,0 +1,13 @@
+package org.punit.type;
+
+public interface PUnitTest {
+
+ public void setUpBeforeWatchers();
+
+ public void setUpAfterWatchers();
+
+ public void tearDownBeforeWatchers();
+
+ public void tearDownAfterWatchers();
+
+}
Deleted: trunk/punit/src/org/punit/type/Test.java
===================================================================
--- trunk/punit/src/org/punit/type/Test.java 2007-05-10 16:53:45 UTC (rev 13)
+++ trunk/punit/src/org/punit/type/Test.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -1,13 +0,0 @@
-package org.punit.type;
-
-public interface Test {
-
- public void setUpBeforeWatchers();
-
- public void setUpAfterWatchers();
-
- public void tearDownBeforeWatchers();
-
- public void tearDownAfterWatchers();
-
-}
Modified: trunk/punit/src/org/punit/util/ReflectionUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-05-10 16:53:45 UTC (rev 13)
+++ trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -18,12 +18,30 @@
public static Method getMethod(Class clazz, String methodName, Class[] params) {
try {
- return clazz.getDeclaredMethod(methodName, params);
+ Method method = clazz.getDeclaredMethod(methodName, params);
+ return method;
} catch (Exception e) {
return null;
}
}
+ /**
+ * Gets the method and sets the accessible to true
+ * @param clazz
+ * @param methodName
+ * @param params
+ * @return
+ */
+ public static Method getMethodAndSetAccessible(Class clazz, String methodName, Class[] params) {
+ try {
+ Method method = clazz.getDeclaredMethod(methodName, params);
+ method.setAccessible(true);
+ return method;
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
public static Object invokeMethod(Method method, Object instance, Object[] params) throws ReflectionException {
try {
return method.invoke(instance, params);
Added: trunk/punit/src/org/punit/util/Visitor.java
===================================================================
--- trunk/punit/src/org/punit/util/Visitor.java (rev 0)
+++ trunk/punit/src/org/punit/util/Visitor.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -0,0 +1,5 @@
+package org.punit.util;
+
+public interface Visitor {
+ public void visit(Object obj);
+}
Added: trunk/punit/src/org/punit/util/VisitorUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/VisitorUtil.java (rev 0)
+++ trunk/punit/src/org/punit/util/VisitorUtil.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -0,0 +1,11 @@
+package org.punit.util;
+
+import java.util.*;
+
+public class VisitorUtil {
+ public static void traverse(Iterator iter, Visitor visitor) {
+ while (iter.hasNext()) {
+ visitor.visit(iter.next());
+ }
+ }
+}
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-10 16:53:45 UTC (rev 13)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -2,6 +2,7 @@
import junit.framework.*;
import tests.api.org.punit.builder.*;
+import tests.api.org.punit.exception.*;
import tests.api.org.punit.runner.*;
import tests.api.org.punit.util.*;
import tests.api.org.punit.watcher.*;
@@ -10,6 +11,7 @@
public static Test suite() {
TestSuite suite = new TestSuite("Test for tests.api.org.punit");
//$JUnit-BEGIN$
+ suite.addTestSuite(ConcurrentExceptionTest.class);
suite.addTestSuite(MemoryWatcherTest.class);
suite.addTestSuite(PUnitRunnerTest.class);
suite.addTestSuite(PUnitTestMethodBuilderTest.class);
Modified: trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java 2007-05-10 16:53:45 UTC (rev 13)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -19,47 +19,84 @@
public void testBuildTestMethods1() {
Object[] methods = _testMethodBuidler.buildTestMethods(Test1.class);
String[] names = toMethodNameArray(methods);
- AssertUtil.assertArrayContent(names, new String[] { "test1", "test2", "testa", "testb" });
+ AssertUtil.assertArrayContent(names, new String[] { "test1", "test2",
+ "testa", "testb" });
}
-
+
public void testBuildTestMethods2() {
Object[] methods = _testMethodBuidler.buildTestMethods(Test2.class);
String[] names = toMethodNameArray(methods);
- AssertUtil.assertArrayContent(names, new String[] { "test1", "test2", "testa", "testb" });
+ AssertUtil.assertArrayContent(names, new String[] { "test1", "test2",
+ "testa", "testb" });
}
public void testBuildTestMethods3() {
Object[] methods = _testMethodBuidler.buildTestMethods(Test3.class);
String[] names = toMethodNameArray(methods);
- AssertUtil.assertArray(names, new String[] { "test1", "test2", "testa", "testb" });
+ AssertUtil.assertArray(names, new String[] { "test1", "test2", "testa",
+ "testb" });
}
private String[] toMethodNameArray(Object[] methods) {
- String[] names = new String [methods.length];
- for(int i = 0; i < methods.length; ++i) {
- names[i] = ((Method)methods[i]).getName();
+ String[] names = new String[methods.length];
+ for (int i = 0; i < methods.length; ++i) {
+ names[i] = ((Method) methods[i]).getName();
}
return names;
}
private static class Test1 {
- public void test1() {}
- public void test2() {}
- public void testa() {}
- public void testb() {}
+ public void test1() {
+ }
+
+ public void test2() {
+ }
+
+ public void testa() {
+ }
+
+ public void testb() {
+ }
+
+ public void _testc() {
+ }
+
+ void testd() {
+ }
+
+ private void teste() {
+ }
+
+ public static void testf() {
+
+ }
}
private static class Test2 {
- public void test2() {}
- public void test1() {}
- public void testb() {}
- public void testa() {}
+ public void test2() {
+ }
+
+ public void test1() {
+ }
+
+ public void testb() {
+ }
+
+ public void testa() {
+ }
}
private static class Test3 implements Alphabetical {
- public void test2() {}
- public void test1() {}
- public void testb() {}
- public void testa() {}
+ public void test2() {
+ }
+
+ public void test1() {
+ }
+
+ public void testb() {
+ }
+
+ public void testa() {
+ }
}
}
Added: trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -0,0 +1,17 @@
+package tests.api.org.punit.exception;
+
+import org.punit.exception.*;
+
+import junit.framework.*;
+
+public class ConcurrentExceptionTest extends TestCase {
+ public void testGetMessage() {
+ ConcurrentException concurrentException = new ConcurrentException();
+ NullPointerException npe = new NullPointerException("NPE");
+ concurrentException.add(npe);
+ IllegalArgumentException iae = new IllegalArgumentException("IAE");
+ concurrentException.add(iae);
+ String message = concurrentException.getMessage();
+ assertEquals(npe + "\n" + iae + "\n", message);
+ }
+}
Modified: trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java 2007-05-10 16:53:45 UTC (rev 13)
+++ trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java 2007-05-10 17:59:07 UTC (rev 14)
@@ -30,10 +30,21 @@
method = ReflectionUtil.getMethod(Test1.class, "test2", new Class[] {});
assertNull(method);
- method = ReflectionUtil.getMethod(Test1.class, "test3", new Class[] {});
+ method = ReflectionUtil.getMethod(Test1.class, "test4", new Class[] {});
assertNull(method);
}
+ public void testGetMethodAndSetAccessible() {
+ Test1 obj = new Test1();
+ Method method = ReflectionUtil.getMethodAndSetAccessible(Test1.class,
+ "test1", new Class[] {});
+ ReflectionUtil.invokeMethod(method, obj, new Object[] {});
+
+ method = ReflectionUtil.getMethodAndSetAccessible(Test1.class,
+ "test3", new Class[] {});
+ ReflectionUtil.invokeMethod(method, obj, new Object[] {});
+ }
+
public void testInvokeMethod() {
final Test1 obj = new Test1();
final Method method = ReflectionUtil.getMethod(Test1.class, "test1",
@@ -111,6 +122,10 @@
private void test2(int i) {
value = i;
}
+
+ public void test3() {
+
+ }
}
private static class Test2 {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-10 21:50:12
|
Revision: 15
http://p-unit.svn.sourceforge.net/p-unit/?rev=15&view=rev
Author: zhanghuangzhu
Date: 2007-05-10 14:50:13 -0700 (Thu, 10 May 2007)
Log Message:
-----------
Andrew Zhang: continue to implement the runner.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java
trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java
trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java
trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java
trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java
trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java
trunk/punit.test/src/tests/sample/testcase/VMTestSample.java
trunk/punit.test/src/tests/sample/testcase/VersionCompetitiveTestSample.java
Added Paths:
-----------
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentTestClass.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitTestClass.java
trunk/punit.test/src/tests/api/org/punit/runner/TestClass.java
trunk/punit.test/src/tests/api/org/punit/runner/TestSuiteClass.java
trunk/punit.test/src/tests/sample/testcase/PUnitTestCaseSample.java
Removed Paths:
-------------
trunk/punit/src/org/punit/runner/PUnitRunner.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java
Modified: trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -9,7 +9,7 @@
public abstract class AbstractTestMethodRunner implements TestMethodRunner {
- protected final Watcher[] _watchers;
+ protected Watcher[] _watchers;
protected Object _testInstance;
@@ -21,7 +21,11 @@
protected Method _setUpMethod;
- public AbstractTestMethodRunner(Watcher[] watchers) {
+ public AbstractTestMethodRunner() {
+ _watchers = new Watcher[] {new MemoryWatcher(), new TimeWatcher()};
+ }
+
+ public void install(Watcher[] watchers) {
_watchers = watchers;
}
@@ -53,7 +57,12 @@
_testInstance.getClass(), "tearDown", new Class[] {});
}
- private void setUpBeforeWatchers() {
+ /**
+ * This method might be overriden by subclass.
+ * The runner may do some more things during this step.
+ *
+ */
+ protected void setUpBeforeWatchers() {
if (isPUnitTest()) {
((PUnitTest) _testInstance).setUpBeforeWatchers();
}
Modified: trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -1,18 +1,16 @@
package org.punit.runner;
import org.punit.exception.*;
-import org.punit.result.*;
import org.punit.type.*;
import org.punit.util.*;
-import org.punit.watcher.*;
public class ConcurrentTestMethodRunner extends AbstractTestMethodRunner {
TestMethodThread[] _threads;
ConcurrentException _concurrentException = new ConcurrentException();
- public ConcurrentTestMethodRunner(Watcher[] watchers) {
- super(watchers);
+ public ConcurrentTestMethodRunner() {
+
}
protected void runImpl() throws Throwable {
@@ -39,10 +37,8 @@
}
}
- /**
- * @Override
- */
protected void setUpBeforeWatchers() {
+ super.setUpBeforeWatchers();
Concurrent concurrentTestInstance = (Concurrent) _testInstance;
int threadCount = concurrentTestInstance.concurrentCount();
_threads = new TestMethodThread[threadCount];
Copied: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java (from rev 12, trunk/punit/src/org/punit/runner/PUnitRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,56 @@
+package org.punit.runner;
+
+import java.lang.reflect.*;
+
+import org.punit.builder.*;
+import org.punit.result.*;
+
+public abstract class PUnitAbstractRunner implements Runner {
+ private TestSuiteBuilder _testSuiteBuiler;
+
+ private TestMethodBuilder _testMethodBuilder;
+
+ private TestMethodRunner _testMethodRunner;
+
+ public PUnitAbstractRunner(TestSuiteBuilder testSuiteBuiler, TestMethodBuilder testMethodBuilder, TestMethodRunner testMethodRunner) {
+ _testSuiteBuiler = testSuiteBuiler;
+ _testMethodBuilder = testMethodBuilder;
+ _testMethodRunner = testMethodRunner;
+ }
+
+ public TestResult run(Class clazz) {
+ Object[] testClasses = _testSuiteBuiler.buildTestClasses(clazz);
+ for (int i = 0; i < testClasses.length; ++i) {
+ runTestClass((Class)testClasses[i]);
+ }
+ return null;
+ }
+
+ private void runTestClass(Class clazz) {
+ if(!accept(clazz)) {
+ return;
+ }
+ Object[] testMethods = buildTestMethod(clazz);
+ for(int i = 0; i < testMethods.length; ++i) {
+ Method method = (Method) testMethods[i];
+ runTestMethod(clazz, method);
+ }
+ }
+
+ private void runTestMethod(Class clazz, Method method) {
+ // TODO: add run result to the test result
+ try {
+ _testMethodRunner.run(clazz, method);
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ private Object[] buildTestMethod(Class testClass) {
+ return _testMethodBuilder.buildTestMethods(testClass);
+ }
+
+ public abstract boolean accept(Class testCaseClass);
+
+}
Modified: trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -1,11 +1,16 @@
package org.punit.runner;
-import org.punit.result.*;
+import org.punit.builder.*;
+import org.punit.type.*;
-public class PUnitConcurrentRunner implements Runner {
+public class PUnitConcurrentRunner extends PUnitAbstractRunner {
- public TestResult run(Class clazz) {
- throw new UnsupportedOperationException();
+ public PUnitConcurrentRunner() {
+ super(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder(), new ConcurrentTestMethodRunner());
}
+ public boolean accept(Class clazz) {
+ return Concurrent.class.isAssignableFrom(clazz);
+ }
+
}
Deleted: trunk/punit/src/org/punit/runner/PUnitRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitRunner.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit/src/org/punit/runner/PUnitRunner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -1,49 +0,0 @@
-package org.punit.runner;
-
-import java.lang.reflect.*;
-
-import org.punit.builder.*;
-import org.punit.result.*;
-
-public class PUnitRunner implements Runner {
- private TestSuiteBuilder _testSuiteBuiler;
-
- private TestMethodBuilder _testMethodBuilder;
-
- private TestMethodRunner _testMethodRunner;
-
- public PUnitRunner() {
- this(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder());
- }
-
- public PUnitRunner(TestSuiteBuilder testSuiteBuiler, TestMethodBuilder testMethodBuilder) {
- _testSuiteBuiler = testSuiteBuiler;
- _testMethodBuilder = testMethodBuilder;
- }
-
- public TestResult run(Class clazz) {
- Object[] testClasses = _testSuiteBuiler.buildTestClasses(clazz);
- for (int i = 0; i < testClasses.length; ++i) {
- runTestClass((Class)testClasses[i]);
- }
- throw new UnsupportedOperationException();
- }
-
- private void runTestClass(Class clazz) {
- Object[] testMethods = buildTestMethod(clazz);
- for(int i = 0; i < testMethods.length; ++i) {
- Method method = (Method) testMethods[i];
- runTestMethod(clazz, method);
- }
- throw new UnsupportedOperationException();
- }
-
- private void runTestMethod(Class clazz, Method method) {
-
- }
-
- private Object[] buildTestMethod(Class testClass) {
- return _testMethodBuilder.buildTestMethods(testClass);
- }
-
-}
Added: trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitSoloRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,16 @@
+package org.punit.runner;
+
+import org.punit.builder.*;
+
+public class PUnitSoloRunner extends PUnitAbstractRunner {
+
+ public PUnitSoloRunner() {
+ super(new PUnitTestSuiteBuilder(), new PUnitTestMethodBuilder(), new SoloTestMethodRunner());
+
+ }
+
+ public boolean accept(Class clazz) {
+ return true;
+ }
+
+}
Modified: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit/src/org/punit/runner/Runner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -1,6 +1,5 @@
package org.punit.runner;
-import org.punit.*;
import org.punit.result.*;
public interface Runner {
Modified: trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -2,12 +2,11 @@
import org.punit.exception.*;
import org.punit.util.*;
-import org.punit.watcher.*;
public class SoloTestMethodRunner extends AbstractTestMethodRunner {
- public SoloTestMethodRunner(Watcher[] watchers) {
- super(watchers);
+ public SoloTestMethodRunner() {
+
}
protected void runImpl() throws Throwable {
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -13,7 +13,8 @@
//$JUnit-BEGIN$
suite.addTestSuite(ConcurrentExceptionTest.class);
suite.addTestSuite(MemoryWatcherTest.class);
- suite.addTestSuite(PUnitRunnerTest.class);
+ suite.addTestSuite(PUnitConcurrentRunnerTest.class);
+ suite.addTestSuite(PUnitSoloRunnerTest.class);
suite.addTestSuite(PUnitTestMethodBuilderTest.class);
suite.addTestSuite(PUnitTestSuiteBuilderTest.class);
suite.addTestSuite(ReflectionUtilTest.class);
Added: trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentTestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/ConcurrentTestClass.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,20 @@
+package tests.api.org.punit.runner;
+
+import org.punit.type.*;
+
+public class ConcurrentTestClass implements Concurrent {
+
+ public static int value = 0;
+
+ public static void reset() {
+ value = 0;
+ }
+
+ public synchronized void test() {
+ ++value;
+ }
+
+ public int concurrentCount() {
+ return 5;
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentRunnerTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentRunnerTest.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,64 @@
+package tests.api.org.punit.runner;
+
+import org.punit.runner.*;
+
+import junit.framework.*;
+
+public class PUnitConcurrentRunnerTest extends TestCase {
+ private PUnitConcurrentRunner _runner;
+
+ protected void setUp() throws Exception {
+ _runner = new PUnitConcurrentRunner();
+ }
+
+ public void testRunConcurrent() {
+ ConcurrentTestClass.reset();
+ _runner.run(ConcurrentTestClass.class);
+ assertConcurrentTestClassRun();
+ }
+
+ public void testRunTest() {
+ TestClass.reset();
+ _runner.run(TestClass.class);
+ assertTestClassNotRun();
+ }
+
+ public void testRunPUnitTest() {
+ PUnitTestClass.reset();
+ _runner.run(PUnitTestClass.class);
+ assertPUnitTestNotRun();
+ }
+
+ public void testRunTestSuite() {
+ ConcurrentTestClass.reset();
+ TestClass.reset();
+ PUnitTestClass.reset();
+ _runner.run(TestSuiteClass.class);
+ assertConcurrentTestClassRun();
+ assertTestClassNotRun();
+ assertPUnitTestNotRun();
+ }
+
+ private void assertPUnitTestNotRun() {
+ assertFalse(PUnitTestClass._test1);
+ assertFalse(PUnitTestClass._test2);
+ assertFalse(PUnitTestClass._setUp);
+ assertFalse(PUnitTestClass._tearDown);
+ assertFalse(PUnitTestClass._setUpBeforeWatchers);
+ assertFalse(PUnitTestClass._setUpAfterWatchers);
+ assertFalse(PUnitTestClass._tearDownBeforeWatchers);
+ assertFalse(PUnitTestClass._tearDownAfterWatchers);
+ }
+
+ private void assertConcurrentTestClassRun() {
+ ConcurrentTestClass test = new ConcurrentTestClass();
+ assertEquals(test.concurrentCount(), ConcurrentTestClass.value);
+ }
+
+ private void assertTestClassNotRun() {
+ assertFalse(TestClass._test1);
+ assertFalse(TestClass._test2);
+ assertFalse(TestClass._setUp);
+ assertFalse(TestClass._tearDown);
+ }
+}
Deleted: trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -1,9 +0,0 @@
-package tests.api.org.punit.runner;
-
-import junit.framework.*;
-
-public class PUnitRunnerTest extends TestCase {
- public void test() {
-
- }
-}
Copied: trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloRunnerTest.java (from rev 12, trunk/punit.test/src/tests/api/org/punit/runner/PUnitRunnerTest.java)
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloRunnerTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloRunnerTest.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,62 @@
+package tests.api.org.punit.runner;
+
+import org.punit.runner.*;
+
+import junit.framework.*;
+
+public class PUnitSoloRunnerTest extends TestCase {
+ private PUnitSoloRunner _runner;
+
+ protected void setUp() throws Exception {
+ _runner = new PUnitSoloRunner();
+ }
+
+ public void testRunTest() {
+ TestClass.reset();
+ _runner.run(TestClass.class);
+ assertTestClassRun();
+ }
+
+ public void testRunPUnitTest() {
+ PUnitTestClass.reset();
+ assertPUnitTestClassRun();
+ }
+
+ public void testRunConcurrent() {
+ ConcurrentTestClass.reset();
+ _runner.run(ConcurrentTestClass.class);
+ assertConcurrentTestClassRun();
+ }
+
+
+ public void testRunTestSuite() {
+ TestClass.reset();
+ PUnitTestClass.reset();
+ _runner.run(TestSuiteClass.class);
+ assertTestClassRun();
+ assertPUnitTestClassRun();
+ }
+
+ private void assertTestClassRun() {
+ assertFalse(TestClass._test1);
+ assertTrue(TestClass._test2);
+ assertTrue(TestClass._setUp);
+ assertTrue(TestClass._tearDown);
+ }
+
+ private void assertPUnitTestClassRun() {
+ _runner.run(PUnitTestClass.class);
+ assertFalse(PUnitTestClass._test1);
+ assertTrue(PUnitTestClass._test2);
+ assertFalse(PUnitTestClass._setUp);
+ assertFalse(PUnitTestClass._tearDown);
+ assertTrue(PUnitTestClass._setUpBeforeWatchers);
+ assertTrue(PUnitTestClass._setUpAfterWatchers);
+ assertTrue(PUnitTestClass._tearDownBeforeWatchers);
+ assertTrue(PUnitTestClass._tearDownAfterWatchers);
+ }
+
+ private void assertConcurrentTestClassRun() {
+ assertEquals(1, ConcurrentTestClass.value);
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/runner/PUnitTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitTestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitTestClass.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,65 @@
+package tests.api.org.punit.runner;
+
+import org.punit.type.*;
+
+public class PUnitTestClass implements PUnitTest {
+ public static boolean _test1;
+
+ public static boolean _test2;
+
+ public static boolean _setUp;
+
+ public static boolean _tearDown;
+
+ public static boolean _setUpAfterWatchers;
+
+ public static boolean _setUpBeforeWatchers;
+
+ public static boolean _tearDownAfterWatchers;
+
+ public static boolean _tearDownBeforeWatchers;
+
+ public static void reset() {
+ _test1 = false;
+ _test2 = false;
+ _setUp = false;
+ _tearDown = false;
+ _setUpAfterWatchers = false;
+ _setUpBeforeWatchers = false;
+ _tearDownAfterWatchers = false;
+ _tearDownBeforeWatchers = false;
+
+ }
+
+ private void setUp() {
+ _setUp = true;
+ }
+
+ private void tearDown() {
+ _tearDown = true;
+ }
+
+ private void test1() {
+ _test1 = true;
+ }
+
+ public void test2() {
+ _test2 = true;
+ }
+
+ public void setUpAfterWatchers() {
+ _setUpAfterWatchers = true;
+ }
+
+ public void setUpBeforeWatchers() {
+ _setUpBeforeWatchers = true;
+ }
+
+ public void tearDownAfterWatchers() {
+ _tearDownAfterWatchers = true;
+ }
+
+ public void tearDownBeforeWatchers() {
+ _tearDownBeforeWatchers = true;
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/runner/TestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/TestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/TestClass.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,35 @@
+package tests.api.org.punit.runner;
+
+public class TestClass {
+ public static boolean _test1;
+
+ public static boolean _test2;
+
+ public static boolean _setUp;
+
+ public static boolean _tearDown;
+
+ public static void reset() {
+ _test1 = false;
+ _test2 = false;
+ _setUp = false;
+ _tearDown = false;
+ }
+
+
+ private void setUp() {
+ _setUp = true;
+ }
+
+ private void tearDown() {
+ _tearDown = true;
+ }
+
+ private void test1() {
+ _test1 = true;
+ }
+
+ public void test2() {
+ _test2 = true;
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/runner/TestSuiteClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/TestSuiteClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/TestSuiteClass.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,14 @@
+package tests.api.org.punit.runner;
+
+import org.punit.type.*;
+
+public class TestSuiteClass implements TestSuite {
+
+ public Class[] suite() {
+ return new Class[] {
+ TestClass.class,
+ PUnitTestClass.class,
+ ConcurrentTestClass.class,
+ };
+ }
+}
Modified: trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -6,7 +6,7 @@
public class ConcurrentTestSample implements Concurrent {
public static void main(String[] args) {
- new PUnitRunner().run(ConcurrentTestSample.class);
+ new PUnitConcurrentRunner().run(ConcurrentTestSample.class);
}
public void test1() {
Modified: trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -7,9 +7,17 @@
public class JUnitTestSample extends TestCase {
public static void main(String[] args) {
- new PUnitRunner().run(JUnitTestSample.class);
+ new PUnitSoloRunner().run(JUnitTestSample.class);
}
+ public void setUp() {
+
+ }
+
+ public void tearDown() {
+
+ }
+
public void test1() {
}
@@ -17,5 +25,5 @@
public void test2() {
}
-
+
}
Added: trunk/punit.test/src/tests/sample/testcase/PUnitTestCaseSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/PUnitTestCaseSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/PUnitTestCaseSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -0,0 +1,40 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+public class PUnitTestCaseSample implements PUnitTest {
+
+ public static void main(String[] args) {
+ new PUnitSoloRunner().run(PUnitTestCaseSample.class);
+ }
+
+ public void setUpAfterWatchers() {
+ }
+
+ public void setUpBeforeWatchers() {
+ }
+
+ public void tearDownBeforeWatchers() {
+ }
+
+ public void tearDownAfterWatchers() {
+ }
+
+ public void setUp() {
+
+ }
+
+ public void tearDown() {
+
+ }
+
+ public void test1() {
+
+ }
+
+ public void test2() {
+
+ }
+
+}
Modified: trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -1,9 +1,20 @@
package tests.sample.testcase;
+import org.punit.runner.*;
import org.punit.type.*;
public class PUnitTestSuiteSample implements TestSuite {
+ public static void main(String[] args) {
+ new PUnitSoloRunner().run(PUnitTestSuiteSample.class);
+ new PUnitConcurrentRunner().run(PUnitTestSuiteSample.class);
+ }
+
public Class[] suite() {
- throw new UnsupportedOperationException();
+ return new Class[] {
+ ConcurrentTestSample.class,
+ JUnitTestSample.class,
+ SimpleTestSample.class,
+ PUnitTestCaseSample.class,
+ };
}
}
Modified: trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -6,7 +6,7 @@
public class ParameterizableTestSample implements Parameterizable {
public static void main(String[] args) {
- new PUnitRunner().run(ParameterizableTestSample.class);
+ new PUnitSoloRunner().run(ParameterizableTestSample.class);
}
public void test1() {
Modified: trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -5,9 +5,17 @@
public class SimpleTestSample {
public static void main(String[] args) {
- new PUnitRunner().run(SimpleTestSample.class);
+ new PUnitSoloRunner().run(SimpleTestSample.class);
}
+ public void setUp() {
+
+ }
+
+ public void tearDown() {
+
+ }
+
public void test1() {
}
Modified: trunk/punit.test/src/tests/sample/testcase/VMTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/VMTestSample.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/sample/testcase/VMTestSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -6,7 +6,7 @@
public class VMTestSample implements VMComparable {
public static void main(String[] args) {
- new PUnitRunner().run(VMTestSample.class);
+ new PUnitSoloRunner().run(VMTestSample.class);
}
public void test1() {
Modified: trunk/punit.test/src/tests/sample/testcase/VersionCompetitiveTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/VersionCompetitiveTestSample.java 2007-05-10 17:59:07 UTC (rev 14)
+++ trunk/punit.test/src/tests/sample/testcase/VersionCompetitiveTestSample.java 2007-05-10 21:50:13 UTC (rev 15)
@@ -6,7 +6,7 @@
public class VersionCompetitiveTestSample implements VersionCompetitive {
public static void main(String[] args) {
- new PUnitRunner().run(VersionCompetitiveTestSample.class);
+ new PUnitSoloRunner().run(VersionCompetitiveTestSample.class);
}
public void test1() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-11 09:18:12
|
Revision: 16
http://p-unit.svn.sourceforge.net/p-unit/?rev=16&view=rev
Author: zhanghuangzhu
Date: 2007-05-11 02:18:13 -0700 (Fri, 11 May 2007)
Log Message:
-----------
Andrew Zhang: Implemented PUnitSoloParameterizableRunner.
Modified Paths:
--------------
trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
trunk/punit/src/org/punit/type/Parameterizable.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestSuiteBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitTestClass.java
trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java
Added Paths:
-----------
trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java
trunk/punit/src/org/punit/builder/PUnitParameterizableTestMethodBuilder.java
trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java
trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java
trunk/punit/src/org/punit/runner/ParameterizableRunner.java
trunk/punit/src/org/punit/runner/testmethod/
trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java
trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java
trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java
trunk/punit/src/org/punit/runner/testmethod/TestMethodRunner.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitParameterizableTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloParameterizableRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/
trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestClass.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass2.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass3.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass4.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestClass5.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java
trunk/punit.test/src/tests/util/TestUtil.java
Removed Paths:
-------------
trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java
trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java
trunk/punit/src/org/punit/runner/TestMethodRunner.java
Added: trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java (rev 0)
+++ trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,40 @@
+package org.punit.builder;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+import org.punit.type.*;
+
+public abstract class PUnitAbstractTestMethodBuilder implements TestMethodBuilder {
+ public Object[] buildTestMethods(Class testClass) {
+ Method[] methods = testClass.getDeclaredMethods();
+ Collection testMethods;
+ if (isAlphabetical(testClass)) {
+ testMethods = new TreeSet(new AlphabeticalMethodNameComparator());
+ } else {
+ testMethods = new ArrayList();
+ }
+ for (int i = 0; i < methods.length; ++i) {
+ Method method = methods[i];
+ if (isTestMethod(method)) {
+ testMethods.add(method);
+ }
+ }
+ return testMethods.toArray();
+ }
+
+ private boolean isAlphabetical(Class testClass) {
+ return Alphabetical.class.isAssignableFrom(testClass);
+ }
+
+ protected abstract boolean isTestMethod(Method method);
+
+ private static class AlphabeticalMethodNameComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ Method m1 = (Method) o1;
+ Method m2 = (Method) o2;
+ return m1.getName().compareTo(m2.getName());
+ }
+ }
+
+}
Added: trunk/punit/src/org/punit/builder/PUnitParameterizableTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitParameterizableTestMethodBuilder.java (rev 0)
+++ trunk/punit/src/org/punit/builder/PUnitParameterizableTestMethodBuilder.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,30 @@
+package org.punit.builder;
+
+import java.lang.reflect.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class PUnitParameterizableTestMethodBuilder extends PUnitAbstractTestMethodBuilder {
+
+ /**
+ *
+ * Returns true if the method is public, not static, and has
+ * one Parameter argument and starts with "test",.
+ *
+ * @param method
+ * @return true if it is a test method
+ */
+ protected boolean isTestMethod(Method method) {
+ String name = method.getName();
+ return ReflectionUtil.isPublic(method)
+ && !ReflectionUtil.isStatic(method) && hasOnlyParameterParam(method)
+ && name.startsWith("test");
+ }
+
+ private boolean hasOnlyParameterParam(Method method) {
+ Class[] params = method.getParameterTypes();
+ return params.length == 1 && Parameter.class.isAssignableFrom(params[0]);
+ }
+
+}
Modified: trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,40 +1,17 @@
package org.punit.builder;
import java.lang.reflect.*;
-import java.util.*;
-import org.punit.type.*;
import org.punit.util.*;
-public class PUnitTestMethodBuilder implements TestMethodBuilder {
+public class PUnitTestMethodBuilder extends PUnitAbstractTestMethodBuilder {
- public Object[] buildTestMethods(Class testClass) {
- Method[] methods = testClass.getDeclaredMethods();
- Collection testMethods;
- if (isAlphabetical(testClass)) {
- testMethods = new TreeSet(new AlphabeticalMethodNameComparator());
- } else {
- testMethods = new ArrayList();
- }
- for (int i = 0; i < methods.length; ++i) {
- Method method = methods[i];
- if (isTestMethod(method)) {
- testMethods.add(method);
- }
- }
- return testMethods.toArray();
- }
-
- private boolean isAlphabetical(Class testClass) {
- return Alphabetical.class.isAssignableFrom(testClass);
- }
-
/**
* Returns true if this method is regarded as a test method. Might be
* overriden by the subclass for convenience.
*
- * By default, returns true if the method is public and not static, and
- * starts with "test".
+ * Returns true if the method is public, not static, and has
+ * zero argument and starts with "test",.
*
* @param method
* @return true if it is a test method
@@ -42,14 +19,11 @@
protected boolean isTestMethod(Method method) {
String name = method.getName();
return ReflectionUtil.isPublic(method)
- && !ReflectionUtil.isStatic(method) && name.startsWith("test");
+ && !ReflectionUtil.isStatic(method) && hasNoParam(method)
+ && name.startsWith("test");
}
- private static class AlphabeticalMethodNameComparator implements Comparator {
- public int compare(Object o1, Object o2) {
- Method m1 = (Method) o1;
- Method m2 = (Method) o2;
- return m1.getName().compareTo(m2.getName());
- }
+ private boolean hasNoParam(Method method) {
+ return method.getParameterTypes().length == 0;
}
}
Added: trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,19 @@
+package org.punit.runner;
+
+import org.punit.builder.*;
+import org.punit.runner.testmethod.*;
+import org.punit.type.*;
+
+public abstract class AbstractParameterizableRunner extends PUnitAbstractRunner implements ParameterizableRunner {
+
+ public AbstractParameterizableRunner(TestSuiteBuilder testSuiteBuiler,
+ TestMethodBuilder testMethodBuilder,
+ TestMethodRunner testMethodRunner) {
+ super(testSuiteBuiler, testMethodBuilder, testMethodRunner);
+ }
+
+ public boolean accept(Class clazz) {
+ return Parameterizable.class.isAssignableFrom(clazz);
+ }
+
+}
\ No newline at end of file
Deleted: trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,138 +0,0 @@
-package org.punit.runner;
-
-import java.lang.reflect.*;
-
-import org.punit.exception.*;
-import org.punit.type.*;
-import org.punit.util.*;
-import org.punit.watcher.*;
-
-public abstract class AbstractTestMethodRunner implements TestMethodRunner {
-
- protected Watcher[] _watchers;
-
- protected Object _testInstance;
-
- protected Method _method;
-
- protected Class _class;
-
- protected Method _tearDownMethod;
-
- protected Method _setUpMethod;
-
- public AbstractTestMethodRunner() {
- _watchers = new Watcher[] {new MemoryWatcher(), new TimeWatcher()};
- }
-
- public void install(Watcher[] watchers) {
- _watchers = watchers;
- }
-
- public Object[] run(Class clazz, Method method) throws Throwable {
- try {
- init(clazz, method);
- setUpBeforeWatchers();
- startWatchers();
- setUpAfterWatchers();
- runImpl();
- } finally {
- tearDownBeforeWatchers();
- stopWatchers();
- tearDownAfterWatchers();
- }
- return watchersValues();
- }
-
- protected abstract void runImpl() throws Throwable;
-
- protected final void init(Class clazz, Method method) {
- _testInstance = ReflectionUtil.newInstance(clazz);
- _class = clazz;
- _method = method;
- _method.setAccessible(true);
- _setUpMethod = ReflectionUtil.getMethodAndSetAccessible(_testInstance
- .getClass(), "setUp", new Class[] {});
- _tearDownMethod = ReflectionUtil.getMethodAndSetAccessible(
- _testInstance.getClass(), "tearDown", new Class[] {});
- }
-
- /**
- * This method might be overriden by subclass.
- * The runner may do some more things during this step.
- *
- */
- protected void setUpBeforeWatchers() {
- if (isPUnitTest()) {
- ((PUnitTest) _testInstance).setUpBeforeWatchers();
- }
- }
-
- private void setUpAfterWatchers() throws Throwable {
- if (isPUnitTest()) {
- ((PUnitTest) _testInstance).setUpAfterWatchers();
- } else {
- setUp();
- }
- }
-
- private void tearDownBeforeWatchers() throws Throwable {
- if (isPUnitTest()) {
- ((PUnitTest) _testInstance).tearDownBeforeWatchers();
- } else {
- tearDown();
- }
- }
-
- private void tearDownAfterWatchers() {
- if (isPUnitTest()) {
- ((PUnitTest) _testInstance).tearDownAfterWatchers();
- }
- }
-
- private void setUp() throws Throwable {
- if (_setUpMethod != null) {
- try {
- ReflectionUtil.invokeMethod(_setUpMethod, _testInstance,
- new Object[] {});
- } catch (ReflectionException e) {
- throw e.getCause();
- }
- }
- }
-
- private void tearDown() throws Throwable {
- if (_tearDownMethod != null) {
- try {
- ReflectionUtil.invokeMethod(_tearDownMethod, _testInstance,
- new Object[] {});
- } catch (ReflectionException e) {
- throw e.getCause();
- }
- }
- }
-
- protected final void startWatchers() {
- for (int i = 0; i < _watchers.length; ++i) {
- _watchers[i].start();
- }
- }
-
- protected final void stopWatchers() {
- for (int i = 0; i < _watchers.length; ++i) {
- _watchers[i].stop();
- }
- }
-
- protected final Object[] watchersValues() {
- Object[] values = new Object[_watchers.length];
- for (int i = 0; i < _watchers.length; ++i) {
- values[i] = _watchers[i].value();
- }
- return values;
- }
-
- private boolean isPUnitTest() {
- return PUnitTest.class.isAssignableFrom(_class);
- }
-}
Deleted: trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,63 +0,0 @@
-package org.punit.runner;
-
-import org.punit.exception.*;
-import org.punit.type.*;
-import org.punit.util.*;
-
-public class ConcurrentTestMethodRunner extends AbstractTestMethodRunner {
- TestMethodThread[] _threads;
-
- ConcurrentException _concurrentException = new ConcurrentException();
-
- public ConcurrentTestMethodRunner() {
-
- }
-
- protected void runImpl() throws Throwable {
- startThreads();
- joinThreads();
- if(_concurrentException.size() > 0) {
- throw _concurrentException;
- }
- }
-
- private void startThreads() {
- for (int i = 0; i < _threads.length; ++i) {
- _threads[i].start();
- }
- }
-
- private void joinThreads() {
- for (int i = 0; i < _threads.length; ++i) {
- try {
- _threads[i].join();
- } catch (InterruptedException e) {
- _concurrentException.add(e);
- }
- }
- }
-
- protected void setUpBeforeWatchers() {
- super.setUpBeforeWatchers();
- Concurrent concurrentTestInstance = (Concurrent) _testInstance;
- int threadCount = concurrentTestInstance.concurrentCount();
- _threads = new TestMethodThread[threadCount];
- for (int i = 0; i < _threads.length; ++i) {
- _threads[i] = new TestMethodThread();
- }
- }
-
- private class TestMethodThread extends Thread {
- // TODO: exception hanlding
- public void run() {
- try {
- ReflectionUtil.invokeMethod(_method, _testInstance,
- new Object[] {});
- } catch (ReflectionException e) {
- _concurrentException.add(e.getCause());
- } catch (Throwable t) {
- _concurrentException.add(t);
- }
- }
- }
-}
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -4,6 +4,9 @@
import org.punit.builder.*;
import org.punit.result.*;
+import org.punit.runner.testmethod.*;
+import org.punit.type.*;
+import org.punit.util.*;
public abstract class PUnitAbstractRunner implements Runner {
private TestSuiteBuilder _testSuiteBuiler;
@@ -39,14 +42,36 @@
private void runTestMethod(Class clazz, Method method) {
// TODO: add run result to the test result
+ Object testInstance = ReflectionUtil.newInstance(clazz);
try {
- _testMethodRunner.run(clazz, method);
+ if (needsRunParameterizable(clazz)) {
+ Parameterizable pInstance = (Parameterizable) testInstance;
+ Parameter[] params = pInstance.parameters();
+ for (int i = 0; i < params.length; ++i) {
+ _testMethodRunner.run(testInstance, method,
+ new Object[] { params[i] });
+ }
+ } else {
+ _testMethodRunner.run(testInstance, method, new Object[] {});
+ }
} catch (Throwable e) {
e.printStackTrace();
}
}
+ private boolean needsRunParameterizable(Class clazz) {
+ return isParameterizable(clazz) && isParameterizableRunner();
+ }
+
+ private boolean isParameterizableRunner() {
+ return (this instanceof ParameterizableRunner);
+ }
+
+ private boolean isParameterizable(Class clazz) {
+ return Parameterizable.class.isAssignableFrom(clazz);
+ }
+
private Object[] buildTestMethod(Class testClass) {
return _testMethodBuilder.buildTestMethods(testClass);
}
Modified: trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,6 +1,7 @@
package org.punit.runner;
import org.punit.builder.*;
+import org.punit.runner.testmethod.*;
import org.punit.type.*;
public class PUnitConcurrentRunner extends PUnitAbstractRunner {
Added: trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,14 @@
+package org.punit.runner;
+
+import org.punit.builder.*;
+import org.punit.runner.testmethod.*;
+import org.punit.type.*;
+
+public class PUnitSoloParameterizableRunner extends AbstractParameterizableRunner {
+
+ public PUnitSoloParameterizableRunner() {
+ super(new PUnitTestSuiteBuilder(), new PUnitParameterizableTestMethodBuilder(), new SoloParameterizableTestMethodRunner());
+ }
+
+
+}
Modified: trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,6 +1,7 @@
package org.punit.runner;
import org.punit.builder.*;
+import org.punit.runner.testmethod.*;
public class PUnitSoloRunner extends PUnitAbstractRunner {
Added: trunk/punit/src/org/punit/runner/ParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/ParameterizableRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/ParameterizableRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,5 @@
+package org.punit.runner;
+
+public interface ParameterizableRunner {
+
+}
Deleted: trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,21 +0,0 @@
-package org.punit.runner;
-
-import org.punit.exception.*;
-import org.punit.util.*;
-
-public class SoloTestMethodRunner extends AbstractTestMethodRunner {
-
- public SoloTestMethodRunner() {
-
- }
-
- protected void runImpl() throws Throwable {
- try {
- ReflectionUtil
- .invokeMethod(_method, _testInstance, new Object[] {});
- } catch (ReflectionException e) {
- throw e.getCause();
- }
- }
-
-}
Deleted: trunk/punit/src/org/punit/runner/TestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/TestMethodRunner.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/runner/TestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,14 +0,0 @@
-package org.punit.runner;
-
-import java.lang.reflect.*;
-
-public interface TestMethodRunner {
- /**
- * Runs the test method, and returns the watcher values.
- * @param clazz
- * @param method
- * @return
- */
- public Object[] run(Class clazz, Method method) throws Throwable;
-
-}
Copied: trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java (from rev 15, trunk/punit/src/org/punit/runner/AbstractTestMethodRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/testmethod/AbstractTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,141 @@
+package org.punit.runner.testmethod;
+
+import java.lang.reflect.*;
+
+import org.punit.exception.*;
+import org.punit.type.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
+
+public abstract class AbstractTestMethodRunner implements TestMethodRunner {
+
+ protected Watcher[] _watchers;
+
+ protected Object _testInstance;
+
+ protected Method _method;
+
+ protected Object[] _params;
+
+ protected Class _class;
+
+ protected Method _tearDownMethod;
+
+ protected Method _setUpMethod;
+
+ public AbstractTestMethodRunner() {
+ _watchers = new Watcher[] {new MemoryWatcher(), new TimeWatcher()};
+ }
+
+ public void install(Watcher[] watchers) {
+ _watchers = watchers;
+ }
+
+ public Object[] run(Object testInstance, Method method, Object[] params) throws Throwable {
+ try {
+ init(testInstance, method, params);
+ setUpBeforeWatchers();
+ startWatchers();
+ setUpAfterWatchers();
+ runImpl();
+ } finally {
+ tearDownBeforeWatchers();
+ stopWatchers();
+ tearDownAfterWatchers();
+ }
+ return watchersValues();
+ }
+
+ protected abstract void runImpl() throws Throwable;
+
+ protected final void init(Object testInstance, Method method, Object[] params) {
+ _testInstance = testInstance;
+ _class = testInstance.getClass();
+ _params = params;
+ _method = method;
+ _method.setAccessible(true);
+ _setUpMethod = ReflectionUtil.getMethodAndSetAccessible(_testInstance
+ .getClass(), "setUp", new Class[] {});
+ _tearDownMethod = ReflectionUtil.getMethodAndSetAccessible(
+ _testInstance.getClass(), "tearDown", new Class[] {});
+ }
+
+ /**
+ * This method might be overriden by subclass.
+ * The runner may do some more things during this step.
+ *
+ */
+ protected void setUpBeforeWatchers() {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).setUpBeforeWatchers();
+ }
+ }
+
+ private void setUpAfterWatchers() throws Throwable {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).setUpAfterWatchers();
+ } else {
+ setUp();
+ }
+ }
+
+ private void tearDownBeforeWatchers() throws Throwable {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).tearDownBeforeWatchers();
+ } else {
+ tearDown();
+ }
+ }
+
+ private void tearDownAfterWatchers() {
+ if (isPUnitTest()) {
+ ((PUnitTest) _testInstance).tearDownAfterWatchers();
+ }
+ }
+
+ private void setUp() throws Throwable {
+ if (_setUpMethod != null) {
+ try {
+ ReflectionUtil.invokeMethod(_setUpMethod, _testInstance,
+ new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+ }
+
+ private void tearDown() throws Throwable {
+ if (_tearDownMethod != null) {
+ try {
+ ReflectionUtil.invokeMethod(_tearDownMethod, _testInstance,
+ new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+ }
+
+ protected final void startWatchers() {
+ for (int i = 0; i < _watchers.length; ++i) {
+ _watchers[i].start();
+ }
+ }
+
+ protected final void stopWatchers() {
+ for (int i = 0; i < _watchers.length; ++i) {
+ _watchers[i].stop();
+ }
+ }
+
+ protected final Object[] watchersValues() {
+ Object[] values = new Object[_watchers.length];
+ for (int i = 0; i < _watchers.length; ++i) {
+ values[i] = _watchers[i].value();
+ }
+ return values;
+ }
+
+ private boolean isPUnitTest() {
+ return PUnitTest.class.isAssignableFrom(_class);
+ }
+}
Copied: trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java (from rev 15, trunk/punit/src/org/punit/runner/ConcurrentTestMethodRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,62 @@
+package org.punit.runner.testmethod;
+
+import org.punit.exception.*;
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class ConcurrentTestMethodRunner extends AbstractTestMethodRunner {
+ TestMethodThread[] _threads;
+
+ ConcurrentException _concurrentException = new ConcurrentException();
+
+ public ConcurrentTestMethodRunner() {
+
+ }
+
+ protected void runImpl() throws Throwable {
+ startThreads();
+ joinThreads();
+ if(_concurrentException.size() > 0) {
+ throw _concurrentException;
+ }
+ }
+
+ private void startThreads() {
+ for (int i = 0; i < _threads.length; ++i) {
+ _threads[i].start();
+ }
+ }
+
+ private void joinThreads() {
+ for (int i = 0; i < _threads.length; ++i) {
+ try {
+ _threads[i].join();
+ } catch (InterruptedException e) {
+ _concurrentException.add(e);
+ }
+ }
+ }
+
+ protected void setUpBeforeWatchers() {
+ super.setUpBeforeWatchers();
+ Concurrent concurrentTestInstance = (Concurrent) _testInstance;
+ int threadCount = concurrentTestInstance.concurrentCount();
+ _threads = new TestMethodThread[threadCount];
+ for (int i = 0; i < _threads.length; ++i) {
+ _threads[i] = new TestMethodThread();
+ }
+ }
+
+ private class TestMethodThread extends Thread {
+ // TODO: exception hanlding
+ public void run() {
+ try {
+ ReflectionUtil.invokeMethod(_method, _testInstance, _params);
+ } catch (ReflectionException e) {
+ _concurrentException.add(e.getCause());
+ } catch (Throwable t) {
+ _concurrentException.add(t);
+ }
+ }
+ }
+}
Added: trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,17 @@
+package org.punit.runner.testmethod;
+
+import org.punit.exception.*;
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class SoloParameterizableTestMethodRunner extends AbstractTestMethodRunner {
+
+ protected void runImpl() throws Throwable {
+ try {
+ ReflectionUtil.invokeMethod(_method, _testInstance, _params);
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+
+}
Copied: trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java (from rev 15, trunk/punit/src/org/punit/runner/SoloTestMethodRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,17 @@
+package org.punit.runner.testmethod;
+
+import org.punit.exception.*;
+import org.punit.util.*;
+
+public class SoloTestMethodRunner extends AbstractTestMethodRunner {
+
+ protected void runImpl() throws Throwable {
+ try {
+ ReflectionUtil
+ .invokeMethod(_method, _testInstance, new Object[] {});
+ } catch (ReflectionException e) {
+ throw e.getCause();
+ }
+ }
+
+}
Copied: trunk/punit/src/org/punit/runner/testmethod/TestMethodRunner.java (from rev 12, trunk/punit/src/org/punit/runner/TestMethodRunner.java)
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/TestMethodRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/testmethod/TestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,14 @@
+package org.punit.runner.testmethod;
+
+import java.lang.reflect.*;
+
+public interface TestMethodRunner {
+ /**
+ * Runs the test method, and returns the watcher values.
+ * @param clazz
+ * @param method
+ * @return
+ */
+ public Object[] run(Object testInstance, Method method, Object[] params) throws Throwable;
+
+}
Modified: trunk/punit/src/org/punit/type/Parameterizable.java
===================================================================
--- trunk/punit/src/org/punit/type/Parameterizable.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit/src/org/punit/type/Parameterizable.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -1,5 +1,5 @@
package org.punit.type;
public interface Parameterizable {
- Parameter [] paramters();
+ Parameter [] parameters();
}
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-10 21:50:13 UTC (rev 15)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -14,6 +14,8 @@
suite.addTestSuite(ConcurrentExceptionTest.class);
suite.addTestSuite(MemoryWatcherTest.class);
suite.addTestSuite(PUnitConcurrentRunnerTest.class);
+ suite.addTestSuite(PUnitParameterizableTestMethodBuilderTest.class);
+ suite.addTestSuite(PUnitSoloParameterizableRunnerTest.class);
suite.addTestSuite(PUnitSoloRunnerTest.class);
suite.addTestSuite(PUnitTestMethodBuilderTest.class);
suite.addTestSuite(PUnitTestSuiteBuilderTest.class);
Added: trunk/punit.test/src/tests/api/org/punit/builder/PUnitParameterizableTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitParameterizableTestMethodBuilderTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitParameterizableTestMethodBuilderTest.java 2007-05-11 09:18:13 UTC (rev 16)
@@ -0,0 +1,30 @@
+package tests.api.org.punit.builder;
+
+import org.punit.builder.*;
+
+import tests.api.org.punit.testclasses.*;
+import tests.util.*;
+
+import junit.framework.*;
+
+public class PUnitParameterizableTestMethodBuilderTest extends TestCase {
+ private PUnitParameterizableTestMethodBuilder _testMethodBuidler;
+
+ protected void setUp() throws Exception {
+ _testMethodBuidler = new PUnitParameterizableTestMethodBuilder();
+ }
+
+
+ public void test1() {
+ Object[] methods = _testMethodBuidler.buildT...
[truncated message content] |
|
From: <zha...@us...> - 2007-05-11 10:31:31
|
Revision: 17
http://p-unit.svn.sourceforge.net/p-unit/?rev=17&view=rev
Author: zhanghuangzhu
Date: 2007-05-11 03:31:31 -0700 (Fri, 11 May 2007)
Log Message:
-----------
Andrew Zhang: Implemented PUnitConcurrentParameterizableRunner.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java
trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java
trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloParameterizableRunnerTest.java
Added Paths:
-----------
trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java
trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentParameterizableRunnerTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java
Removed Paths:
-------------
trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java
trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java
Deleted: trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit/src/org/punit/runner/AbstractParameterizableRunner.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -1,19 +0,0 @@
-package org.punit.runner;
-
-import org.punit.builder.*;
-import org.punit.runner.testmethod.*;
-import org.punit.type.*;
-
-public abstract class AbstractParameterizableRunner extends PUnitAbstractRunner implements ParameterizableRunner {
-
- public AbstractParameterizableRunner(TestSuiteBuilder testSuiteBuiler,
- TestMethodBuilder testMethodBuilder,
- TestMethodRunner testMethodRunner) {
- super(testSuiteBuiler, testMethodBuilder, testMethodRunner);
- }
-
- public boolean accept(Class clazz) {
- return Parameterizable.class.isAssignableFrom(clazz);
- }
-
-}
\ No newline at end of file
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -76,6 +76,6 @@
return _testMethodBuilder.buildTestMethods(testClass);
}
- public abstract boolean accept(Class testCaseClass);
+ public abstract boolean accept(Class testClass);
}
Added: trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -0,0 +1,21 @@
+package org.punit.runner;
+
+import org.punit.builder.*;
+import org.punit.runner.testmethod.*;
+import org.punit.type.*;
+
+public class PUnitConcurrentParameterizableRunner extends PUnitAbstractRunner
+ implements ParameterizableRunner {
+
+ public PUnitConcurrentParameterizableRunner() {
+ super(new PUnitTestSuiteBuilder(),
+ new PUnitParameterizableTestMethodBuilder(),
+ new ConcurrentTestMethodRunner());
+ }
+
+ public boolean accept(Class testClass) {
+ return Parameterizable.class.isAssignableFrom(testClass)
+ && Concurrent.class.isAssignableFrom(testClass);
+ }
+
+}
Modified: trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -4,11 +4,15 @@
import org.punit.runner.testmethod.*;
import org.punit.type.*;
-public class PUnitSoloParameterizableRunner extends AbstractParameterizableRunner {
+public class PUnitSoloParameterizableRunner extends PUnitAbstractRunner implements ParameterizableRunner {
public PUnitSoloParameterizableRunner() {
- super(new PUnitTestSuiteBuilder(), new PUnitParameterizableTestMethodBuilder(), new SoloParameterizableTestMethodRunner());
+ super(new PUnitTestSuiteBuilder(), new PUnitParameterizableTestMethodBuilder(), new SoloTestMethodRunner());
}
+ public boolean accept(Class testClass) {
+ return Parameterizable.class.isAssignableFrom(testClass);
+ }
+
}
Modified: trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit/src/org/punit/runner/testmethod/ConcurrentTestMethodRunner.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -5,22 +5,23 @@
import org.punit.util.*;
public class ConcurrentTestMethodRunner extends AbstractTestMethodRunner {
+
TestMethodThread[] _threads;
ConcurrentException _concurrentException = new ConcurrentException();
- public ConcurrentTestMethodRunner() {
-
- }
-
protected void runImpl() throws Throwable {
startThreads();
joinThreads();
- if(_concurrentException.size() > 0) {
+ if (_concurrentException.size() > 0) {
throw _concurrentException;
}
}
+ protected void runMethod() throws Throwable {
+ ReflectionUtil.invokeMethod(_method, _testInstance, _params);
+ }
+
private void startThreads() {
for (int i = 0; i < _threads.length; ++i) {
_threads[i].start();
@@ -43,15 +44,20 @@
int threadCount = concurrentTestInstance.concurrentCount();
_threads = new TestMethodThread[threadCount];
for (int i = 0; i < _threads.length; ++i) {
- _threads[i] = new TestMethodThread();
+ _threads[i] = new TestMethodThread(this);
}
}
private class TestMethodThread extends Thread {
- // TODO: exception hanlding
+ ConcurrentTestMethodRunner _runner;
+
+ public TestMethodThread(ConcurrentTestMethodRunner runner) {
+ _runner = runner;
+ }
+
public void run() {
try {
- ReflectionUtil.invokeMethod(_method, _testInstance, _params);
+ _runner.runMethod();
} catch (ReflectionException e) {
_concurrentException.add(e.getCause());
} catch (Throwable t) {
Deleted: trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit/src/org/punit/runner/testmethod/SoloParameterizableTestMethodRunner.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -1,17 +0,0 @@
-package org.punit.runner.testmethod;
-
-import org.punit.exception.*;
-import org.punit.type.*;
-import org.punit.util.*;
-
-public class SoloParameterizableTestMethodRunner extends AbstractTestMethodRunner {
-
- protected void runImpl() throws Throwable {
- try {
- ReflectionUtil.invokeMethod(_method, _testInstance, _params);
- } catch (ReflectionException e) {
- throw e.getCause();
- }
- }
-
-}
Modified: trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit/src/org/punit/runner/testmethod/SoloTestMethodRunner.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -7,8 +7,7 @@
protected void runImpl() throws Throwable {
try {
- ReflectionUtil
- .invokeMethod(_method, _testInstance, new Object[] {});
+ ReflectionUtil.invokeMethod(_method, _testInstance, _params);
} catch (ReflectionException e) {
throw e.getCause();
}
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -13,6 +13,7 @@
//$JUnit-BEGIN$
suite.addTestSuite(ConcurrentExceptionTest.class);
suite.addTestSuite(MemoryWatcherTest.class);
+ suite.addTestSuite(PUnitConcurrentParameterizableRunnerTest.class);
suite.addTestSuite(PUnitConcurrentRunnerTest.class);
suite.addTestSuite(PUnitParameterizableTestMethodBuilderTest.class);
suite.addTestSuite(PUnitSoloParameterizableRunnerTest.class);
Added: trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentParameterizableRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentParameterizableRunnerTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitConcurrentParameterizableRunnerTest.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -0,0 +1,31 @@
+package tests.api.org.punit.runner;
+
+import junit.framework.*;
+
+import org.punit.runner.*;
+
+import tests.api.org.punit.testclasses.*;
+
+public class PUnitConcurrentParameterizableRunnerTest extends TestCase {
+ private PUnitConcurrentParameterizableRunner _runner;
+
+ protected void setUp() throws Exception {
+ _runner = new PUnitConcurrentParameterizableRunner();
+ ConcurrentParameterizableTestClass.reset();
+ }
+
+ public void testRunTest() {
+ _runner.run(ConcurrentParameterizableTestClass.class);
+ assertTestClassRun();
+ }
+
+ private void assertTestClassRun() {
+ assertEquals(ConcurrentParameterizableTestClass.SUM
+ * ConcurrentParameterizableTestClass.COCURRENT_COUNT,
+ ConcurrentParameterizableTestClass._test1);
+ assertFalse(ConcurrentParameterizableTestClass._test2);
+ assertTrue(ConcurrentParameterizableTestClass._setUp);
+ assertTrue(ConcurrentParameterizableTestClass._tearDown);
+ }
+
+}
Modified: trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloParameterizableRunnerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloParameterizableRunnerTest.java 2007-05-11 09:18:13 UTC (rev 16)
+++ trunk/punit.test/src/tests/api/org/punit/runner/PUnitSoloParameterizableRunnerTest.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -7,7 +7,7 @@
import tests.api.org.punit.testclasses.*;
public class PUnitSoloParameterizableRunnerTest extends TestCase {
- private AbstractParameterizableRunner _runner;
+ private PUnitSoloParameterizableRunner _runner;
protected void setUp() throws Exception {
_runner = new PUnitSoloParameterizableRunner();
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/ConcurrentParameterizableTestClass.java 2007-05-11 10:31:31 UTC (rev 17)
@@ -0,0 +1,70 @@
+package tests.api.org.punit.testclasses;
+
+import org.punit.type.*;
+
+public class ConcurrentParameterizableTestClass implements Parameterizable, Concurrent {
+
+ private static final int VALUE1 = 10;
+
+ private static final int VALUE2 = 20;
+
+ public static final int SUM = 30;
+
+ public static final int COCURRENT_COUNT = 5;
+
+ public static int _test1;
+
+ public static boolean _test2;
+
+ public static boolean _setUp;
+
+ public static boolean _tearDown;
+
+ public static void reset() {
+ _test1 = 0;
+ _test2 = false;
+ _setUp = false;
+ _tearDown = false;
+ }
+
+ private void setUp() {
+ _setUp = true;
+ }
+
+ private void tearDown() {
+ _tearDown = true;
+ }
+
+
+ public synchronized void test1(Parameter1 p) {
+ _test1 += p.value;
+ }
+
+ public void test2() {
+ _test2 = true;
+ }
+
+ public void test3(Parameter p) {
+
+ }
+
+ public void test3(int i) {
+
+ }
+
+ public Parameter[] parameters() {
+ return new Parameter[] { new Parameter1(VALUE1), new Parameter1(VALUE2), };
+ }
+
+ static class Parameter1 implements Parameter {
+ int value;
+
+ Parameter1(int i) {
+ value = i;
+ }
+ }
+
+ public int concurrentCount() {
+ return COCURRENT_COUNT;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-11 15:09:57
|
Revision: 24
http://p-unit.svn.sourceforge.net/p-unit/?rev=24&view=rev
Author: zhanghuangzhu
Date: 2007-05-11 08:09:57 -0700 (Fri, 11 May 2007)
Log Message:
-----------
Andrew Zhang: implemented CompetitiveTestSuite
Modified Paths:
--------------
trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java
Added Paths:
-----------
trunk/punit/src/org/punit/type/Competitive.java
trunk/punit/src/org/punit/type/CompetitiveTestSuite.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveInterface.java
trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass2.java
trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite2.java
trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java
Modified: trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java 2007-05-11 13:28:28 UTC (rev 23)
+++ trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java 2007-05-11 15:09:57 UTC (rev 24)
@@ -4,37 +4,65 @@
import java.util.*;
import org.punit.type.*;
+import org.punit.util.*;
-public abstract class PUnitAbstractTestMethodBuilder implements TestMethodBuilder {
- public Object[] buildTestMethods(Class testClass) {
- Method[] methods = testClass.getDeclaredMethods();
- Collection testMethods;
- if (isAlphabetical(testClass)) {
- testMethods = new TreeSet(new AlphabeticalMethodNameComparator());
- } else {
- testMethods = new ArrayList();
- }
- for (int i = 0; i < methods.length; ++i) {
- Method method = methods[i];
- if (isTestMethod(method)) {
- testMethods.add(method);
- }
- }
- return testMethods.toArray();
- }
+public abstract class PUnitAbstractTestMethodBuilder implements
+ TestMethodBuilder {
- private boolean isAlphabetical(Class testClass) {
- return Alphabetical.class.isAssignableFrom(testClass);
- }
+ public Object[] buildTestMethods(Class testClass) {
+ checkTestClass(testClass);
+ Method[] methods = testClass.getDeclaredMethods();
+ Collection testMethods;
+ if (isAlphabetical(testClass)) {
+ testMethods = new TreeSet(new AlphabeticalMethodNameComparator());
+ } else {
+ testMethods = new ArrayList();
+ }
+ for (int i = 0; i < methods.length; ++i) {
+ Method method = methods[i];
+ if (isTestMethod(method)) {
+ testMethods.add(method);
+ }
+ }
+ return testMethods.toArray();
+ }
- protected abstract boolean isTestMethod(Method method);
+ protected abstract boolean isTestMethod(Method method);
- private static class AlphabeticalMethodNameComparator implements Comparator {
- public int compare(Object o1, Object o2) {
- Method m1 = (Method) o1;
- Method m2 = (Method) o2;
- return m1.getName().compareTo(m2.getName());
- }
- }
+ private void checkTestClass(Class testClass) {
+ if (isCompetitiveTestSuite(testClass)) {
+ checkCompetitiveTestSuite(testClass);
+ }
+ }
+ private void checkCompetitiveTestSuite(Class testClass) {
+ CompetitiveTestSuite suite = (CompetitiveTestSuite) ReflectionUtil
+ .newInstance(testClass);
+ Class competitiveInterface = suite.comptitiveInterface();
+ Class[] implementors = suite.suite();
+ for (int i = 0; i < implementors.length; ++i) {
+ Class implementor = implementors[i];
+ if (!competitiveInterface.isAssignableFrom(implementor)) {
+ throw new IllegalArgumentException(implementor
+ + " should implement " + competitiveInterface);
+ }
+ }
+ }
+
+ private boolean isCompetitiveTestSuite(Class testClass) {
+ return CompetitiveTestSuite.class.isAssignableFrom(testClass);
+ }
+
+ private boolean isAlphabetical(Class testClass) {
+ return Alphabetical.class.isAssignableFrom(testClass);
+ }
+
+ private static class AlphabeticalMethodNameComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ Method m1 = (Method) o1;
+ Method m2 = (Method) o2;
+ return m1.getName().compareTo(m2.getName());
+ }
+ }
+
}
Added: trunk/punit/src/org/punit/type/Competitive.java
===================================================================
--- trunk/punit/src/org/punit/type/Competitive.java (rev 0)
+++ trunk/punit/src/org/punit/type/Competitive.java 2007-05-11 15:09:57 UTC (rev 24)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface Competitive {
+ public int competitiveID();
+}
Added: trunk/punit/src/org/punit/type/CompetitiveTestSuite.java
===================================================================
--- trunk/punit/src/org/punit/type/CompetitiveTestSuite.java (rev 0)
+++ trunk/punit/src/org/punit/type/CompetitiveTestSuite.java 2007-05-11 15:09:57 UTC (rev 24)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface CompetitiveTestSuite extends TestSuite{
+ public Class comptitiveInterface();
+}
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-11 13:28:28 UTC (rev 23)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-11 15:09:57 UTC (rev 24)
@@ -14,6 +14,7 @@
//$JUnit-BEGIN$
suite.addTestSuite(ConcurrentExceptionTest.class);
suite.addTestSuite(MemoryWatcherTest.class);
+ suite.addTestSuite(PUnitAbstractTestMethodBuilderTest.class);
suite.addTestSuite(PUnitConcurrentParameterizableRunnerTest.class);
suite.addTestSuite(PUnitConcurrentRunnerTest.class);
suite.addTestSuite(PUnitParameterizableTestMethodBuilderTest.class);
Added: trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java 2007-05-11 15:09:57 UTC (rev 24)
@@ -0,0 +1,35 @@
+package tests.api.org.punit.builder;
+
+import java.lang.reflect.*;
+import junit.framework.*;
+import org.punit.builder.*;
+import tests.api.org.punit.testclasses.*;
+import tests.util.*;
+
+public class PUnitAbstractTestMethodBuilderTest extends TestCase {
+ private MockTestMethodBuilder _build;
+
+ protected void setUp() throws Exception {
+ _build = new MockTestMethodBuilder();
+ }
+
+ public void testBuildCompetitive1() {
+ _build.buildTestMethods(CompetitiveTestSuite1.class);
+ }
+
+ public void testBuildCompetitive2() {
+ AssertUtil.assertException(IllegalArgumentException.class, new CodeRunner() {
+ public void run() throws Throwable {
+ _build.buildTestMethods(CompetitiveTestSuite2.class);
+ }
+ });
+ }
+
+ static class MockTestMethodBuilder extends PUnitAbstractTestMethodBuilder {
+
+ protected boolean isTestMethod(Method method) {
+ return false;
+ }
+
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveInterface.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveInterface.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveInterface.java 2007-05-11 15:09:57 UTC (rev 24)
@@ -0,0 +1,10 @@
+package tests.api.org.punit.testclasses;
+
+import org.punit.type.*;
+
+public interface CompetitiveInterface extends Competitive {
+
+ public void test1();
+
+ public void test2();
+}
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass1.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass1.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass1.java 2007-05-11 15:09:57 UTC (rev 24)
@@ -0,0 +1,32 @@
+package tests.api.org.punit.testclasses;
+
+import org.punit.runner.*;
+
+
+public class CompetitiveTestClass1 implements CompetitiveInterface {
+
+ public static void main(String[] args) {
+ new PUnitSoloRunner().run(CompetitiveTestClass1.class);
+ }
+
+ public void setUp() {
+
+ }
+
+ public void tearDown() {
+
+ }
+
+ public void test1() {
+ System.out.println("test1");
+ }
+
+ public void test2() {
+ System.out.println("test2");
+ }
+
+ public int competitiveID() {
+ return 10;
+ }
+
+}
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass2.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass2.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass2.java 2007-05-11 15:09:57 UTC (rev 24)
@@ -0,0 +1,32 @@
+package tests.api.org.punit.testclasses;
+
+import org.punit.runner.*;
+
+
+public class CompetitiveTestClass2 implements CompetitiveInterface {
+
+ public static void main(String[] args) {
+ new PUnitSoloRunner().run(CompetitiveTestClass2.class);
+ }
+
+ public void setUp() {
+
+ }
+
+ public void tearDown() {
+
+ }
+
+ public void test1() {
+ System.out.println("test1");
+ }
+
+ public void test2() {
+ System.out.println("test2");
+ }
+
+ public int competitiveID() {
+ return 10;
+ }
+
+}
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite1.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite1.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite1.java 2007-05-11 15:09:57 UTC (rev 24)
@@ -0,0 +1,27 @@
+package tests.api.org.punit.testclasses;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+public class CompetitiveTestSuite1 implements CompetitiveTestSuite {
+
+ public static void main(String[] args) {
+ new PUnitSoloRunner().run(CompetitiveTestSuite1.class);
+ }
+
+ public int id() {
+ return 10;
+ }
+
+ public Class[] suite() {
+ return new Class[] {
+ CompetitiveTestClass1.class,
+ CompetitiveTestClass2.class,
+ };
+ }
+
+ public Class comptitiveInterface() {
+ return CompetitiveInterface.class;
+ }
+
+}
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite2.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite2.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite2.java 2007-05-11 15:09:57 UTC (rev 24)
@@ -0,0 +1,28 @@
+package tests.api.org.punit.testclasses;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+public class CompetitiveTestSuite2 implements CompetitiveTestSuite {
+
+ public static void main(String[] args) {
+ new PUnitSoloRunner().run(CompetitiveTestSuite2.class);
+ }
+
+ public int id() {
+ return 10;
+ }
+
+ public Class[] suite() {
+ return new Class[] {
+ CompetitiveTestClass1.class,
+ CompetitiveTestClass2.class,
+ TestClass1.class,
+ };
+ }
+
+ public Class comptitiveInterface() {
+ return CompetitiveInterface.class;
+ }
+
+}
Added: trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java (rev 0)
+++ trunk/punit.test/src/tests/sample/testcase/CompetitiveTestSample.java 2007-05-11 15:09:57 UTC (rev 24)
@@ -0,0 +1,11 @@
+package tests.sample.testcase;
+
+import org.punit.runner.*;
+
+import tests.api.org.punit.testclasses.*;
+
+public class CompetitiveTestSample {
+ public static void main(String[] args) {
+ new PUnitSoloRunner().run(CompetitiveTestSuite1.class);
+ }
+}
Modified: trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java 2007-05-11 13:28:28 UTC (rev 23)
+++ trunk/punit.test/src/tests/sample/testcase/PUnitTestSuiteSample.java 2007-05-11 15:09:57 UTC (rev 24)
@@ -16,6 +16,7 @@
public Class[] suite() {
return new Class[] {
+ CompetitiveTestSample.class,
ConcurrentParameterizableTestSample.class,
ConcurrentTestSample.class,
JUnitTestSample.class,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-12 13:13:39
|
Revision: 28
http://p-unit.svn.sourceforge.net/p-unit/?rev=28&view=rev
Author: zhanghuangzhu
Date: 2007-05-12 06:13:40 -0700 (Sat, 12 May 2007)
Log Message:
-----------
Andrew Zhang: First implementation for logging system.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
Added Paths:
-----------
trunk/punit/src/org/punit/logger/
trunk/punit/src/org/punit/logger/PUnitLogger.java
trunk/punit/src/org/punit/util/LoggerUtil.java
trunk/punit.test/src/tests/api/org/punit/logger/
trunk/punit.test/src/tests/api/org/punit/logger/PUnitLoggerTest.java
trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java
Added: trunk/punit/src/org/punit/logger/PUnitLogger.java
===================================================================
--- trunk/punit/src/org/punit/logger/PUnitLogger.java (rev 0)
+++ trunk/punit/src/org/punit/logger/PUnitLogger.java 2007-05-12 13:13:40 UTC (rev 28)
@@ -0,0 +1,39 @@
+package org.punit.logger;
+
+import java.io.*;
+import java.util.logging.*;
+
+public class PUnitLogger {
+
+ public static PrintStream _ps;
+
+ public static Level _level;
+
+ static {
+ reset();
+ }
+
+ public static void reset() {
+ _ps = System.err;
+ _level = Level.FINE;
+ }
+
+ public static void setLogLevel(Level level) {
+ _level = level;
+ }
+
+ public static void setOutputStream(PrintStream ps) {
+ _ps = ps;
+ }
+
+ public static void log(String message, Level level) {
+ if(_ps == null) {
+ return;
+ }
+ if(level.intValue() < _level.intValue()) {
+ return;
+ }
+ _ps.print(message);
+ _ps.flush();
+ }
+}
Modified: trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-12 11:58:43 UTC (rev 27)
+++ trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-12 13:13:40 UTC (rev 28)
@@ -1,8 +1,10 @@
package org.punit.runner.method;
import java.lang.reflect.*;
+import java.util.logging.*;
import org.punit.exception.*;
+import org.punit.logger.*;
import org.punit.type.*;
import org.punit.util.*;
import org.punit.watcher.*;
@@ -32,6 +34,7 @@
}
public Object[] run(Object testInstance, Method method, Object[] params) throws Throwable {
+ LoggerUtil.logMethod(method);
try {
init(testInstance, method, params);
setUpBeforeWatchers();
Added: trunk/punit/src/org/punit/util/LoggerUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/LoggerUtil.java (rev 0)
+++ trunk/punit/src/org/punit/util/LoggerUtil.java 2007-05-12 13:13:40 UTC (rev 28)
@@ -0,0 +1,31 @@
+package org.punit.util;
+
+import java.lang.reflect.*;
+import java.util.logging.*;
+
+import org.punit.logger.*;
+
+public class LoggerUtil {
+ public static void logMethod(Method method) {
+ PUnitLogger.log(simpleMethodName(method), Level.FINE);
+ }
+
+ public static String simpleMethodName(Method method) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(method.getDeclaringClass().getName());
+ sb.append(".");
+ sb.append(method.getName());
+ sb.append("(");
+ Class[] params = method.getParameterTypes();
+ for(int i = 0; i < params.length - 1 ; ++i) {
+ sb.append(params[i].getSimpleName());
+ sb.append(", ");
+ }
+ if(params.length > 0) {
+ sb.append(params[params.length - 1].getSimpleName());
+ }
+ sb.append(")");
+ return sb.toString();
+ }
+
+}
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-12 11:58:43 UTC (rev 27)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-12 13:13:40 UTC (rev 28)
@@ -3,6 +3,7 @@
import junit.framework.*;
import tests.api.org.punit.builder.*;
import tests.api.org.punit.exception.*;
+import tests.api.org.punit.logger.*;
import tests.api.org.punit.runner.*;
import tests.api.org.punit.util.*;
import tests.api.org.punit.watcher.*;
@@ -13,10 +14,12 @@
TestSuite suite = new TestSuite("Test for tests.api.org.punit");
//$JUnit-BEGIN$
suite.addTestSuite(ConcurrentExceptionTest.class);
+ suite.addTestSuite(LoggerUtilTest.class);
suite.addTestSuite(MemoryWatcherTest.class);
suite.addTestSuite(PUnitAbstractTestMethodBuilderTest.class);
suite.addTestSuite(PUnitConcurrentParameterizableRunnerTest.class);
suite.addTestSuite(PUnitConcurrentRunnerTest.class);
+ suite.addTestSuite(PUnitLoggerTest.class);
suite.addTestSuite(PUnitParameterizableTestMethodBuilderTest.class);
suite.addTestSuite(PUnitSoloParameterizableRunnerTest.class);
suite.addTestSuite(PUnitSoloRunnerTest.class);
Added: trunk/punit.test/src/tests/api/org/punit/logger/PUnitLoggerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/logger/PUnitLoggerTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/logger/PUnitLoggerTest.java 2007-05-12 13:13:40 UTC (rev 28)
@@ -0,0 +1,67 @@
+package tests.api.org.punit.logger;
+
+import java.io.*;
+import java.util.logging.*;
+
+import junit.framework.*;
+
+import org.punit.logger.*;
+
+public class PUnitLoggerTest extends TestCase {
+ private static MockPrintStream _mockPrintStream = new MockPrintStream(
+ System.err);
+
+ static {
+ PUnitLogger.setOutputStream(_mockPrintStream);
+ }
+
+ protected void setUp() throws Exception {
+ reset();
+ }
+
+ protected void tearDown() {
+ PUnitLogger.reset();
+ }
+
+ public void test() {
+ PUnitLogger.setLogLevel(Level.ALL);
+ PUnitLogger.log(null, Level.INFO);
+ assertPrinted();
+
+ PUnitLogger.setLogLevel(Level.INFO);
+ reset();
+ PUnitLogger.log(null, Level.SEVERE);
+ assertPrinted();
+
+ reset();
+ PUnitLogger.log(null, Level.FINE);
+ assertNotPrinted();
+
+ }
+
+ private void reset() {
+ _mockPrintStream._printed = false;
+ }
+
+ private void assertPrinted() {
+ assertTrue(_mockPrintStream._printed);
+ }
+
+ private void assertNotPrinted() {
+ assertFalse(_mockPrintStream._printed);
+ }
+
+ private static class MockPrintStream extends PrintStream {
+
+ public boolean _printed;
+
+ public MockPrintStream(OutputStream out) {
+ super(out);
+ }
+
+ public void print(String s) {
+ _printed = true;
+ }
+
+ }
+}
Added: trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java 2007-05-12 13:13:40 UTC (rev 28)
@@ -0,0 +1,52 @@
+package tests.api.org.punit.util;
+
+import java.lang.reflect.*;
+
+import junit.framework.*;
+
+import org.punit.type.*;
+import org.punit.util.*;
+
+public class LoggerUtilTest extends TestCase {
+
+ private static final String CLASS_NAME = LoggerUtilTest.class.getName();
+
+ public void testSimpleMethodName() {
+ Method method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f",
+ new Class[] {});
+ String simpleMethodName = LoggerUtil.simpleMethodName(method);
+ assertEquals(CLASS_NAME + ".f()", simpleMethodName);
+
+ method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f",
+ new Class[] { Parameter.class });
+ simpleMethodName = LoggerUtil.simpleMethodName(method);
+ assertEquals(CLASS_NAME + ".f(Parameter)", simpleMethodName);
+
+ method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f",
+ new Class[] { int.class });
+ simpleMethodName = LoggerUtil.simpleMethodName(method);
+ assertEquals(CLASS_NAME + ".f(int)", simpleMethodName);
+
+ method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f",
+ new Class[] { int[].class });
+ simpleMethodName = LoggerUtil.simpleMethodName(method);
+ assertEquals(CLASS_NAME + ".f(int[])", simpleMethodName);
+ }
+
+ public void f() {
+
+ }
+
+ public void f(Parameter p) {
+
+ }
+
+ public void f(int i) {
+
+ }
+
+ public void f(int[] i) {
+
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-12 22:14:11
|
Revision: 29
http://p-unit.svn.sourceforge.net/p-unit/?rev=29&view=rev
Author: zhanghuangzhu
Date: 2007-05-12 15:14:09 -0700 (Sat, 12 May 2007)
Log Message:
-----------
Andrew Zhang: Implemented logging system based on event.
Modified Paths:
--------------
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/runner/method/ConcurrentTestMethodRunner.java
trunk/punit/src/org/punit/runner/method/TestMethodRunner.java
trunk/punit/src/org/punit/type/PUnitTest.java
trunk/punit/src/org/punit/util/LoggerUtil.java
trunk/punit/src/org/punit/watcher/MemoryWatcher.java
trunk/punit/src/org/punit/watcher/TimeWatcher.java
trunk/punit/src/org/punit/watcher/Watcher.java
trunk/punit.test/src/tests/api/org/punit/logger/PUnitLoggerTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestSample.java
trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java
trunk/punit.test/src/tests/sample/testcase/ConcurrentParameterizableTestSample.java
trunk/punit.test/src/tests/sample/testcase/ConcurrentTestSample.java
trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java
trunk/punit.test/src/tests/sample/testcase/PUnitTestCaseSample.java
trunk/punit.test/src/tests/sample/testcase/ParameterizableTestSample.java
trunk/punit.test/src/tests/sample/testcase/SimpleTestSample.java
Added Paths:
-----------
trunk/punit/src/org/punit/events/
trunk/punit/src/org/punit/events/ClassEvent.java
trunk/punit/src/org/punit/events/ClassEventListener.java
trunk/punit/src/org/punit/events/MethodEvent.java
trunk/punit/src/org/punit/events/MethodEventListener.java
trunk/punit/src/org/punit/events/RunnerEvent.java
trunk/punit/src/org/punit/events/RunnerEventListener.java
trunk/punit/src/org/punit/events/WatcherEvent.java
trunk/punit/src/org/punit/events/WatcherEventListener.java
trunk/punit/src/org/punit/logger/LogListener.java
Removed Paths:
-------------
trunk/punit/src/org/punit/logger/PUnitLogger.java
Added: trunk/punit/src/org/punit/events/ClassEvent.java
===================================================================
--- trunk/punit/src/org/punit/events/ClassEvent.java (rev 0)
+++ trunk/punit/src/org/punit/events/ClassEvent.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -0,0 +1,10 @@
+package org.punit.events;
+
+
+
+public interface ClassEvent {
+
+ public void addClassEventListener(ClassEventListener listener);
+
+ public void removeClassEventListener(ClassEventListener listener);
+}
Added: trunk/punit/src/org/punit/events/ClassEventListener.java
===================================================================
--- trunk/punit/src/org/punit/events/ClassEventListener.java (rev 0)
+++ trunk/punit/src/org/punit/events/ClassEventListener.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -0,0 +1,11 @@
+package org.punit.events;
+
+import java.util.*;
+
+public interface ClassEventListener extends EventListener {
+
+ public void onClassStart(Class clazz);
+
+ public void onClassEnd(Class clazz);
+
+}
Added: trunk/punit/src/org/punit/events/MethodEvent.java
===================================================================
--- trunk/punit/src/org/punit/events/MethodEvent.java (rev 0)
+++ trunk/punit/src/org/punit/events/MethodEvent.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -0,0 +1,10 @@
+package org.punit.events;
+
+
+
+public interface MethodEvent {
+
+ public void addMethodEventListener(MethodEventListener listener);
+
+ public void removeMethodEventListener(MethodEventListener listener);
+}
Added: trunk/punit/src/org/punit/events/MethodEventListener.java
===================================================================
--- trunk/punit/src/org/punit/events/MethodEventListener.java (rev 0)
+++ trunk/punit/src/org/punit/events/MethodEventListener.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -0,0 +1,12 @@
+package org.punit.events;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+public interface MethodEventListener extends EventListener {
+
+ public void onMethodStart(Method method);
+
+ public void onMethodEnd(Method method, Throwable t);
+
+}
Added: trunk/punit/src/org/punit/events/RunnerEvent.java
===================================================================
--- trunk/punit/src/org/punit/events/RunnerEvent.java (rev 0)
+++ trunk/punit/src/org/punit/events/RunnerEvent.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -0,0 +1,10 @@
+package org.punit.events;
+
+
+
+public interface RunnerEvent {
+
+ public void addRunnerEventListener(RunnerEventListener listener);
+
+ public void removeRunnerEventListener(RunnerEventListener listener);
+}
Added: trunk/punit/src/org/punit/events/RunnerEventListener.java
===================================================================
--- trunk/punit/src/org/punit/events/RunnerEventListener.java (rev 0)
+++ trunk/punit/src/org/punit/events/RunnerEventListener.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -0,0 +1,11 @@
+package org.punit.events;
+
+import java.util.*;
+
+public interface RunnerEventListener extends EventListener {
+
+ public void onRunnerStart(Class clazz);
+
+ public void onRunnerEnd(Class clazz);
+
+}
Added: trunk/punit/src/org/punit/events/WatcherEvent.java
===================================================================
--- trunk/punit/src/org/punit/events/WatcherEvent.java (rev 0)
+++ trunk/punit/src/org/punit/events/WatcherEvent.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -0,0 +1,8 @@
+package org.punit.events;
+
+public interface WatcherEvent {
+
+ public void addWatcherEventListener(WatcherEventListener listener);
+
+ public void removeWatcherEventListener(WatcherEventListener listener);
+}
Added: trunk/punit/src/org/punit/events/WatcherEventListener.java
===================================================================
--- trunk/punit/src/org/punit/events/WatcherEventListener.java (rev 0)
+++ trunk/punit/src/org/punit/events/WatcherEventListener.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -0,0 +1,16 @@
+package org.punit.events;
+
+import java.util.*;
+
+import org.punit.watcher.*;
+
+public interface WatcherEventListener extends EventListener {
+ public void onWatchersStart();
+
+ public void onWatcherStart(Watcher watch);
+
+ public void onWatcherEnd(Watcher watch);
+
+ public void onWatchersEnd();
+
+}
Copied: trunk/punit/src/org/punit/logger/LogListener.java (from rev 28, trunk/punit/src/org/punit/logger/PUnitLogger.java)
===================================================================
--- trunk/punit/src/org/punit/logger/LogListener.java (rev 0)
+++ trunk/punit/src/org/punit/logger/LogListener.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -0,0 +1,151 @@
+package org.punit.logger;
+
+import java.io.*;
+import java.lang.reflect.*;
+import java.util.*;
+import java.util.logging.*;
+
+import org.punit.events.*;
+import org.punit.util.*;
+import org.punit.watcher.*;
+
+public class LogListener implements RunnerEventListener, ClassEventListener,
+ MethodEventListener, WatcherEventListener {
+
+ Summary _summary = new Summary();
+
+ private boolean _watchersStart;
+
+ public void onRunnerStart(Class clazz) {
+ _summary.start();
+ }
+
+ public void onRunnerEnd(Class clazz) {
+ _summary.stop();
+ _summary.log(this);
+ ;
+ }
+
+ public void onClassStart(Class clazz) {
+ log(clazz.getName() + "\n", Level.INFO);
+ }
+
+ public void onClassEnd(Class clazz) {
+
+ }
+
+ public void onMethodStart(Method method) {
+ log(LoggerUtil.simpleMethodName(method), Level.INFO);
+ }
+
+ public void onMethodEnd(Method method, Throwable t) {
+ _summary.countMethod();
+ log("\n", Level.INFO);
+ if (t != null) {
+ log(t.toString() + "\n", Level.INFO);
+ _summary.addThrowable(t);
+ }
+ }
+
+ public void onWatchersStart() {
+ _watchersStart = true;
+ log(" - [", Level.FINE);
+ }
+
+ public void onWatcherStart(Watcher watch) {
+ }
+
+ public void onWatchersEnd() {
+ log("]", Level.FINE);
+ }
+
+ public void onWatcherEnd(Watcher watch) {
+ String watchValue = watch.stringValue();
+ String s = _watchersStart ? watchValue : "," + watch.stringValue();
+ _watchersStart = false;
+ log(s, Level.FINE);
+ }
+
+ public PrintStream _ps = System.err;
+
+ public Level _level = Level.FINE;
+
+ public void setLogLevel(Level level) {
+ _level = level;
+ }
+
+ public void setOutputStream(PrintStream ps) {
+ _ps = ps;
+ }
+
+ public void log(String message, Level level) {
+ if (_ps == null) {
+ return;
+ }
+ if (level.intValue() < _level.intValue()) {
+ return;
+ }
+ _ps.print(message);
+ _ps.flush();
+ }
+
+ static class Summary {
+ private int _methodCount;
+
+ private TimeWatcher _timeWatcher = new TimeWatcher();
+
+ private List _throwableList = new ArrayList();
+
+ public void countMethod() {
+ ++_methodCount;
+ }
+
+ public void start() {
+ _timeWatcher.start();
+ }
+
+ public void stop() {
+ _timeWatcher.stop();
+ }
+
+ /*
+ * The format is:
+ *
+ * Total: 4 (GREEN) - 156ms
+ *
+ * or:
+ *
+ * Total: 2 (RED) - 120ms
+ * 1)java.lang.IllegalArgumentException
+ * at tests.SimpleTestSample.test1(SimpleTestSample.java:20)
+ * 2)java.lang.NullPointerException
+ * at tests.SimpleTestSample.test2(SimpleTestSample.java:24)
+ *
+ */
+ public void log(final LogListener logger) {
+ StringBuffer sb = new StringBuffer("Total: ");
+ sb.append(_methodCount);
+ int failures = _throwableList.size();
+ if (failures == 0) {
+ sb.append(" (GREEN) - ");
+ } else {
+ sb.append(" (RED) - ");
+ }
+ sb.append(_timeWatcher.stringValue());
+ sb.append("\n");
+ logger.log(sb.toString(), Level.INFO);
+ VisitorUtil.traverse(_throwableList.iterator(), new Visitor() {
+ int count = 0;
+
+ public void visit(Object obj) {
+ logger.log(++count + ")", Level.INFO);
+ ((Throwable) obj).printStackTrace(logger._ps);
+ }
+ });
+ }
+
+ public void addThrowable(Throwable t) {
+ _throwableList.add(t);
+ }
+ }
+}
Deleted: trunk/punit/src/org/punit/logger/PUnitLogger.java
===================================================================
--- trunk/punit/src/org/punit/logger/PUnitLogger.java 2007-05-12 13:13:40 UTC (rev 28)
+++ trunk/punit/src/org/punit/logger/PUnitLogger.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -1,39 +0,0 @@
-package org.punit.logger;
-
-import java.io.*;
-import java.util.logging.*;
-
-public class PUnitLogger {
-
- public static PrintStream _ps;
-
- public static Level _level;
-
- static {
- reset();
- }
-
- public static void reset() {
- _ps = System.err;
- _level = Level.FINE;
- }
-
- public static void setLogLevel(Level level) {
- _level = level;
- }
-
- public static void setOutputStream(PrintStream ps) {
- _ps = ps;
- }
-
- public static void log(String message, Level level) {
- if(_ps == null) {
- return;
- }
- if(level.intValue() < _level.intValue()) {
- return;
- }
- _ps.print(message);
- _ps.flush();
- }
-}
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-12 13:13:40 UTC (rev 28)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -1,8 +1,11 @@
package org.punit.runner;
import java.lang.reflect.*;
+import java.util.*;
import org.punit.builder.*;
+import org.punit.events.*;
+import org.punit.logger.*;
import org.punit.result.*;
import org.punit.runner.method.*;
import org.punit.type.*;
@@ -14,32 +17,76 @@
private TestMethodBuilder _testMethodBuilder;
private TestMethodRunner _testMethodRunner;
+
+ private List _runnerEventListeners = new ArrayList();
+
+ private List _classEventListeners = new ArrayList();
+
+ private LogListener _logger = new LogListener();
public PUnitAbstractRunner(TestSuiteBuilder testSuiteBuiler, TestMethodBuilder testMethodBuilder, TestMethodRunner testMethodRunner) {
_testSuiteBuiler = testSuiteBuiler;
_testMethodBuilder = testMethodBuilder;
_testMethodRunner = testMethodRunner;
+ registerLogListener();
}
public Result run(Class clazz) {
+ onRunnerStart(clazz);
Object[] testClasses = _testSuiteBuiler.buildTestClasses(clazz);
for (int i = 0; i < testClasses.length; ++i) {
runTestClass((Class)testClasses[i]);
}
+ onRunnerEnd(clazz);
return null;
}
+ private void onRunnerStart(final Class clazz) {
+ VisitorUtil.traverse(_runnerEventListeners.iterator(), new Visitor() {
+ public void visit(Object obj) {
+ ((RunnerEventListener)obj).onRunnerStart(clazz);
+ }
+ });
+ }
+
+ private void onRunnerEnd(final Class clazz) {
+ VisitorUtil.traverse(_runnerEventListeners.iterator(), new Visitor() {
+ public void visit(Object obj) {
+ ((RunnerEventListener)obj).onRunnerEnd(clazz);
+ }
+ });
+ }
+
private void runTestClass(Class clazz) {
if(!accept(clazz)) {
return;
}
+ onClassStart(clazz);
Object[] testMethods = buildTestMethod(clazz);
for(int i = 0; i < testMethods.length; ++i) {
Method method = (Method) testMethods[i];
runTestMethod(clazz, method);
}
+ onClassEnd(clazz);
}
+ private void onClassStart(final Class clazz) {
+ VisitorUtil.traverse(_classEventListeners.iterator(), new Visitor() {
+ public void visit(Object obj) {
+ ((ClassEventListener)obj).onClassStart(clazz);
+ }
+ });
+ }
+
+ private void onClassEnd(final Class clazz) {
+ VisitorUtil.traverse(_classEventListeners.iterator(), new Visitor() {
+ public void visit(Object obj) {
+ ((ClassEventListener)obj).onClassEnd(clazz);
+ }
+ });
+ }
+
+
private void runTestMethod(Class clazz, Method method) {
// TODO: add run result to the test result
Object testInstance = ReflectionUtil.newInstance(clazz);
@@ -78,4 +125,48 @@
public abstract boolean accept(Class testClass);
+ public TestMethodBuilder testMethodBuilder() {
+ return _testMethodBuilder;
+ }
+
+ public TestMethodRunner testMethodRunner() {
+ return _testMethodRunner;
+ }
+
+ public TestSuiteBuilder testSuiteBuiler() {
+ return _testSuiteBuiler;
+ }
+
+ public void addRunnerEventListener(RunnerEventListener listener) {
+ _runnerEventListeners.add(listener);
+ }
+
+ public void removeRunnerEventListener(RunnerEventListener listener) {
+ _runnerEventListeners.remove(listener);
+ }
+
+ public void addClassEventListener(ClassEventListener listener) {
+ _classEventListeners.add(listener);
+ }
+
+ public void removeClassEventListener(ClassEventListener listener) {
+ _classEventListeners.remove(listener);
+ }
+
+ private void registerLogListener() {
+ addRunnerEventListener(_logger);
+ addClassEventListener(_logger);
+ _testMethodRunner.addMethodEventListener(_logger);
+ _testMethodRunner.addWatcherEventListener(_logger);
+ }
+
+ public void removeLogListener() {
+ removeClassEventListener(_logger);
+ _testMethodRunner.removeMethodEventListener(_logger);
+ _testMethodRunner.removeWatcherEventListener(_logger);
+ }
+
+ public LogListener logListener() {
+ return _logger;
+ }
}
Modified: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java 2007-05-12 13:13:40 UTC (rev 28)
+++ trunk/punit/src/org/punit/runner/Runner.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -1,7 +1,8 @@
package org.punit.runner;
+import org.punit.events.*;
import org.punit.result.*;
-public interface Runner {
+public interface Runner extends RunnerEvent, ClassEvent {
public Result run(Class clazz);
}
Modified: trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-12 13:13:40 UTC (rev 28)
+++ trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -1,10 +1,10 @@
package org.punit.runner.method;
import java.lang.reflect.*;
-import java.util.logging.*;
+import java.util.*;
+import org.punit.events.*;
import org.punit.exception.*;
-import org.punit.logger.*;
import org.punit.type.*;
import org.punit.util.*;
import org.punit.watcher.*;
@@ -16,7 +16,7 @@
protected Object _testInstance;
protected Method _method;
-
+
protected Object[] _params;
protected Class _class;
@@ -25,33 +25,66 @@
protected Method _setUpMethod;
+ private List _methodEventListeners = new ArrayList();
+
+ private List _watcherEventListeners = new ArrayList();
+
public AbstractTestMethodRunner() {
- _watchers = new Watcher[] {new MemoryWatcher(), new TimeWatcher()};
+ _watchers = new Watcher[] { new MemoryWatcher(), new TimeWatcher() };
}
-
+
public void setWatchers(Watcher[] watchers) {
_watchers = watchers;
}
- public Object[] run(Object testInstance, Method method, Object[] params) throws Throwable {
- LoggerUtil.logMethod(method);
+ public void run(Object testInstance, Method method, Object[] params) {
+ Throwable throwable = null;
try {
+ onMethodStart(method);
init(testInstance, method, params);
setUpBeforeWatchers();
startWatchers();
setUpAfterWatchers();
runImpl();
+ } catch (Throwable t) {
+ throwable = t;
} finally {
- tearDownBeforeWatchers();
- stopWatchers();
- tearDownAfterWatchers();
+ try {
+ tearDownBeforeWatchers();
+ } catch (Throwable t) {
+ throwable = t;
+ } finally {
+ try {
+ stopWatchers();
+ tearDownAfterWatchers();
+ } catch (Throwable t) {
+ throwable = t;
+ }
+ }
+ onMethodEnd(method, throwable);
}
- return watchersValues();
}
+ private void onMethodStart(final Method method) {
+ VisitorUtil.traverse(_methodEventListeners.iterator(), new Visitor() {
+ public void visit(Object obj) {
+ ((MethodEventListener) obj).onMethodStart(method);
+ }
+ });
+ }
+
+ private void onMethodEnd(final Method method, final Throwable t) {
+ VisitorUtil.traverse(_methodEventListeners.iterator(), new Visitor() {
+ public void visit(Object obj) {
+ ((MethodEventListener) obj).onMethodEnd(method, t);
+ }
+ });
+ }
+
protected abstract void runImpl() throws Throwable;
- protected final void init(Object testInstance, Method method, Object[] params) {
+ protected final void init(Object testInstance, Method method,
+ Object[] params) {
_testInstance = testInstance;
_class = testInstance.getClass();
_params = params;
@@ -63,11 +96,11 @@
}
/**
- * This method might be overriden by subclass.
- * The runner may do some more things during this step.
- *
+ * This method might be overriden by subclass. The runner may do some more
+ * things during this step.
+ *
*/
- protected void setUpBeforeWatchers() {
+ protected void setUpBeforeWatchers() throws Throwable {
if (isPUnitTest()) {
((PUnitTest) _testInstance).setUpBeforeWatchers();
}
@@ -89,7 +122,7 @@
}
}
- private void tearDownAfterWatchers() {
+ private void tearDownAfterWatchers() throws Throwable {
if (isPUnitTest()) {
((PUnitTest) _testInstance).tearDownAfterWatchers();
}
@@ -118,17 +151,53 @@
}
protected final void startWatchers() {
+ onWatchersStart();
for (int i = 0; i < _watchers.length; ++i) {
+ onWatcherStart(_watchers[i]);
_watchers[i].start();
}
}
+ private void onWatchersStart() {
+ VisitorUtil.traverse(_watcherEventListeners.iterator(), new Visitor() {
+ public void visit(Object obj) {
+ ((WatcherEventListener) obj).onWatchersStart();
+ }
+ });
+ }
+
+ private void onWatcherStart(final Watcher watcher) {
+ VisitorUtil.traverse(_watcherEventListeners.iterator(), new Visitor() {
+ public void visit(Object obj) {
+ ((WatcherEventListener) obj).onWatcherStart(watcher);
+ }
+ });
+ }
+
protected final void stopWatchers() {
for (int i = 0; i < _watchers.length; ++i) {
_watchers[i].stop();
+ onWatcherEnd(_watchers[i]);
}
+ onWatchersEnd();
}
+ private void onWatcherEnd(final Watcher watcher) {
+ VisitorUtil.traverse(_methodEventListeners.iterator(), new Visitor() {
+ public void visit(Object obj) {
+ ((WatcherEventListener) obj).onWatcherEnd(watcher);
+ }
+ });
+ }
+
+ private void onWatchersEnd() {
+ VisitorUtil.traverse(_methodEventListeners.iterator(), new Visitor() {
+ public void visit(Object obj) {
+ ((WatcherEventListener) obj).onWatchersEnd();
+ }
+ });
+ }
+
protected final Object[] watchersValues() {
Object[] values = new Object[_watchers.length];
for (int i = 0; i < _watchers.length; ++i) {
@@ -140,4 +209,21 @@
private boolean isPUnitTest() {
return PUnitTest.class.isAssignableFrom(_class);
}
+
+ public void addMethodEventListener(MethodEventListener listener) {
+ _methodEventListeners.add(listener);
+ }
+
+ public void removeMethodEventListener(MethodEventListener listener) {
+ _methodEventListeners.remove(listener);
+ }
+
+ public void addWatcherEventListener(WatcherEventListener listener) {
+ _watcherEventListeners.add(listener);
+ }
+
+ public void removeWatcherEventListener(WatcherEventListener listener) {
+ _watcherEventListeners.remove(listener);
+ }
+
}
Modified: trunk/punit/src/org/punit/runner/method/ConcurrentTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/ConcurrentTestMethodRunner.java 2007-05-12 13:13:40 UTC (rev 28)
+++ trunk/punit/src/org/punit/runner/method/ConcurrentTestMethodRunner.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -38,7 +38,7 @@
}
}
- protected void setUpBeforeWatchers() {
+ protected void setUpBeforeWatchers() throws Throwable {
super.setUpBeforeWatchers();
Concurrent concurrentTestInstance = (Concurrent) _testInstance;
int threadCount = concurrentTestInstance.concurrentCount();
Modified: trunk/punit/src/org/punit/runner/method/TestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/TestMethodRunner.java 2007-05-12 13:13:40 UTC (rev 28)
+++ trunk/punit/src/org/punit/runner/method/TestMethodRunner.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -2,13 +2,16 @@
import java.lang.reflect.*;
-public interface TestMethodRunner {
+import org.punit.events.*;
+
+public interface TestMethodRunner extends MethodEvent, WatcherEvent {
/**
* Runs the test method, and returns the watcher values.
* @param clazz
* @param method
* @return
*/
- public Object[] run(Object testInstance, Method method, Object[] params) throws Throwable;
+ public void run(Object testInstance, Method method, Object[] params);
+
}
Modified: trunk/punit/src/org/punit/type/PUnitTest.java
===================================================================
--- trunk/punit/src/org/punit/type/PUnitTest.java 2007-05-12 13:13:40 UTC (rev 28)
+++ trunk/punit/src/org/punit/type/PUnitTest.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -1,13 +1,13 @@
package org.punit.type;
public interface PUnitTest {
-
- public void setUpBeforeWatchers();
-
- public void setUpAfterWatchers();
- public void tearDownBeforeWatchers();
-
- public void tearDownAfterWatchers();
-
+ public void setUpBeforeWatchers() throws Exception;
+
+ public void setUpAfterWatchers() throws Exception;
+
+ public void tearDownBeforeWatchers() throws Exception;
+
+ public void tearDownAfterWatchers() throws Exception;
+
}
Modified: trunk/punit/src/org/punit/util/LoggerUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/LoggerUtil.java 2007-05-12 13:13:40 UTC (rev 28)
+++ trunk/punit/src/org/punit/util/LoggerUtil.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -1,19 +1,11 @@
package org.punit.util;
import java.lang.reflect.*;
-import java.util.logging.*;
-import org.punit.logger.*;
-
public class LoggerUtil {
- public static void logMethod(Method method) {
- PUnitLogger.log(simpleMethodName(method), Level.FINE);
- }
public static String simpleMethodName(Method method) {
StringBuffer sb = new StringBuffer();
- sb.append(method.getDeclaringClass().getName());
- sb.append(".");
sb.append(method.getName());
sb.append("(");
Class[] params = method.getParameterTypes();
Modified: trunk/punit/src/org/punit/watcher/MemoryWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-12 13:13:40 UTC (rev 28)
+++ trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -32,6 +32,7 @@
_maxUsedMemory = usedMemory;
}
}
+
private class MemoryWatcherThread extends Thread {
public void run() {
while(!_stop) {
@@ -40,4 +41,8 @@
}
}
}
+
+ public String stringValue() {
+ return value() + "bytes";
+ }
}
Modified: trunk/punit/src/org/punit/watcher/TimeWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-12 13:13:40 UTC (rev 28)
+++ trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -36,4 +36,8 @@
public Object value() {
return (_endTime - _startTime)/1000000;
}
+
+ public String stringValue() {
+ return value() + "ms";
+ }
}
Modified: trunk/punit/src/org/punit/watcher/Watcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/Watcher.java 2007-05-12 13:13:40 UTC (rev 28)
+++ trunk/punit/src/org/punit/watcher/Watcher.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -8,4 +8,6 @@
public Object value();
+ public String stringValue();
+
}
Modified: trunk/punit.test/src/tests/api/org/punit/logger/PUnitLoggerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/logger/PUnitLoggerTest.java 2007-05-12 13:13:40 UTC (rev 28)
+++ trunk/punit.test/src/tests/api/org/punit/logger/PUnitLoggerTest.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -8,45 +8,37 @@
import org.punit.logger.*;
public class PUnitLoggerTest extends TestCase {
- private static MockPrintStream _mockPrintStream = new MockPrintStream(
- System.err);
+ LogListener _logger = new LogListener();
- static {
- PUnitLogger.setOutputStream(_mockPrintStream);
- }
+ private MockPrintStream _mockPrintStream;
protected void setUp() throws Exception {
- reset();
+ _mockPrintStream = new MockPrintStream(System.err);
+ _logger.setOutputStream(_mockPrintStream);
}
-
- protected void tearDown() {
- PUnitLogger.reset();
- }
- public void test() {
- PUnitLogger.setLogLevel(Level.ALL);
- PUnitLogger.log(null, Level.INFO);
+ public void test1() {
+ _logger.setLogLevel(Level.ALL);
+ _logger.log(null, Level.INFO);
assertPrinted();
-
- PUnitLogger.setLogLevel(Level.INFO);
- reset();
- PUnitLogger.log(null, Level.SEVERE);
+ }
+
+ public void test2() {
+ _logger.setLogLevel(Level.INFO);
+ _logger.log(null, Level.SEVERE);
assertPrinted();
-
- reset();
- PUnitLogger.log(null, Level.FINE);
+ }
+
+ public void test3() {
+ _logger.setLogLevel(Level.FINE);
+ _logger.log(null, Level.FINER);
assertNotPrinted();
-
}
- private void reset() {
- _mockPrintStream._printed = false;
- }
-
private void assertPrinted() {
assertTrue(_mockPrintStream._printed);
}
-
+
private void assertNotPrinted() {
assertFalse(_mockPrintStream._printed);
}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestSample.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestSample.java 2007-05-12 13:13:40 UTC (rev 28)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/ParameterizableTestSample.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -11,11 +11,9 @@
}
public void test1(Parameter param) {
- System.out.println("test1 " + param);
}
public void test2() {
- System.out.println("test2");
}
public Parameter[] parameters() {
Modified: trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java 2007-05-12 13:13:40 UTC (rev 28)
+++ trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java 2007-05-12 22:14:09 UTC (rev 29)
@@ -9,28 +9,26 @@
public class LoggerUtilTest extends TestCase {
- private static final String CLASS_NAME = LoggerUtilTest.class.getName();
-
public void testSimpleMethodName() {
Method method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f",
new Class[] {});
String simpleMethodName = LoggerUtil.simpleMethodName(method);
- assertEquals(CLASS_NAME + ".f()", simpleMethodName);
+ assertEquals("f()", simpleMethodName);
method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f",
new Class[] { Parameter.class });
simpleMethodName = LoggerUtil.simpleMethodName(method);
- assertEquals(CLASS_NAME + ".f(Parameter)", simpleMethodName);
+ assertEquals("f(Parameter)", simpleMethodName);
method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f",
new Class[] { int.class });
simpleMethodName = LoggerUtil.simpleMethodName(method);
- assertEquals(CLASS_NAME + ".f(int)", simpleMethodName);
+ assertEquals("f(int)", simpleMethodName);
method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f",
new Class[] { int[].class });
simpleMethodName = LoggerUtil.simpleMethodName(method);
- assertEquals(CLASS_NAME + ".f(int[])", simpleMethodName);
+ assertEquals("f(int[])", simpleMethodName);
}
public void f() {
Modified: trunk/punit.test/src/tests/sample/testcase/ConcurrentParameterizableTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/ConcurrentParameterizableTestSample.java 2007-05-12 13:13:40 UTC (rev 28)
+++ trunk/punit.test/src/tests/s...
[truncated message content] |
|
From: <zha...@us...> - 2007-05-13 08:48:39
|
Revision: 36
http://p-unit.svn.sourceforge.net/p-unit/?rev=36&view=rev
Author: zhanghuangzhu
Date: 2007-05-13 01:48:40 -0700 (Sun, 13 May 2007)
Log Message:
-----------
Andrew Zhang: implemented FileLoggerListener.
Modified Paths:
--------------
trunk/punit/src/org/punit/logger/StreamLoggerListener.java
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit.test/src/tests/api/org/punit/logger/PUnitLoggerTest.java
Added Paths:
-----------
trunk/punit/src/org/punit/logger/FileLoggerListener.java
Added: trunk/punit/src/org/punit/logger/FileLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/logger/FileLoggerListener.java (rev 0)
+++ trunk/punit/src/org/punit/logger/FileLoggerListener.java 2007-05-13 08:48:40 UTC (rev 36)
@@ -0,0 +1,28 @@
+package org.punit.logger;
+
+import java.io.*;
+
+public class FileLoggerListener extends StreamLoggerListener {
+
+ public void onRunnerStart(Class clazz) {
+ initResultFolder();
+ String fileName = "result/result_." + clazz.getName() + ".txt";
+ try {
+ PrintStream ps = new PrintStream(fileName);
+ setOutputStream(ps);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ super.onRunnerStart(clazz);
+ }
+
+ private void initResultFolder() {
+ new File("result").delete();
+ new File("result").mkdir();
+ }
+
+ public void onRunnerEnd(Class clazz) {
+ super.onRunnerEnd(clazz);
+ _ps.close();
+ }
+}
Modified: trunk/punit/src/org/punit/logger/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/logger/StreamLoggerListener.java 2007-05-13 08:16:15 UTC (rev 35)
+++ trunk/punit/src/org/punit/logger/StreamLoggerListener.java 2007-05-13 08:48:40 UTC (rev 36)
@@ -18,9 +18,13 @@
public Level _level = Level.FINE;
+ public StreamLoggerListener() {
+ }
+
public StreamLoggerListener(PrintStream ps) {
_ps = ps;
}
+
public void onRunnerStart(Class clazz) {
_summary.start();
log("Started to run " + clazz.getName() + "\n", Level.INFO);
@@ -29,7 +33,6 @@
public void onRunnerEnd(Class clazz) {
_summary.stop();
_summary.log(this);
- ;
}
public void onClassStart(Class clazz) {
@@ -131,7 +134,9 @@
public void log(final StreamLoggerListener logger) {
StringBuffer sb = new StringBuffer("Total: ");
sb.append(_methodCount);
+ sb.append(", failures: ");
int failures = _throwableList.size();
+ sb.append(failures);
if (failures == 0) {
sb.append(" (GREEN) - ");
} else {
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-13 08:16:15 UTC (rev 35)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-13 08:48:40 UTC (rev 36)
@@ -13,29 +13,33 @@
public abstract class PUnitAbstractRunner implements Runner {
private TestSuiteBuilder _testSuiteBuiler;
-
+
private TestMethodBuilder _testMethodBuilder;
-
+
private TestMethodRunner _testMethodRunner;
-
+
private List _runnerEventListeners = new ArrayList();
-
+
private List _classEventListeners = new ArrayList();
-
+
private ConsoleLoggerListener _consoleLogger = new ConsoleLoggerListener();
- public PUnitAbstractRunner(TestSuiteBuilder testSuiteBuiler, TestMethodBuilder testMethodBuilder, TestMethodRunner testMethodRunner) {
+ private FileLoggerListener _fileLogger = new FileLoggerListener();
+
+ public PUnitAbstractRunner(TestSuiteBuilder testSuiteBuiler,
+ TestMethodBuilder testMethodBuilder,
+ TestMethodRunner testMethodRunner) {
_testSuiteBuiler = testSuiteBuiler;
_testMethodBuilder = testMethodBuilder;
_testMethodRunner = testMethodRunner;
- registerLogListener();
+ registerLoggerListeners();
}
- public Result run(Class clazz) {
+ public Result run(Class clazz) {
onRunnerStart(clazz);
Object[] testClasses = _testSuiteBuiler.buildTestClasses(clazz);
for (int i = 0; i < testClasses.length; ++i) {
- runTestClass((Class)testClasses[i]);
+ runTestClass((Class) testClasses[i]);
}
onRunnerEnd(clazz);
return null;
@@ -44,26 +48,26 @@
private void onRunnerStart(final Class clazz) {
VisitorUtil.traverse(_runnerEventListeners.iterator(), new Visitor() {
public void visit(Object obj) {
- ((RunnerEventListener)obj).onRunnerStart(clazz);
+ ((RunnerEventListener) obj).onRunnerStart(clazz);
}
});
}
-
+
private void onRunnerEnd(final Class clazz) {
VisitorUtil.traverse(_runnerEventListeners.iterator(), new Visitor() {
public void visit(Object obj) {
- ((RunnerEventListener)obj).onRunnerEnd(clazz);
+ ((RunnerEventListener) obj).onRunnerEnd(clazz);
}
});
}
-
+
private void runTestClass(Class clazz) {
- if(!accept(clazz)) {
+ if (!accept(clazz)) {
return;
}
onClassStart(clazz);
Object[] testMethods = buildTestMethod(clazz);
- for(int i = 0; i < testMethods.length; ++i) {
+ for (int i = 0; i < testMethods.length; ++i) {
Method method = (Method) testMethods[i];
runTestMethod(clazz, method);
}
@@ -73,22 +77,20 @@
private void onClassStart(final Class clazz) {
VisitorUtil.traverse(_classEventListeners.iterator(), new Visitor() {
public void visit(Object obj) {
- ((ClassEventListener)obj).onClassStart(clazz);
+ ((ClassEventListener) obj).onClassStart(clazz);
}
});
}
-
+
private void onClassEnd(final Class clazz) {
VisitorUtil.traverse(_classEventListeners.iterator(), new Visitor() {
public void visit(Object obj) {
- ((ClassEventListener)obj).onClassEnd(clazz);
+ ((ClassEventListener) obj).onClassEnd(clazz);
}
});
}
-
private void runTestMethod(Class clazz, Method method) {
- // TODO: add run result to the test result
Object testInstance = ReflectionUtil.newInstance(clazz);
try {
if (needsRunParameterizable(clazz)) {
@@ -104,7 +106,7 @@
} catch (Throwable e) {
e.printStackTrace();
}
-
+
}
private boolean needsRunParameterizable(Class clazz) {
@@ -114,7 +116,7 @@
private boolean isParameterizableRunner() {
return (this instanceof ParameterizableRunner);
}
-
+
private boolean isParameterizable(Class clazz) {
return Parameterizable.class.isAssignableFrom(clazz);
}
@@ -122,7 +124,7 @@
private Object[] buildTestMethod(Class testClass) {
return _testMethodBuilder.buildTestMethods(testClass);
}
-
+
public abstract boolean accept(Class testClass);
public TestMethodBuilder testMethodBuilder() {
@@ -144,7 +146,7 @@
public void removeRunnerEventListener(RunnerEventListener listener) {
_runnerEventListeners.remove(listener);
}
-
+
public void addClassEventListener(ClassEventListener listener) {
_classEventListeners.add(listener);
}
@@ -153,20 +155,38 @@
_classEventListeners.remove(listener);
}
- private void registerLogListener() {
- addRunnerEventListener(_consoleLogger);
- addClassEventListener(_consoleLogger);
- _testMethodRunner.addMethodEventListener(_consoleLogger);
- _testMethodRunner.addWatcherEventListener(_consoleLogger);
+ private void registerLoggerListeners() {
+ registerStreamLoggerListener(_consoleLogger);
+ registerStreamLoggerListener(_fileLogger);
}
-
- public void removeLogListener() {
- removeClassEventListener(_consoleLogger);
- _testMethodRunner.removeMethodEventListener(_consoleLogger);
- _testMethodRunner.removeWatcherEventListener(_consoleLogger);
+
+ private void registerStreamLoggerListener(StreamLoggerListener logger) {
+ addRunnerEventListener(logger);
+ addClassEventListener(logger);
+ _testMethodRunner.addMethodEventListener(logger);
+ _testMethodRunner.addWatcherEventListener(logger);
}
- public StreamLoggerListener consoleLogger() {
+ public void removeConsoleLogger() {
+ removeStreamLoggerListener(_consoleLogger);
+ }
+
+ public void removeFileLogger() {
+ removeStreamLoggerListener(_fileLogger);
+ }
+
+ private void removeStreamLoggerListener(StreamLoggerListener logger) {
+ removeRunnerEventListener(logger);
+ removeClassEventListener(logger);
+ _testMethodRunner.removeMethodEventListener(logger);
+ _testMethodRunner.removeWatcherEventListener(logger);
+ }
+
+ public ConsoleLoggerListener consoleLogger() {
return _consoleLogger;
}
+
+ public FileLoggerListener fileLogger() {
+ return _fileLogger;
+ }
}
Modified: trunk/punit.test/src/tests/api/org/punit/logger/PUnitLoggerTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/logger/PUnitLoggerTest.java 2007-05-13 08:16:15 UTC (rev 35)
+++ trunk/punit.test/src/tests/api/org/punit/logger/PUnitLoggerTest.java 2007-05-13 08:48:40 UTC (rev 36)
@@ -8,7 +8,7 @@
import org.punit.logger.*;
public class PUnitLoggerTest extends TestCase {
- LogListener _logger = new LogListener();
+ ConsoleLoggerListener _logger = new ConsoleLoggerListener();
private MockPrintStream _mockPrintStream;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-13 09:23:02
|
Revision: 38
http://p-unit.svn.sourceforge.net/p-unit/?rev=38&view=rev
Author: zhanghuangzhu
Date: 2007-05-13 02:23:00 -0700 (Sun, 13 May 2007)
Log Message:
-----------
Andrew Zhang: refactored isTestMethod and began to externalize strings.
Modified Paths:
--------------
trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java
trunk/punit/src/org/punit/builder/PUnitParameterizableTestMethodBuilder.java
trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java
trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java
trunk/punit.test/src/tests/util/AssertUtil.java
Added Paths:
-----------
trunk/punit/.settings/
trunk/punit/.settings/org.eclipse.core.resources.prefs
trunk/punit/src/org/punit/message/
trunk/punit/src/org/punit/message/Messages.java
trunk/punit/src/punit.properties
Added: trunk/punit/.settings/org.eclipse.core.resources.prefs
===================================================================
--- trunk/punit/.settings/org.eclipse.core.resources.prefs (rev 0)
+++ trunk/punit/.settings/org.eclipse.core.resources.prefs 2007-05-13 09:23:00 UTC (rev 38)
@@ -0,0 +1,3 @@
+#Sun May 13 17:10:01 CST 2007
+eclipse.preferences.version=1
+encoding//src/punit.properties=8859_1
Modified: trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java 2007-05-13 09:02:21 UTC (rev 37)
+++ trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java 2007-05-13 09:23:00 UTC (rev 38)
@@ -3,6 +3,8 @@
import java.lang.reflect.*;
import java.util.*;
+import org.punit.*;
+import org.punit.message.*;
import org.punit.type.*;
import org.punit.util.*;
@@ -27,7 +29,19 @@
return testMethods.toArray();
}
- protected abstract boolean isTestMethod(Method method);
+ protected boolean isTestMethod(Method method) {
+ return isModifierValid(method) && isNameValid(method) && isParamValid(method);
+ }
+
+ protected boolean isModifierValid(Method method) {
+ return ReflectionUtil.isPublic(method) && !ReflectionUtil.isStatic(method);
+ }
+
+ protected boolean isNameValid(Method method) {
+ return method.getName().startsWith("test"); //$NON-NLS-1$
+ }
+
+ protected abstract boolean isParamValid(Method method);
private void checkTestClass(Class testClass) {
if (isCompetitiveTestSuite(testClass)) {
@@ -44,7 +58,7 @@
Class implementor = implementors[i];
if (!competitiveInterface.isAssignableFrom(implementor)) {
throw new IllegalArgumentException(implementor
- + " should implement " + competitiveInterface);
+ + Messages.getString("builder.01") + competitiveInterface); //$NON-NLS-1$
}
}
}
Modified: trunk/punit/src/org/punit/builder/PUnitParameterizableTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitParameterizableTestMethodBuilder.java 2007-05-13 09:02:21 UTC (rev 37)
+++ trunk/punit/src/org/punit/builder/PUnitParameterizableTestMethodBuilder.java 2007-05-13 09:23:00 UTC (rev 38)
@@ -3,26 +3,10 @@
import java.lang.reflect.*;
import org.punit.type.*;
-import org.punit.util.*;
public class PUnitParameterizableTestMethodBuilder extends PUnitAbstractTestMethodBuilder {
- /**
- *
- * Returns true if the method is public, not static, and has
- * one Parameter argument and starts with "test",.
- *
- * @param method
- * @return true if it is a test method
- */
- protected boolean isTestMethod(Method method) {
- String name = method.getName();
- return ReflectionUtil.isPublic(method)
- && !ReflectionUtil.isStatic(method) && hasOnlyParameterParam(method)
- && name.startsWith("test");
- }
-
- private boolean hasOnlyParameterParam(Method method) {
+ protected boolean isParamValid(Method method) {
Class[] params = method.getParameterTypes();
return params.length == 1 && Parameter.class.isAssignableFrom(params[0]);
}
Modified: trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java 2007-05-13 09:02:21 UTC (rev 37)
+++ trunk/punit/src/org/punit/builder/PUnitTestMethodBuilder.java 2007-05-13 09:23:00 UTC (rev 38)
@@ -2,28 +2,10 @@
import java.lang.reflect.*;
-import org.punit.util.*;
-
public class PUnitTestMethodBuilder extends PUnitAbstractTestMethodBuilder {
- /**
- * Returns true if this method is regarded as a test method. Might be
- * overriden by the subclass for convenience.
- *
- * Returns true if the method is public, not static, and has
- * zero argument and starts with "test",.
- *
- * @param method
- * @return true if it is a test method
- */
- protected boolean isTestMethod(Method method) {
- String name = method.getName();
- return ReflectionUtil.isPublic(method)
- && !ReflectionUtil.isStatic(method) && hasNoParam(method)
- && name.startsWith("test");
- }
-
- private boolean hasNoParam(Method method) {
+ protected boolean isParamValid(Method method) {
return method.getParameterTypes().length == 0;
}
+
}
Modified: trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java 2007-05-13 09:02:21 UTC (rev 37)
+++ trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java 2007-05-13 09:23:00 UTC (rev 38)
@@ -29,7 +29,6 @@
}
private void buildTestClassesFromClass(List testClasses, Class clazz) {
- String name = null;
testClasses.add(clazz);
}
Added: trunk/punit/src/org/punit/message/Messages.java
===================================================================
--- trunk/punit/src/org/punit/message/Messages.java (rev 0)
+++ trunk/punit/src/org/punit/message/Messages.java 2007-05-13 09:23:00 UTC (rev 38)
@@ -0,0 +1,21 @@
+package org.punit.message;
+
+import java.util.*;
+
+public class Messages {
+ private static final String BUNDLE_NAME = "punit"; //$NON-NLS-1$
+
+ private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
+ .getBundle(BUNDLE_NAME);
+
+ private Messages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return RESOURCE_BUNDLE.getString(key);
+ } catch (MissingResourceException e) {
+ return '!' + key + '!';
+ }
+ }
+}
Added: trunk/punit/src/punit.properties
===================================================================
--- trunk/punit/src/punit.properties (rev 0)
+++ trunk/punit/src/punit.properties 2007-05-13 09:23:00 UTC (rev 38)
@@ -0,0 +1 @@
+builder.01=\ should implement
Modified: trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java 2007-05-13 09:02:21 UTC (rev 37)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java 2007-05-13 09:23:00 UTC (rev 38)
@@ -1,6 +1,7 @@
package tests.api.org.punit.builder;
import java.lang.reflect.*;
+
import junit.framework.*;
import org.punit.builder.*;
import tests.api.org.punit.testclasses.*;
@@ -27,9 +28,10 @@
static class MockTestMethodBuilder extends PUnitAbstractTestMethodBuilder {
- protected boolean isTestMethod(Method method) {
- return false;
- }
+ protected boolean isParamValid(Method method) {
+ return false;
+ }
+
}
}
Modified: trunk/punit.test/src/tests/util/AssertUtil.java
===================================================================
--- trunk/punit.test/src/tests/util/AssertUtil.java 2007-05-13 09:02:21 UTC (rev 37)
+++ trunk/punit.test/src/tests/util/AssertUtil.java 2007-05-13 09:23:00 UTC (rev 38)
@@ -45,6 +45,7 @@
code.run();
Assert.fail(throwable + " expected!");
} catch (Throwable e) {
+ e.printStackTrace();
Assert.assertSame(throwable, e.getClass());
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-13 10:02:11
|
Revision: 39
http://p-unit.svn.sourceforge.net/p-unit/?rev=39&view=rev
Author: zhanghuangzhu
Date: 2007-05-13 03:02:07 -0700 (Sun, 13 May 2007)
Log Message:
-----------
Andrew Zhang: externalized strings.
Modified Paths:
--------------
trunk/punit/src/org/punit/exception/ConcurrentException.java
trunk/punit/src/org/punit/logger/FileLoggerListener.java
trunk/punit/src/org/punit/logger/StreamLoggerListener.java
trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java
trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java
trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/util/LoggerUtil.java
trunk/punit/src/org/punit/watcher/MemoryWatcher.java
trunk/punit/src/org/punit/watcher/TimeWatcher.java
trunk/punit/src/punit.properties
trunk/punit.test/src/tests/api/org/punit/builder/PUnitParameterizableTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass2.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestParameter.java
trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java
trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java
Modified: trunk/punit/src/org/punit/exception/ConcurrentException.java
===================================================================
--- trunk/punit/src/org/punit/exception/ConcurrentException.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit/src/org/punit/exception/ConcurrentException.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -19,7 +19,7 @@
}
public void printStackTrace() {
- System.err.println(ConcurrentException.class.getName()+":");
+ System.err.println(ConcurrentException.class.getName()+":"); //$NON-NLS-1$
VisitorUtil.traverse(_throwables.iterator(), new Visitor() {
public void visit(Object obj) {
((Throwable) obj).printStackTrace();
@@ -28,7 +28,7 @@
}
public void printStackTrace(final PrintStream ps) {
- ps.println(ConcurrentException.class.getName() + ":");
+ ps.println(ConcurrentException.class.getName() + ":"); //$NON-NLS-1$
VisitorUtil.traverse(_throwables.iterator(), new Visitor() {
public void visit(Object obj) {
((Throwable) obj).printStackTrace(ps);
@@ -37,7 +37,7 @@
}
public void printStackTrace(final PrintWriter pw) {
- pw.println(ConcurrentException.class.getName() + ":");
+ pw.println(ConcurrentException.class.getName() + ":"); //$NON-NLS-1$
VisitorUtil.traverse(_throwables.iterator(), new Visitor() {
public void visit(Object obj) {
((Throwable) obj).printStackTrace(pw);
@@ -55,7 +55,7 @@
final StringBuffer sb = new StringBuffer();
public void visit(Object obj) {
sb.append(((Throwable) obj));
- sb.append("\n");
+ sb.append(LoggerUtil.LINE_SEPERATOR);
}
}
}
Modified: trunk/punit/src/org/punit/logger/FileLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/logger/FileLoggerListener.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit/src/org/punit/logger/FileLoggerListener.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -24,11 +24,11 @@
}
private void initResultFolder() {
- new File("result").mkdir();
+ new File("result").mkdir(); //$NON-NLS-1$
}
private String generateFileName(Class clazz, Runner runner) {
- return "result/result_." + clazz.getName() + "_" + runner
- + ".txt";
+ return "result/result_." + clazz.getName() + "_" + runner //$NON-NLS-1$ //$NON-NLS-2$
+ + ".txt"; //$NON-NLS-1$
}
}
Modified: trunk/punit/src/org/punit/logger/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/logger/StreamLoggerListener.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit/src/org/punit/logger/StreamLoggerListener.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -6,29 +6,31 @@
import java.util.logging.*;
import org.punit.events.*;
+import org.punit.message.*;
import org.punit.runner.*;
import org.punit.util.*;
import org.punit.watcher.*;
public class StreamLoggerListener implements PUnitEvent {
public PrintStream _ps;
-
+
Summary _summary = new Summary();
-
+
private boolean _watchersStart;
-
+
public Level _level = Level.FINE;
public StreamLoggerListener() {
}
-
+
public StreamLoggerListener(PrintStream ps) {
_ps = ps;
}
-
+
public void onRunnerStart(Class clazz, Runner runner) {
_summary.start();
- log("Started to run " + clazz.getName() + runner + "\n", Level.INFO);
+ log(Messages.getString("logger.01") + clazz.getName() + runner //$NON-NLS-1$
+ + LoggerUtil.LINE_SEPERATOR, Level.INFO);
}
public void onRunnerEnd(Class clazz, Runner runner) {
@@ -37,11 +39,11 @@
}
public void onClassStart(Class clazz) {
- log(clazz.getName() + "\n", Level.INFO);
+ log(clazz.getName() + LoggerUtil.LINE_SEPERATOR, Level.INFO);
}
public void onClassEnd(Class clazz) {
-
+
}
public void onMethodStart(Method method) {
@@ -50,9 +52,9 @@
public void onMethodEnd(Method method, Throwable t) {
_summary.countMethod();
- log("\n", Level.INFO);
+ logln(Level.INFO);
if (t != null) {
- log(t.toString() + "\n", Level.INFO);
+ logln(t.toString(), Level.INFO);
_summary.addThrowable(t);
}
}
@@ -65,16 +67,16 @@
}
public void onWatchersEnd() {
- log("]", Level.FINE);
+ log("]", Level.FINE); //$NON-NLS-1$
}
public void onWatcherEnd(Watcher watch) {
- String watchValue = watch.stringValue();
- if(_watchersStart) {
- log(" - [" + watchValue, Level.FINE);
- } else {
- log("," + watch.stringValue(), Level.FINE);
- }
+ String watchValue = watch.stringValue();
+ if (_watchersStart) {
+ log(" - [" + watchValue, Level.FINE); //$NON-NLS-1$
+ } else {
+ log("," + watch.stringValue(), Level.FINE); //$NON-NLS-1$
+ }
_watchersStart = false;
}
@@ -86,6 +88,14 @@
_ps = ps;
}
+ public void logln(Level level) {
+ log(LoggerUtil.LINE_SEPERATOR, level);
+ }
+
+ public void logln(String message, Level level) {
+ log(message + LoggerUtil.LINE_SEPERATOR, level);
+ }
+
public void log(String message, Level level) {
if (_ps == null) {
return;
@@ -125,32 +135,34 @@
*
* or:
*
- * Total: 2 (RED) - 120ms
- * 1)java.lang.IllegalArgumentException
- * at tests.SimpleTestSample.test1(SimpleTestSample.java:20)
- * 2)java.lang.NullPointerException
- * at tests.SimpleTestSample.test2(SimpleTestSample.java:24)
+ * Total: 2 (RED) - 120ms 1)java.lang.IllegalArgumentException at
+ * tests.SimpleTestSample.test1(SimpleTestSample.java:20)
+ * 2)java.lang.NullPointerException at
+ * tests.SimpleTestSample.test2(SimpleTestSample.java:24)
*
*/
public void log(final StreamLoggerListener logger) {
- StringBuffer sb = new StringBuffer("Total: ");
+ StringBuffer sb = new StringBuffer();
+ sb.append(Messages.getString("logger.02")); //$NON-NLS-1$
+ sb.append(" "); //$NON-NLS-1$
sb.append(_methodCount);
- sb.append(", failures: ");
+ sb.append(", "); //$NON-NLS-1$
+ sb.append(Messages.getString("logger.03")); //$NON-NLS-1$
int failures = _throwableList.size();
sb.append(failures);
+ sb.append(" ("); //$NON-NLS-1$
if (failures == 0) {
- sb.append(" (GREEN) - ");
+ sb.append(Messages.getString("logger.04")); //$NON-NLS-1$
} else {
- sb.append(" (RED) - ");
+ sb.append(Messages.getString("logger.05")); //$NON-NLS-1$
}
sb.append(_timeWatcher.stringValue());
- sb.append("\n");
+ sb.append(LoggerUtil.LINE_SEPERATOR);
logger.log(sb.toString(), Level.INFO);
VisitorUtil.traverse(_throwableList.iterator(), new Visitor() {
int count = 0;
-
public void visit(Object obj) {
- logger.log(++count + ")", Level.INFO);
+ logger.log(++count + ")", Level.INFO); //$NON-NLS-1$
((Throwable) obj).printStackTrace(logger._ps);
}
});
Modified: trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -1,6 +1,7 @@
package org.punit.runner;
import org.punit.builder.*;
+import org.punit.message.*;
import org.punit.runner.method.*;
import org.punit.type.*;
@@ -19,7 +20,7 @@
}
public String toString() {
- return "concurrent_parameterizable";
+ return Messages.getString("runner.04"); //$NON-NLS-1$
}
}
Modified: trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -1,6 +1,7 @@
package org.punit.runner;
import org.punit.builder.*;
+import org.punit.message.*;
import org.punit.runner.method.*;
import org.punit.type.*;
@@ -15,7 +16,7 @@
}
public String toString() {
- return "concurrent";
+ return Messages.getString("runner.03"); //$NON-NLS-1$
}
}
Modified: trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -1,6 +1,7 @@
package org.punit.runner;
import org.punit.builder.*;
+import org.punit.message.*;
import org.punit.runner.method.*;
import org.punit.type.*;
@@ -15,7 +16,7 @@
}
public String toString() {
- return "solo_parameterizable";
+ return Messages.getString("runner.02"); //$NON-NLS-1$
}
Modified: trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -1,6 +1,7 @@
package org.punit.runner;
import org.punit.builder.*;
+import org.punit.message.*;
import org.punit.runner.method.*;
public class PUnitSoloRunner extends PUnitAbstractRunner {
@@ -15,7 +16,7 @@
}
public String toString() {
- return "solo";
+ return Messages.getString("runner.01"); //$NON-NLS-1$
}
}
Modified: trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -90,9 +90,9 @@
_params = params;
_method = method;
_setUpMethod = ReflectionUtil.getMethodAndSetAccessible(_testInstance
- .getClass(), "setUp", new Class[] {});
+ .getClass(), "setUp", new Class[] {}); //$NON-NLS-1$
_tearDownMethod = ReflectionUtil.getMethodAndSetAccessible(
- _testInstance.getClass(), "tearDown", new Class[] {});
+ _testInstance.getClass(), "tearDown", new Class[] {}); //$NON-NLS-1$
}
/**
Modified: trunk/punit/src/org/punit/util/LoggerUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/LoggerUtil.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit/src/org/punit/util/LoggerUtil.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -3,20 +3,25 @@
import java.lang.reflect.*;
public class LoggerUtil {
+ public final static String LINE_SEPERATOR;
+ static {
+ LINE_SEPERATOR = System.getProperty("line.separator"); //$NON-NLS-1$
+ }
+
public static String simpleMethodName(Method method) {
StringBuffer sb = new StringBuffer();
sb.append(method.getName());
- sb.append("(");
+ sb.append("("); //$NON-NLS-1$
Class[] params = method.getParameterTypes();
for(int i = 0; i < params.length - 1 ; ++i) {
sb.append(params[i].getSimpleName());
- sb.append(", ");
+ sb.append(", "); //$NON-NLS-1$
}
if(params.length > 0) {
sb.append(params[params.length - 1].getSimpleName());
}
- sb.append(")");
+ sb.append(")"); //$NON-NLS-1$
return sb.toString();
}
Modified: trunk/punit/src/org/punit/watcher/MemoryWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -1,5 +1,6 @@
package org.punit.watcher;
+import org.punit.message.*;
import org.punit.util.*;
public class MemoryWatcher implements Watcher {
@@ -43,6 +44,6 @@
}
public String stringValue() {
- return value() + "bytes";
+ return value() + Messages.getString("watcher.01"); //$NON-NLS-1$
}
}
Modified: trunk/punit/src/org/punit/watcher/TimeWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -19,6 +19,8 @@
package org.punit.watcher;
+import org.punit.message.*;
+
public class TimeWatcher implements Watcher {
private long _startTime;
@@ -38,6 +40,6 @@
}
public String stringValue() {
- return value() + "ms";
+ return value() + Messages.getString("watcher.02"); //$NON-NLS-1$
}
}
Modified: trunk/punit/src/punit.properties
===================================================================
--- trunk/punit/src/punit.properties 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit/src/punit.properties 2007-05-13 10:02:07 UTC (rev 39)
@@ -1 +1,12 @@
-builder.01=\ should implement
+builder.01=\ should implement
+logger.01=\ Started running
+logger.02=\ total:
+logger.03=\ failures:
+logger.04=\ GREEN
+logger.05=\ RED
+runner.01=solo
+runner.02=solo_parameterizable
+runner.03=concurrent
+runner.04=concurrent_parameterizable
+watcher.01=bytes
+watcher.02=ms
Modified: trunk/punit.test/src/tests/api/org/punit/builder/PUnitParameterizableTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitParameterizableTestMethodBuilderTest.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitParameterizableTestMethodBuilderTest.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -19,7 +19,7 @@
Object[] methods = _testMethodBuidler.buildTestMethods(ParameterizableTestClass.class);
assertEquals(2, methods.length);
String[] names = TestUtil.toMethodNameArray(methods);
- AssertUtil.assertArrayContent(names, new String[] { "test1", "test3" });
+ AssertUtil.assertArrayContent(names, new String[] { "test1", "test3" }); //$NON-NLS-1$//$NON-NLS-2$
}
public void test2() {
Modified: trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitTestMethodBuilderTest.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -17,21 +17,21 @@
public void testBuildTestMethods1() {
Object[] methods = _testMethodBuidler.buildTestMethods(TestClass1.class);
String[] names = TestUtil.toMethodNameArray(methods);
- AssertUtil.assertArrayContent(names, new String[] { "test1", "test2",
- "testa", "testb" });
+ AssertUtil.assertArrayContent(names, new String[] { "test1", "test2", //$NON-NLS-1$ //$NON-NLS-2$
+ "testa", "testb" }); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testBuildTestMethods2() {
Object[] methods = _testMethodBuidler.buildTestMethods(TestClass2.class);
String[] names = TestUtil.toMethodNameArray(methods);
- AssertUtil.assertArrayContent(names, new String[] { "test1", "test2",
- "testa", "testb" });
+ AssertUtil.assertArrayContent(names, new String[] { "test1", "test2", //$NON-NLS-1$ //$NON-NLS-2$
+ "testa", "testb" }); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testBuildTestMethods3() {
Object[] methods = _testMethodBuidler.buildTestMethods(TestClass3.class);
String[] names = TestUtil.toMethodNameArray(methods);
- AssertUtil.assertArray(names, new String[] { "test1", "test2", "testa",
- "testb" });
+ AssertUtil.assertArray(names, new String[] { "test1", "test2", "testa", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ "testb" }); //$NON-NLS-1$
}
}
Modified: trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit.test/src/tests/api/org/punit/exception/ConcurrentExceptionTest.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -1,17 +1,18 @@
package tests.api.org.punit.exception;
import org.punit.exception.*;
+import org.punit.util.*;
import junit.framework.*;
public class ConcurrentExceptionTest extends TestCase {
public void testGetMessage() {
ConcurrentException concurrentException = new ConcurrentException();
- NullPointerException npe = new NullPointerException("NPE");
+ NullPointerException npe = new NullPointerException("NPE"); //$NON-NLS-1$
concurrentException.add(npe);
- IllegalArgumentException iae = new IllegalArgumentException("IAE");
+ IllegalArgumentException iae = new IllegalArgumentException("IAE"); //$NON-NLS-1$
concurrentException.add(iae);
String message = concurrentException.getMessage();
- assertEquals(npe + "\n" + iae + "\n", message);
+ assertEquals(npe + LoggerUtil.LINE_SEPERATOR + iae + LoggerUtil.LINE_SEPERATOR, message);
}
}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass1.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass1.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass1.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -18,11 +18,11 @@
}
public void test1() {
- System.out.println("test1");
+ System.out.println("test1"); //$NON-NLS-1$
}
public void test2() {
- System.out.println("test2");
+ System.out.println("test2"); //$NON-NLS-1$
}
public int competitiveID() {
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass2.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass2.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass2.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -18,11 +18,11 @@
}
public void test1() {
- System.out.println("test1");
+ System.out.println("test1"); //$NON-NLS-1$
}
public void test2() {
- System.out.println("test2");
+ System.out.println("test2"); //$NON-NLS-1$
}
public int competitiveID() {
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/TestParameter.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestParameter.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestParameter.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -10,6 +10,6 @@
}
public String toString() {
- return "param: " + value;
+ return "param: " + value; //$NON-NLS-1$
}
}
\ No newline at end of file
Modified: trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit.test/src/tests/api/org/punit/util/LoggerUtilTest.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -10,25 +10,25 @@
public class LoggerUtilTest extends TestCase {
public void testSimpleMethodName() {
- Method method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f",
+ Method method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f", //$NON-NLS-1$
new Class[] {});
String simpleMethodName = LoggerUtil.simpleMethodName(method);
- assertEquals("f()", simpleMethodName);
+ assertEquals("f()", simpleMethodName); //$NON-NLS-1$
- method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f",
+ method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f", //$NON-NLS-1$
new Class[] { Parameter.class });
simpleMethodName = LoggerUtil.simpleMethodName(method);
- assertEquals("f(Parameter)", simpleMethodName);
+ assertEquals("f(Parameter)", simpleMethodName); //$NON-NLS-1$
- method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f",
+ method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f", //$NON-NLS-1$
new Class[] { int.class });
simpleMethodName = LoggerUtil.simpleMethodName(method);
- assertEquals("f(int)", simpleMethodName);
+ assertEquals("f(int)", simpleMethodName); //$NON-NLS-1$
- method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f",
+ method = ReflectionUtil.getMethod(LoggerUtilTest.class, "f", //$NON-NLS-1$
new Class[] { int[].class });
simpleMethodName = LoggerUtil.simpleMethodName(method);
- assertEquals("f(int[])", simpleMethodName);
+ assertEquals("f(int[])", simpleMethodName); //$NON-NLS-1$
}
public void f() {
Modified: trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java 2007-05-13 09:23:00 UTC (rev 38)
+++ trunk/punit.test/src/tests/api/org/punit/util/ReflectionUtilTest.java 2007-05-13 10:02:07 UTC (rev 39)
@@ -23,31 +23,31 @@
}
public void testGetMethod() {
- Method method = ReflectionUtil.getMethod(Test1.class, "test1",
+ Method method = ReflectionUtil.getMethod(Test1.class, "test1", //$NON-NLS-1$
new Class[] {});
assertNotNull(method);
- method = ReflectionUtil.getMethod(Test1.class, "test2", new Class[] {});
+ method = ReflectionUtil.getMethod(Test1.class, "test2", new Class[] {}); //$NON-NLS-1$
assertNull(method);
- method = ReflectionUtil.getMethod(Test1.class, "test4", new Class[] {});
+ method = ReflectionUtil.getMethod(Test1.class, "test4", new Class[] {}); //$NON-NLS-1$
assertNull(method);
}
public void testGetMethodAndSetAccessible() {
Test1 obj = new Test1();
Method method = ReflectionUtil.getMethodAndSetAccessible(Test1.class,
- "test1", new Class[] {});
+ "test1", new Class[] {}); //$NON-NLS-1$
ReflectionUtil.invokeMethod(method, obj, new Object[] {});
method = ReflectionUtil.getMethodAndSetAccessible(Test1.class,
- "test3", new Class[] {});
+ "test3", new Class[] {}); //$NON-NLS-1$
ReflectionUtil.invokeMethod(method, obj, new Object[] {});
}
public void testInvokeMethod() {
final Test1 obj = new Test1();
- final Method method = ReflectionUtil.getMethod(Test1.class, "test1",
+ final Method method = ReflectionUtil.getMethod(Test1.class, "test1", //$NON-NLS-1$
new Class[] {});
AssertUtil.assertException(ReflectionException.class, new CodeRunner() {
@@ -60,7 +60,7 @@
ReflectionUtil.invokeMethod(method, obj, new Object[] {});
assertEquals(10, obj.value);
- final Method method2 = ReflectionUtil.getMethod(Test1.class, "test2",
+ final Method method2 = ReflectionUtil.getMethod(Test1.class, "test2", //$NON-NLS-1$
new Class[] {Integer.TYPE});
method2.setAccessible(true);
ReflectionUtil.invokeMethod(method2, obj, new Object[] { new Integer(100) });
@@ -72,7 +72,7 @@
for (int i = 0; i < methods.length; ++i) {
Method method = methods[i];
String name = method.getName();
- if (name.indexOf("public") != -1) {
+ if (name.indexOf("public") != -1) { //$NON-NLS-1$
assertTrue(name, ReflectionUtil.isPublic(method));
} else {
assertFalse(name, ReflectionUtil.isPublic(method));
@@ -84,7 +84,7 @@
Method[] methods = MockClass.class.getDeclaredMethods();
for (int i = 0; i < methods.length; ++i) {
Method method = methods[i];
- if (method.getName().indexOf("static") != -1) {
+ if (method.getName().indexOf("static") != -1) { //$NON-NLS-1$
assertTrue(ReflectionUtil.isStatic(method));
} else {
assertFalse(ReflectionUtil.isStatic(method));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-13 10:41:34
|
Revision: 40
http://p-unit.svn.sourceforge.net/p-unit/?rev=40&view=rev
Author: zhanghuangzhu
Date: 2007-05-13 03:41:32 -0700 (Sun, 13 May 2007)
Log Message:
-----------
Andrew Zhang: strings i18n.
Modified Paths:
--------------
trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java
trunk/punit/src/org/punit/logger/StreamLoggerListener.java
trunk/punit/src/punit.properties
trunk/punit.test/src/tests/util/AssertUtil.java
Modified: trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java 2007-05-13 10:02:07 UTC (rev 39)
+++ trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java 2007-05-13 10:41:32 UTC (rev 40)
@@ -3,7 +3,6 @@
import java.lang.reflect.*;
import java.util.*;
-import org.punit.*;
import org.punit.message.*;
import org.punit.type.*;
import org.punit.util.*;
@@ -11,7 +10,7 @@
public abstract class PUnitAbstractTestMethodBuilder implements
TestMethodBuilder {
- public Object[] buildTestMethods(Class testClass) {
+ public Object[] buildTestMethods(Class testClass) {
checkTestClass(testClass);
Method[] methods = testClass.getDeclaredMethods();
Collection testMethods;
Modified: trunk/punit/src/org/punit/logger/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/logger/StreamLoggerListener.java 2007-05-13 10:02:07 UTC (rev 39)
+++ trunk/punit/src/org/punit/logger/StreamLoggerListener.java 2007-05-13 10:41:32 UTC (rev 40)
@@ -144,7 +144,6 @@
public void log(final StreamLoggerListener logger) {
StringBuffer sb = new StringBuffer();
sb.append(Messages.getString("logger.02")); //$NON-NLS-1$
- sb.append(" "); //$NON-NLS-1$
sb.append(_methodCount);
sb.append(", "); //$NON-NLS-1$
sb.append(Messages.getString("logger.03")); //$NON-NLS-1$
@@ -156,6 +155,7 @@
} else {
sb.append(Messages.getString("logger.05")); //$NON-NLS-1$
}
+ sb.append(") "); //$NON-NLS-1$
sb.append(_timeWatcher.stringValue());
sb.append(LoggerUtil.LINE_SEPERATOR);
logger.log(sb.toString(), Level.INFO);
Modified: trunk/punit/src/punit.properties
===================================================================
--- trunk/punit/src/punit.properties 2007-05-13 10:02:07 UTC (rev 39)
+++ trunk/punit/src/punit.properties 2007-05-13 10:41:32 UTC (rev 40)
@@ -1,9 +1,9 @@
builder.01=\ should implement
-logger.01=\ Started running
-logger.02=\ total:
-logger.03=\ failures:
-logger.04=\ GREEN
-logger.05=\ RED
+logger.01=Started running
+logger.02=total:
+logger.03=failures:
+logger.04=GREEN
+logger.05=RED
runner.01=solo
runner.02=solo_parameterizable
runner.03=concurrent
Modified: trunk/punit.test/src/tests/util/AssertUtil.java
===================================================================
--- trunk/punit.test/src/tests/util/AssertUtil.java 2007-05-13 10:02:07 UTC (rev 39)
+++ trunk/punit.test/src/tests/util/AssertUtil.java 2007-05-13 10:41:32 UTC (rev 40)
@@ -43,9 +43,8 @@
public static void assertException(Class throwable, CodeRunner code) {
try {
code.run();
- Assert.fail(throwable + " expected!");
+ Assert.fail(throwable + " expected!"); //$NON-NLS-1$
} catch (Throwable e) {
- e.printStackTrace();
Assert.assertSame(throwable, e.getClass());
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-13 10:50:32
|
Revision: 41
http://p-unit.svn.sourceforge.net/p-unit/?rev=41&view=rev
Author: zhanghuangzhu
Date: 2007-05-13 03:50:33 -0700 (Sun, 13 May 2007)
Log Message:
-----------
Andrew Zhang: now punit core is jdk1.3 compatible.
Modified Paths:
--------------
trunk/punit/src/org/punit/util/ReflectionUtil.java
trunk/punit/src/org/punit/watcher/MemoryWatcher.java
trunk/punit/src/org/punit/watcher/TimeWatcher.java
Added Paths:
-----------
trunk/punit/.settings/org.eclipse.jdt.core.prefs
trunk/punit/.settings/org.eclipse.jdt.ui.prefs
Added: trunk/punit/.settings/org.eclipse.jdt.core.prefs
===================================================================
--- trunk/punit/.settings/org.eclipse.jdt.core.prefs (rev 0)
+++ trunk/punit/.settings/org.eclipse.jdt.core.prefs 2007-05-13 10:50:33 UTC (rev 41)
@@ -0,0 +1,12 @@
+#Sun May 13 18:44:47 CST 2007
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.3
Added: trunk/punit/.settings/org.eclipse.jdt.ui.prefs
===================================================================
--- trunk/punit/.settings/org.eclipse.jdt.ui.prefs (rev 0)
+++ trunk/punit/.settings/org.eclipse.jdt.ui.prefs 2007-05-13 10:50:33 UTC (rev 41)
@@ -0,0 +1,3 @@
+#Sun May 13 18:44:44 CST 2007
+eclipse.preferences.version=1
+internal.default.compliance=user
Modified: trunk/punit/src/org/punit/util/ReflectionUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-05-13 10:41:32 UTC (rev 40)
+++ trunk/punit/src/org/punit/util/ReflectionUtil.java 2007-05-13 10:50:33 UTC (rev 41)
@@ -10,7 +10,7 @@
try {
Constructor constructor = clazz.getDeclaredConstructor(new Class[] {});
constructor.setAccessible(true);
- return constructor.newInstance();
+ return constructor.newInstance(new Object [] {});
} catch (Exception e) {
throw new ReflectionException(e);
}
Modified: trunk/punit/src/org/punit/watcher/MemoryWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-13 10:41:32 UTC (rev 40)
+++ trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-13 10:50:33 UTC (rev 41)
@@ -24,7 +24,7 @@
}
public Object value() {
- return _maxUsedMemory - _startUsedMemory ;
+ return new Long(_maxUsedMemory - _startUsedMemory);
}
private void monitorMemory() {
Modified: trunk/punit/src/org/punit/watcher/TimeWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-13 10:41:32 UTC (rev 40)
+++ trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-13 10:50:33 UTC (rev 41)
@@ -36,7 +36,7 @@
}
public Object value() {
- return (_endTime - _startTime)/1000000;
+ return new Long((_endTime - _startTime)/1000000);
}
public String stringValue() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-14 07:48:30
|
Revision: 58
http://p-unit.svn.sourceforge.net/p-unit/?rev=58&view=rev
Author: zhanghuangzhu
Date: 2007-05-14 00:48:30 -0700 (Mon, 14 May 2007)
Log Message:
-----------
Andrew Zhang: first implmentation for image reporter.
Modified Paths:
--------------
trunk/punit/src/org/punit/events/WatcherEventListener.java
trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/runner/method/TestMethodRunner.java
trunk/punit/src/org/punit/watcher/MemoryWatcher.java
trunk/punit/src/org/punit/watcher/TimeWatcher.java
trunk/punit/src/org/punit/watcher/Watcher.java
trunk/punit/src/punit.properties
trunk/punit.extension/.classpath
trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java
trunk/punit.test/.classpath
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java
trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java
trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java
Added Paths:
-----------
trunk/punit/src/org/punit/watcher/AbstractWatcher.java
trunk/punit.extension/lib/jcommon-1.0.9.jar
trunk/punit.extension/src/org/punit/reporter/chart/image/ChartConstants.java
Modified: trunk/punit/src/org/punit/events/WatcherEventListener.java
===================================================================
--- trunk/punit/src/org/punit/events/WatcherEventListener.java 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit/src/org/punit/events/WatcherEventListener.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -5,12 +5,12 @@
import org.punit.watcher.*;
public interface WatcherEventListener extends EventListener {
- public void onWatchersStart(Watcher[] watches);
+ public void onWatchersStart(Watcher[] watchers);
- public void onWatcherStart(Watcher watch);
+ public void onWatcherStart(Watcher watcher);
- public void onWatcherEnd(Watcher watch);
+ public void onWatcherEnd(Watcher watcher);
- public void onWatchersEnd(Watcher[] watches);
+ public void onWatchersEnd(Watcher[] watchers);
}
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -63,19 +63,19 @@
_watchersStart = true;
}
- public void onWatcherStart(Watcher watch) {
+ public void onWatcherStart(Watcher watcher) {
}
public void onWatchersEnd(Watcher[] watchers) {
log("]", Level.FINE); //$NON-NLS-1$
}
- public void onWatcherEnd(Watcher watch) {
- String watchValue = watch.stringValue();
+ public void onWatcherEnd(Watcher watcher) {
+ String watchValue = watcher.stringValue();
if (_watchersStart) {
log(" - [" + watchValue, Level.FINE); //$NON-NLS-1$
} else {
- log("," + watch.stringValue(), Level.FINE); //$NON-NLS-1$
+ log("," + watcher.stringValue(), Level.FINE); //$NON-NLS-1$
}
_watchersStart = false;
}
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -5,7 +5,6 @@
import org.punit.builder.*;
import org.punit.events.*;
-import org.punit.reporter.stream.*;
import org.punit.reporter.stream.console.*;
import org.punit.reporter.stream.file.*;
import org.punit.result.*;
@@ -158,26 +157,26 @@
}
private void registerLoggerListeners() {
- registerStreamLoggerListener(_consoleLogger);
- registerStreamLoggerListener(_fileLogger);
+ addPUnitEventListener(_consoleLogger);
+ addPUnitEventListener(_fileLogger);
}
- private void registerStreamLoggerListener(StreamLoggerListener logger) {
- addRunnerEventListener(logger);
- addClassEventListener(logger);
- _testMethodRunner.addMethodEventListener(logger);
- _testMethodRunner.addWatcherEventListener(logger);
+ public void addPUnitEventListener(PUnitEvent listener) {
+ addRunnerEventListener(listener);
+ addClassEventListener(listener);
+ _testMethodRunner.addMethodEventListener(listener);
+ _testMethodRunner.addWatcherEventListener(listener);
}
public void removeConsoleLogger() {
- removeStreamLoggerListener(_consoleLogger);
+ removePUnitEventListener(_consoleLogger);
}
public void removeFileLogger() {
- removeStreamLoggerListener(_fileLogger);
+ removePUnitEventListener(_fileLogger);
}
- private void removeStreamLoggerListener(StreamLoggerListener logger) {
+ public void removePUnitEventListener(PUnitEvent logger) {
removeRunnerEventListener(logger);
removeClassEventListener(logger);
_testMethodRunner.removeMethodEventListener(logger);
Modified: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit/src/org/punit/runner/Runner.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -1,8 +1,28 @@
package org.punit.runner;
+import org.punit.builder.*;
import org.punit.events.*;
import org.punit.result.*;
+import org.punit.runner.method.*;
public interface Runner extends RunnerEvent, ClassEvent {
public Result run(Class clazz);
+
+ public TestMethodBuilder testMethodBuilder();
+
+ public TestMethodRunner testMethodRunner();
+
+ public TestSuiteBuilder testSuiteBuiler();
+
+ public void addRunnerEventListener(RunnerEventListener listener);
+
+ public void removeRunnerEventListener(RunnerEventListener listener);
+
+ public void addPUnitEventListener(PUnitEvent listener);
+
+ public void removePUnitEventListener(PUnitEvent listener);
+
+ public void addClassEventListener(ClassEventListener listener);
+
+ public void removeClassEventListener(ClassEventListener listener);
}
Modified: trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -198,14 +198,18 @@
});
}
- protected final Object[] watchersValues() {
- Object[] values = new Object[_watchers.length];
- for (int i = 0; i < _watchers.length; ++i) {
- values[i] = _watchers[i].value();
- }
- return values;
+// protected final double[] watchersValues() {
+// double[] values = new double[_watchers.length];
+// for (int i = 0; i < _watchers.length; ++i) {
+// values[i] = _watchers[i].value();
+// }
+// return values;
+// }
+
+ public Watcher[] watchers() {
+ return _watchers;
}
-
+
private boolean isPUnitTest() {
return PUnitTest.class.isAssignableFrom(_class);
}
Modified: trunk/punit/src/org/punit/runner/method/TestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/TestMethodRunner.java 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit/src/org/punit/runner/method/TestMethodRunner.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -3,15 +3,21 @@
import java.lang.reflect.*;
import org.punit.events.*;
+import org.punit.watcher.*;
public interface TestMethodRunner extends MethodEvent, WatcherEvent {
/**
* Runs the test method, and returns the watcher values.
+ *
* @param clazz
* @param method
* @return
*/
public void run(Object testInstance, Method method, Object[] params);
-
+ /**
+ * returns the watchers associated with this method runner.
+ * @return
+ */
+ public Watcher[] watchers();
}
Added: trunk/punit/src/org/punit/watcher/AbstractWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/AbstractWatcher.java (rev 0)
+++ trunk/punit/src/org/punit/watcher/AbstractWatcher.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -0,0 +1,5 @@
+package org.punit.watcher;
+
+public abstract class AbstractWatcher implements Watcher {
+ public abstract String toString();
+}
Modified: trunk/punit/src/org/punit/watcher/MemoryWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -3,7 +3,7 @@
import org.punit.message.*;
import org.punit.util.*;
-public class MemoryWatcher implements Watcher {
+public class MemoryWatcher extends AbstractWatcher {
private long _startUsedMemory;
@@ -23,8 +23,8 @@
monitorMemory();
}
- public Object value() {
- return new Long(_maxUsedMemory - _startUsedMemory);
+ public double value() {
+ return _maxUsedMemory - _startUsedMemory;
}
private void monitorMemory() {
@@ -46,4 +46,8 @@
public String stringValue() {
return value() + Messages.getString("watcher.01"); //$NON-NLS-1$
}
+
+ public String toString() {
+ return Messages.getString("watcher.03"); //$NON-NLS-1$
+ }
}
Modified: trunk/punit/src/org/punit/watcher/TimeWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -21,7 +21,7 @@
import org.punit.message.*;
-public class TimeWatcher implements Watcher {
+public class TimeWatcher extends AbstractWatcher {
private long _startTime;
@@ -35,11 +35,15 @@
_endTime = System.nanoTime();
}
- public Object value() {
- return new Long((_endTime - _startTime)/1000000);
+ public double value() {
+ return (_endTime - _startTime)/1000000;
}
public String stringValue() {
return value() + Messages.getString("watcher.02"); //$NON-NLS-1$
}
+
+ public String toString() {
+ return Messages.getString("watcher.04"); //$NON-NLS-1$
+ }
}
Modified: trunk/punit/src/org/punit/watcher/Watcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/Watcher.java 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit/src/org/punit/watcher/Watcher.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -6,7 +6,7 @@
public void stop();
- public Object value();
+ public double value();
public String stringValue();
Modified: trunk/punit/src/punit.properties
===================================================================
--- trunk/punit/src/punit.properties 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit/src/punit.properties 2007-05-14 07:48:30 UTC (rev 58)
@@ -10,3 +10,5 @@
runner.04=concurrent_parameterizable
watcher.01=bytes
watcher.02=ms
+watcher.03=memory
+watcher.04=time
\ No newline at end of file
Modified: trunk/punit.extension/.classpath
===================================================================
--- trunk/punit.extension/.classpath 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit.extension/.classpath 2007-05-14 07:48:30 UTC (rev 58)
@@ -3,5 +3,7 @@
<classpathentry path="src" kind="src"/>
<classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/>
<classpathentry path="/punit" combineaccessrules="false" kind="src"/>
+ <classpathentry path="lib/jfreechart-1.0.5.jar" kind="lib"/>
+ <classpathentry path="lib/jcommon-1.0.9.jar" kind="lib"/>
<classpathentry path="bin" kind="output"/>
</classpath>
Added: trunk/punit.extension/lib/jcommon-1.0.9.jar
===================================================================
(Binary files differ)
Property changes on: trunk/punit.extension/lib/jcommon-1.0.9.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/punit.extension/src/org/punit/reporter/chart/image/ChartConstants.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/image/ChartConstants.java (rev 0)
+++ trunk/punit.extension/src/org/punit/reporter/chart/image/ChartConstants.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -0,0 +1,12 @@
+package org.punit.reporter.chart.image;
+
+import java.awt.*;
+
+public class ChartConstants {
+ public static final Font TITLE_FONT = new Font("SansSerif", Font.BOLD, 14); //$NON-NLS-1$
+ public static final Font LEGEND_FONT = new Font("SansSerif", Font.PLAIN, 12); //$NON-NLS-1$
+ public static final Font VALUE_LABEL_FONT = new Font("SansSerif", Font.ITALIC, 12); //$NON-NLS-1$
+ public static final Font VALUE_TICKLABEL_FONT = new Font("SansSerif", Font.PLAIN, 10); //$NON-NLS-1$
+ public static final Font CATEGORY_LABEL_FONT = new Font("SansSerif", Font.ITALIC, 12); //$NON-NLS-1$
+ public static final Font CATEGORY_TICKLABEL_FONT = new Font("SansSerif", Font.PLAIN, 10); //$NON-NLS-1$
+}
Modified: trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -1,51 +1,142 @@
package org.punit.reporter.chart.image;
+import java.awt.image.*;
+import java.io.*;
import java.lang.reflect.*;
+import java.util.*;
+import java.util.Map.*;
+import javax.imageio.*;
+
+import org.jfree.chart.*;
+import org.jfree.chart.axis.*;
+import org.jfree.chart.plot.*;
+import org.jfree.chart.renderer.category.*;
+import org.jfree.data.category.*;
import org.punit.events.*;
import org.punit.runner.*;
+import org.punit.util.*;
import org.punit.watcher.*;
public class OverviewImageReporter implements PUnitEvent {
- public void onRunnerEnd(Class clazz, Runner runner) {
- throw new UnsupportedOperationException();
+ private static int DEFAULT_HEIGHT = 750;
+
+ private static int DEFAULT_WIDTH = 750;
+
+ private static String DEFAULT_FORMAT = "png"; //$NON-NLS-1$
+
+ private Hashtable _overviewDatasets; // <Watcher,DefaultCategoryDataset>
+
+ private Class _currentClass;
+
+ private Method _currentMethod;
+
+ private int _height;
+
+ private int _width;
+
+ private String _format;
+
+ public OverviewImageReporter() {
+ this(DEFAULT_HEIGHT, DEFAULT_WIDTH, DEFAULT_FORMAT);
}
+ public OverviewImageReporter(int height, int width, String format) {
+ _height = height;
+ _width = width;
+ _format = format;
+ }
+
public void onRunnerStart(Class clazz, Runner runner) {
- throw new UnsupportedOperationException();
+ Watcher[] watchers = runner.testMethodRunner().watchers();
+ _overviewDatasets = new Hashtable(watchers.length);
+ for (int i = 0; i < watchers.length; ++i) {
+ _overviewDatasets.put(watchers[i], new DefaultCategoryDataset());
+ }
}
- public void onClassEnd(Class clazz) {
- throw new UnsupportedOperationException();
+ public void onRunnerEnd(Class clazz, Runner runner) {
+ Set entrySet = _overviewDatasets.entrySet();
+ VisitorUtil.traverse(entrySet.iterator(), new Visitor() {
+ public void visit(Object obj) {
+ Entry entry = (Entry) obj;
+ Watcher watcher = (Watcher) entry.getKey();
+ CategoryDataset dataset = (CategoryDataset) entry.getValue();
+ JFreeChart chart = renderChart(watcher, dataset);
+ String fileName = "result/overview_" + watcher + ".png";
+ saveChartAsPNG(chart, new File(fileName));
+ }
+
+ });
}
+ protected JFreeChart renderChart(Watcher watcher, CategoryDataset dataset) {
+ CategoryAxis categoryAxis = new CategoryAxis(""); //$NON-NLS-1$
+ categoryAxis.setLabelFont(ChartConstants.CATEGORY_LABEL_FONT);
+ categoryAxis.setTickLabelFont(ChartConstants.CATEGORY_TICKLABEL_FONT);
+
+ // configure y axis
+ String yLegendText = watcher.toString();
+ ValueAxis valueAxis = new NumberAxis(yLegendText);
+ valueAxis.setLabelFont(ChartConstants.VALUE_LABEL_FONT);
+ valueAxis.setTickLabelFont(ChartConstants.VALUE_TICKLABEL_FONT);
+ LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, false);
+ CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
+ renderer);
+ plot.setOrientation(PlotOrientation.VERTICAL);
+
+ JFreeChart chart = new JFreeChart("Overview", ChartConstants.TITLE_FONT, plot, false);
+ return chart;
+ }
+
+ protected void saveChartAsPNG(JFreeChart chart, File file) {
+ BufferedImage chartImage = chart.createBufferedImage(_height, _width);
+ try {
+ ImageIO.write(chartImage, _format, file);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void onWatchersStart(Watcher[] watchers) {
+ // nothing needs to do
+ }
+
+ public void onWatchersEnd(Watcher[] watchers) {
+ // nothing needs to do
+ }
+
public void onClassStart(Class clazz) {
- throw new UnsupportedOperationException();
+ _currentClass = clazz;
}
- public void onMethodEnd(Method method, Throwable t) {
- throw new UnsupportedOperationException();
+ public void onClassEnd(Class clazz) {
+ // nothing needs to do
}
public void onMethodStart(Method method) {
- throw new UnsupportedOperationException();
+ _currentMethod = method;
}
- public void onWatcherEnd(Watcher watch) {
- throw new UnsupportedOperationException();
+ public void onMethodEnd(Method method, Throwable t) {
+ // nothing needs to do
}
- public void onWatcherStart(Watcher watch) {
- throw new UnsupportedOperationException();
+ public void onWatcherStart(Watcher watcher) {
+ // nothing needs to do
}
- public void onWatchersEnd() {
- throw new UnsupportedOperationException();
+ public void onWatcherEnd(Watcher watcher) {
+ DefaultCategoryDataset dataset = getDefaultCategoryDataset(watcher);
+ double value = watcher.value();
+ dataset.addValue(value, _currentClass.getName(), _currentMethod
+ .getName()); // value, y, x
}
- public void onWatchersStart() {
- throw new UnsupportedOperationException();
+ protected final DefaultCategoryDataset getDefaultCategoryDataset(
+ Watcher watcher) {
+ return (DefaultCategoryDataset) _overviewDatasets.get(watcher);
}
}
Modified: trunk/punit.test/.classpath
===================================================================
--- trunk/punit.test/.classpath 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit.test/.classpath 2007-05-14 07:48:30 UTC (rev 58)
@@ -4,5 +4,6 @@
<classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"/>
<classpathentry path="/punit" combineaccessrules="false" kind="src"/>
<classpathentry path="org.eclipse.jdt.junit.JUNIT_CONTAINER/3.8.1" kind="con"/>
+ <classpathentry path="/punit.extension" combineaccessrules="false" kind="src"/>
<classpathentry path="bin" kind="output"/>
</classpath>
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -11,7 +11,7 @@
public class AllTests {
public static Test suite() {
- TestSuite suite = new TestSuite("Test for tests.api.org.punit");
+ TestSuite suite = new TestSuite("Test for tests.api.org.punit"); //$NON-NLS-1$
//$JUnit-BEGIN$
suite.addTestSuite(ConcurrentExceptionTest.class);
suite.addTestSuite(LoggerUtilTest.class);
Modified: trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit.test/src/tests/api/org/punit/watcher/MemoryWatcherTest.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -21,8 +21,7 @@
data[i] = 42;
}
_watcher.stop();
- Long value = (Long) _watcher.value();
- long memoryConsumed = value.longValue();
+ double memoryConsumed = _watcher.value();
// The following assertions are not safe in theory, but it works
// practically.
assertTrue(memoryConsumed < data.length * 1.5);
Modified: trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit.test/src/tests/api/org/punit/watcher/TimeWatcherTest.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -16,8 +16,7 @@
_watcher.start();
Thread.sleep(SLEEP_TIME);
_watcher.stop();
- Long value = (Long) _watcher.value();
- long timeElapsed = value.longValue();
+ double timeElapsed = _watcher.value();
// The following assertions are not safe in theory, but it works
// practically.
assertTrue(timeElapsed < SLEEP_TIME * 1.2);
Modified: trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java
===================================================================
--- trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java 2007-05-14 06:10:20 UTC (rev 57)
+++ trunk/punit.test/src/tests/sample/testcase/JUnitTestSample.java 2007-05-14 07:48:30 UTC (rev 58)
@@ -2,12 +2,17 @@
import junit.framework.*;
+import org.punit.reporter.chart.image.*;
import org.punit.runner.*;
+import org.punit.util.*;
public class JUnitTestSample extends TestCase {
public static void main(String[] args) {
- new PUnitSoloRunner().run(JUnitTestSample.class);
+ PUnitSoloRunner runner = new PUnitSoloRunner();
+ OverviewImageReporter reporter = new OverviewImageReporter();
+ runner.addPUnitEventListener(reporter);
+ runner.run(JUnitTestSample.class);
}
public void setUp() {
@@ -19,9 +24,23 @@
}
public void test1() {
+ ThreadUtil.sleepIgnoreInterruption(20);
+ int length = new int[100].length;
+ ++length;
}
public void test2() {
+ ThreadUtil.sleepIgnoreInterruption(10);
+ int length = new int[30000].length;
+ ++length;
}
+ public void test3() {
+ ThreadUtil.sleepIgnoreInterruption(30);
+ int length = 200;
+ for(int i = 0, j = 0; i < length; ++i) {
+ j += new int[i].length;
+ }
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-14 08:47:30
|
Revision: 59
http://p-unit.svn.sourceforge.net/p-unit/?rev=59&view=rev
Author: zhanghuangzhu
Date: 2007-05-14 01:47:31 -0700 (Mon, 14 May 2007)
Log Message:
-----------
Andrew Zhang: refactored reporter system.
Modified Paths:
--------------
trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
trunk/punit/src/org/punit/reporter/stream/file/FileLoggerListener.java
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java
trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java
trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
trunk/punit/src/org/punit/runner/Runner.java
trunk/punit/src/org/punit/watcher/MemoryWatcher.java
trunk/punit/src/org/punit/watcher/TimeWatcher.java
trunk/punit/src/org/punit/watcher/Watcher.java
trunk/punit/src/punit.properties
trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java
Added Paths:
-----------
trunk/punit/src/org/punit/reporter/ReporterConstants.java
trunk/punit/src/org/punit/type/PUnitName.java
Removed Paths:
-------------
trunk/punit/src/org/punit/watcher/AbstractWatcher.java
Added: trunk/punit/src/org/punit/reporter/ReporterConstants.java
===================================================================
--- trunk/punit/src/org/punit/reporter/ReporterConstants.java (rev 0)
+++ trunk/punit/src/org/punit/reporter/ReporterConstants.java 2007-05-14 08:47:31 UTC (rev 59)
@@ -0,0 +1,13 @@
+package org.punit.reporter;
+
+import org.punit.message.*;
+
+public class ReporterConstants {
+
+ private ReporterConstants() {
+ }
+
+ public static final String RESULT_FOLDER = Messages
+ .getString("reporter.01"); //$NON-NLS-1$
+
+}
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-14 07:48:30 UTC (rev 58)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-14 08:47:31 UTC (rev 59)
@@ -29,8 +29,12 @@
public void onRunnerStart(Class clazz, Runner runner) {
_summary.start();
- log(Messages.getString("logger.01") + clazz.getName() + runner //$NON-NLS-1$
- + LoggerUtil.LINE_SEPERATOR, Level.INFO);
+ StringBuffer sb = new StringBuffer();
+ sb.append(runner.punitName());
+ sb.append(Messages.getString("logger.01")); //$NON-NLS-1$
+ sb.append(clazz.getName());
+ sb.append(LoggerUtil.LINE_SEPERATOR);
+ log(sb.toString(), Level.INFO);
}
public void onRunnerEnd(Class clazz, Runner runner) {
Modified: trunk/punit/src/org/punit/reporter/stream/file/FileLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/file/FileLoggerListener.java 2007-05-14 07:48:30 UTC (rev 58)
+++ trunk/punit/src/org/punit/reporter/stream/file/FileLoggerListener.java 2007-05-14 08:47:31 UTC (rev 59)
@@ -2,6 +2,7 @@
import java.io.*;
+import org.punit.reporter.*;
import org.punit.reporter.stream.*;
import org.punit.runner.*;
@@ -25,11 +26,17 @@
}
private void initResultFolder() {
- new File("result").mkdir(); //$NON-NLS-1$
+ new File(ReporterConstants.RESULT_FOLDER).mkdir();
}
private String generateFileName(Class clazz, Runner runner) {
- return "result/result_." + clazz.getName() + "_" + runner //$NON-NLS-1$ //$NON-NLS-2$
- + ".txt"; //$NON-NLS-1$
+ StringBuffer sb = new StringBuffer();
+ sb.append(ReporterConstants.RESULT_FOLDER);
+ sb.append(File.separator);
+ sb.append(clazz.getName());
+ sb.append("."); //$NON-NLS-1$
+ sb.append(runner.punitName());
+ sb.append(".txt"); //$NON-NLS-1$
+ return sb.toString();
}
}
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-14 07:48:30 UTC (rev 58)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-14 08:47:31 UTC (rev 59)
@@ -191,5 +191,4 @@
return _fileLogger;
}
- public abstract String toString();
}
Modified: trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java 2007-05-14 07:48:30 UTC (rev 58)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentParameterizableRunner.java 2007-05-14 08:47:31 UTC (rev 59)
@@ -19,7 +19,7 @@
&& Concurrent.class.isAssignableFrom(testClass);
}
- public String toString() {
+ public String punitName() {
return Messages.getString("runner.04"); //$NON-NLS-1$
}
Modified: trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-14 07:48:30 UTC (rev 58)
+++ trunk/punit/src/org/punit/runner/PUnitConcurrentRunner.java 2007-05-14 08:47:31 UTC (rev 59)
@@ -15,7 +15,7 @@
return Concurrent.class.isAssignableFrom(clazz);
}
- public String toString() {
+ public String punitName() {
return Messages.getString("runner.03"); //$NON-NLS-1$
}
Modified: trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java 2007-05-14 07:48:30 UTC (rev 58)
+++ trunk/punit/src/org/punit/runner/PUnitSoloParameterizableRunner.java 2007-05-14 08:47:31 UTC (rev 59)
@@ -15,7 +15,7 @@
return Parameterizable.class.isAssignableFrom(testClass);
}
- public String toString() {
+ public String punitName() {
return Messages.getString("runner.02"); //$NON-NLS-1$
}
Modified: trunk/punit/src/org/punit/runner/PUnitSoloRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-14 07:48:30 UTC (rev 58)
+++ trunk/punit/src/org/punit/runner/PUnitSoloRunner.java 2007-05-14 08:47:31 UTC (rev 59)
@@ -15,7 +15,7 @@
return true;
}
- public String toString() {
+ public String punitName() {
return Messages.getString("runner.01"); //$NON-NLS-1$
}
Modified: trunk/punit/src/org/punit/runner/Runner.java
===================================================================
--- trunk/punit/src/org/punit/runner/Runner.java 2007-05-14 07:48:30 UTC (rev 58)
+++ trunk/punit/src/org/punit/runner/Runner.java 2007-05-14 08:47:31 UTC (rev 59)
@@ -4,8 +4,9 @@
import org.punit.events.*;
import org.punit.result.*;
import org.punit.runner.method.*;
+import org.punit.type.*;
-public interface Runner extends RunnerEvent, ClassEvent {
+public interface Runner extends RunnerEvent, ClassEvent, PUnitName {
public Result run(Class clazz);
public TestMethodBuilder testMethodBuilder();
Added: trunk/punit/src/org/punit/type/PUnitName.java
===================================================================
--- trunk/punit/src/org/punit/type/PUnitName.java (rev 0)
+++ trunk/punit/src/org/punit/type/PUnitName.java 2007-05-14 08:47:31 UTC (rev 59)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface PUnitName {
+ public String punitName();
+}
Deleted: trunk/punit/src/org/punit/watcher/AbstractWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/AbstractWatcher.java 2007-05-14 07:48:30 UTC (rev 58)
+++ trunk/punit/src/org/punit/watcher/AbstractWatcher.java 2007-05-14 08:47:31 UTC (rev 59)
@@ -1,5 +0,0 @@
-package org.punit.watcher;
-
-public abstract class AbstractWatcher implements Watcher {
- public abstract String toString();
-}
Modified: trunk/punit/src/org/punit/watcher/MemoryWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-14 07:48:30 UTC (rev 58)
+++ trunk/punit/src/org/punit/watcher/MemoryWatcher.java 2007-05-14 08:47:31 UTC (rev 59)
@@ -3,7 +3,7 @@
import org.punit.message.*;
import org.punit.util.*;
-public class MemoryWatcher extends AbstractWatcher {
+public class MemoryWatcher implements Watcher {
private long _startUsedMemory;
@@ -44,10 +44,14 @@
}
public String stringValue() {
- return value() + Messages.getString("watcher.01"); //$NON-NLS-1$
+ return value() + unit();
}
- public String toString() {
+ public String punitName() {
return Messages.getString("watcher.03"); //$NON-NLS-1$
}
+
+ public String unit() {
+ return Messages.getString("watcher.01"); //$NON-NLS-1$
+ }
}
Modified: trunk/punit/src/org/punit/watcher/TimeWatcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-14 07:48:30 UTC (rev 58)
+++ trunk/punit/src/org/punit/watcher/TimeWatcher.java 2007-05-14 08:47:31 UTC (rev 59)
@@ -21,7 +21,7 @@
import org.punit.message.*;
-public class TimeWatcher extends AbstractWatcher {
+public class TimeWatcher implements Watcher {
private long _startTime;
@@ -40,10 +40,14 @@
}
public String stringValue() {
- return value() + Messages.getString("watcher.02"); //$NON-NLS-1$
+ return value() + unit();
}
- public String toString() {
+ public String punitName() {
return Messages.getString("watcher.04"); //$NON-NLS-1$
}
+
+ public String unit() {
+ return Messages.getString("watcher.02"); //$NON-NLS-1$
+ }
}
Modified: trunk/punit/src/org/punit/watcher/Watcher.java
===================================================================
--- trunk/punit/src/org/punit/watcher/Watcher.java 2007-05-14 07:48:30 UTC (rev 58)
+++ trunk/punit/src/org/punit/watcher/Watcher.java 2007-05-14 08:47:31 UTC (rev 59)
@@ -1,6 +1,8 @@
package org.punit.watcher;
-public interface Watcher {
+import org.punit.type.*;
+
+public interface Watcher extends PUnitName {
public void start();
@@ -10,4 +12,6 @@
public String stringValue();
+ public String unit();
+
}
Modified: trunk/punit/src/punit.properties
===================================================================
--- trunk/punit/src/punit.properties 2007-05-14 07:48:30 UTC (rev 58)
+++ trunk/punit/src/punit.properties 2007-05-14 08:47:31 UTC (rev 59)
@@ -4,11 +4,13 @@
logger.03=failures:
logger.04=GREEN
logger.05=RED
-runner.01=solo
-runner.02=solo_parameterizable
-runner.03=concurrent
-runner.04=concurrent_parameterizable
+runner.01=[SOLO]
+runner.02=[SOLO PARAM]
+runner.03=[CONCURRENT]
+runner.04=[CONCURRENT PARAM]
watcher.01=bytes
watcher.02=ms
watcher.03=memory
-watcher.04=time
\ No newline at end of file
+watcher.04=time
+reporter.01=result
+reporter.02=overview
\ No newline at end of file
Modified: trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java 2007-05-14 07:48:30 UTC (rev 58)
+++ trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java 2007-05-14 08:47:31 UTC (rev 59)
@@ -14,6 +14,7 @@
import org.jfree.chart.renderer.category.*;
import org.jfree.data.category.*;
import org.punit.events.*;
+import org.punit.message.*;
import org.punit.runner.*;
import org.punit.util.*;
import org.punit.watcher.*;
@@ -64,7 +65,7 @@
Watcher watcher = (Watcher) entry.getKey();
CategoryDataset dataset = (CategoryDataset) entry.getValue();
JFreeChart chart = renderChart(watcher, dataset);
- String fileName = "result/overview_" + watcher + ".png";
+ String fileName = generateOverviewImageFileName(watcher);
saveChartAsPNG(chart, new File(fileName));
}
@@ -139,4 +140,16 @@
return (DefaultCategoryDataset) _overviewDatasets.get(watcher);
}
+ protected final String generateOverviewImageFileName(Watcher watcher) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(Messages.getString("reporter.01")); //$NON-NLS-1$
+ sb.append(File.pathSeparator);
+ sb.append(Messages.getString("reporter.02")); //$NON-NLS-1$
+ sb.append("_"); //$NON-NLS-1$
+ sb.append(watcher.punitName());
+ sb.append("."); //$NON-NLS-1$
+ sb.append(_format);
+ return sb.toString();
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-14 13:24:44
|
Revision: 67
http://p-unit.svn.sourceforge.net/p-unit/?rev=67&view=rev
Author: zhanghuangzhu
Date: 2007-05-14 06:24:46 -0700 (Mon, 14 May 2007)
Log Message:
-----------
Andrew Zhang: renamed Vistor to Traverser
Modified Paths:
--------------
trunk/punit/src/org/punit/exception/ConcurrentException.java
trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
trunk/punit/src/org/punit/util/VisitorUtil.java
trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java
Added Paths:
-----------
trunk/punit/src/org/punit/util/Traverser.java
Removed Paths:
-------------
trunk/punit/src/org/punit/util/Visitor.java
Modified: trunk/punit/src/org/punit/exception/ConcurrentException.java
===================================================================
--- trunk/punit/src/org/punit/exception/ConcurrentException.java 2007-05-14 10:48:37 UTC (rev 66)
+++ trunk/punit/src/org/punit/exception/ConcurrentException.java 2007-05-14 13:24:46 UTC (rev 67)
@@ -20,8 +20,8 @@
public void printStackTrace() {
System.err.println(ConcurrentException.class.getName()+":"); //$NON-NLS-1$
- VisitorUtil.traverse(_throwables.iterator(), new Visitor() {
- public void visit(Object obj) {
+ VisitorUtil.traverse(_throwables.iterator(), new Traverser() {
+ public void traverse(Object obj) {
((Throwable) obj).printStackTrace();
}
});
@@ -29,8 +29,8 @@
public void printStackTrace(final PrintStream ps) {
ps.println(ConcurrentException.class.getName() + ":"); //$NON-NLS-1$
- VisitorUtil.traverse(_throwables.iterator(), new Visitor() {
- public void visit(Object obj) {
+ VisitorUtil.traverse(_throwables.iterator(), new Traverser() {
+ public void traverse(Object obj) {
((Throwable) obj).printStackTrace(ps);
}
});
@@ -38,8 +38,8 @@
public void printStackTrace(final PrintWriter pw) {
pw.println(ConcurrentException.class.getName() + ":"); //$NON-NLS-1$
- VisitorUtil.traverse(_throwables.iterator(), new Visitor() {
- public void visit(Object obj) {
+ VisitorUtil.traverse(_throwables.iterator(), new Traverser() {
+ public void traverse(Object obj) {
((Throwable) obj).printStackTrace(pw);
}
});
@@ -51,9 +51,9 @@
return visitor.sb.toString();
}
- static class GetMessageVisitor implements Visitor {
+ static class GetMessageVisitor implements Traverser {
final StringBuffer sb = new StringBuffer();
- public void visit(Object obj) {
+ public void traverse(Object obj) {
sb.append(((Throwable) obj));
sb.append(LoggerUtil.LINE_SEPERATOR);
}
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-14 10:48:37 UTC (rev 66)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-14 13:24:46 UTC (rev 67)
@@ -163,9 +163,9 @@
sb.append(_timeWatcher.stringValue());
sb.append(LoggerUtil.LINE_SEPERATOR);
logger.log(sb.toString(), Level.INFO);
- VisitorUtil.traverse(_throwableList.iterator(), new Visitor() {
+ VisitorUtil.traverse(_throwableList.iterator(), new Traverser() {
int count = 0;
- public void visit(Object obj) {
+ public void traverse(Object obj) {
logger.log(++count + ")", Level.INFO); //$NON-NLS-1$
((Throwable) obj).printStackTrace(logger._ps);
}
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-14 10:48:37 UTC (rev 66)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-14 13:24:46 UTC (rev 67)
@@ -47,16 +47,16 @@
}
private void onRunnerStart(final Class clazz) {
- VisitorUtil.traverse(_runnerEventListeners.iterator(), new Visitor() {
- public void visit(Object obj) {
+ VisitorUtil.traverse(_runnerEventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
((RunnerEventListener) obj).onRunnerStart(clazz, PUnitAbstractRunner.this);
}
});
}
private void onRunnerEnd(final Class clazz) {
- VisitorUtil.traverse(_runnerEventListeners.iterator(), new Visitor() {
- public void visit(Object obj) {
+ VisitorUtil.traverse(_runnerEventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
((RunnerEventListener) obj).onRunnerEnd(clazz, PUnitAbstractRunner.this);
}
});
@@ -76,16 +76,16 @@
}
private void onClassStart(final Class clazz) {
- VisitorUtil.traverse(_classEventListeners.iterator(), new Visitor() {
- public void visit(Object obj) {
+ VisitorUtil.traverse(_classEventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
((ClassEventListener) obj).onClassStart(clazz);
}
});
}
private void onClassEnd(final Class clazz) {
- VisitorUtil.traverse(_classEventListeners.iterator(), new Visitor() {
- public void visit(Object obj) {
+ VisitorUtil.traverse(_classEventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
((ClassEventListener) obj).onClassEnd(clazz);
}
});
Modified: trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-14 10:48:37 UTC (rev 66)
+++ trunk/punit/src/org/punit/runner/method/AbstractTestMethodRunner.java 2007-05-14 13:24:46 UTC (rev 67)
@@ -66,16 +66,16 @@
}
private void onMethodStart(final Method method) {
- VisitorUtil.traverse(_methodEventListeners.iterator(), new Visitor() {
- public void visit(Object obj) {
+ VisitorUtil.traverse(_methodEventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
((MethodEventListener) obj).onMethodStart(method);
}
});
}
private void onMethodEnd(final Method method, final Throwable t) {
- VisitorUtil.traverse(_methodEventListeners.iterator(), new Visitor() {
- public void visit(Object obj) {
+ VisitorUtil.traverse(_methodEventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
((MethodEventListener) obj).onMethodEnd(method, t);
}
});
@@ -159,16 +159,16 @@
}
private void onWatchersStart() {
- VisitorUtil.traverse(_watcherEventListeners.iterator(), new Visitor() {
- public void visit(Object obj) {
+ VisitorUtil.traverse(_watcherEventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
((WatcherEventListener) obj).onWatchersStart(_watchers);
}
});
}
private void onWatcherStart(final Watcher watcher) {
- VisitorUtil.traverse(_watcherEventListeners.iterator(), new Visitor() {
- public void visit(Object obj) {
+ VisitorUtil.traverse(_watcherEventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
((WatcherEventListener) obj).onWatcherStart(watcher);
}
});
@@ -183,16 +183,16 @@
}
private void onWatcherEnd(final Watcher watcher) {
- VisitorUtil.traverse(_methodEventListeners.iterator(), new Visitor() {
- public void visit(Object obj) {
+ VisitorUtil.traverse(_methodEventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
((WatcherEventListener) obj).onWatcherEnd(watcher);
}
});
}
private void onWatchersEnd() {
- VisitorUtil.traverse(_methodEventListeners.iterator(), new Visitor() {
- public void visit(Object obj) {
+ VisitorUtil.traverse(_methodEventListeners.iterator(), new Traverser() {
+ public void traverse(Object obj) {
((WatcherEventListener) obj).onWatchersEnd(_watchers);
}
});
Copied: trunk/punit/src/org/punit/util/Traverser.java (from rev 61, trunk/punit/src/org/punit/util/Visitor.java)
===================================================================
--- trunk/punit/src/org/punit/util/Traverser.java (rev 0)
+++ trunk/punit/src/org/punit/util/Traverser.java 2007-05-14 13:24:46 UTC (rev 67)
@@ -0,0 +1,5 @@
+package org.punit.util;
+
+public interface Traverser {
+ public void traverse(Object obj);
+}
Deleted: trunk/punit/src/org/punit/util/Visitor.java
===================================================================
--- trunk/punit/src/org/punit/util/Visitor.java 2007-05-14 10:48:37 UTC (rev 66)
+++ trunk/punit/src/org/punit/util/Visitor.java 2007-05-14 13:24:46 UTC (rev 67)
@@ -1,5 +0,0 @@
-package org.punit.util;
-
-public interface Visitor {
- public void visit(Object obj);
-}
Modified: trunk/punit/src/org/punit/util/VisitorUtil.java
===================================================================
--- trunk/punit/src/org/punit/util/VisitorUtil.java 2007-05-14 10:48:37 UTC (rev 66)
+++ trunk/punit/src/org/punit/util/VisitorUtil.java 2007-05-14 13:24:46 UTC (rev 67)
@@ -3,9 +3,9 @@
import java.util.*;
public class VisitorUtil {
- public static void traverse(Iterator iter, Visitor visitor) {
+ public static void traverse(Iterator iter, Traverser traverser) {
while (iter.hasNext()) {
- visitor.visit(iter.next());
+ traverser.traverse(iter.next());
}
}
}
Modified: trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java 2007-05-14 10:48:37 UTC (rev 66)
+++ trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java 2007-05-14 13:24:46 UTC (rev 67)
@@ -1,6 +1,5 @@
package org.punit.reporter.chart.image;
-import java.awt.*;
import java.awt.image.*;
import java.io.*;
import java.lang.reflect.*;
@@ -13,9 +12,7 @@
import org.jfree.chart.axis.*;
import org.jfree.chart.plot.*;
import org.jfree.chart.renderer.category.*;
-import org.jfree.chart.title.*;
import org.jfree.data.category.*;
-import org.jfree.ui.*;
import org.punit.events.*;
import org.punit.message.*;
import org.punit.runner.*;
@@ -62,8 +59,8 @@
public void onRunnerEnd(Class clazz, Runner runner) {
Set entrySet = _overviewDatasets.entrySet();
- VisitorUtil.traverse(entrySet.iterator(), new Visitor() {
- public void visit(Object obj) {
+ VisitorUtil.traverse(entrySet.iterator(), new Traverser() {
+ public void traverse(Object obj) {
Entry entry = (Entry) obj;
Watcher watcher = (Watcher) entry.getKey();
CategoryDataset dataset = (CategoryDataset) entry.getValue();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-14 17:04:50
|
Revision: 75
http://p-unit.svn.sourceforge.net/p-unit/?rev=75&view=rev
Author: zhanghuangzhu
Date: 2007-05-14 10:04:49 -0700 (Mon, 14 May 2007)
Log Message:
-----------
Andrew Zhang: Removed competitive related classes.
Modified Paths:
--------------
trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java
trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
trunk/punit/src/punit.properties
trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java
trunk/punit.test/src/extension/tests/samples/PUnitTestSuiteSample.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java
Removed Paths:
-------------
trunk/punit/src/org/punit/type/Competitive.java
trunk/punit/src/org/punit/type/CompetitiveTestSuite.java
trunk/punit.test/src/extension/tests/samples/CompetitiveTestSample.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveInterface.java
trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass2.java
trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite2.java
trunk/punit.test/src/tests/samples/CompetitiveTestSample.java
Modified: trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -3,7 +3,6 @@
import java.lang.reflect.*;
import java.util.*;
-import org.punit.message.*;
import org.punit.type.*;
import org.punit.util.*;
@@ -11,7 +10,6 @@
TestMethodBuilder {
public Object[] buildTestMethods(Class testClass) {
- checkTestClass(testClass);
Method[] methods = testClass.getDeclaredMethods();
Collection testMethods;
if (isAlphabetical(testClass)) {
@@ -42,30 +40,6 @@
protected abstract boolean isParamValid(Method method);
- private void checkTestClass(Class testClass) {
- if (isCompetitiveTestSuite(testClass)) {
- checkCompetitiveTestSuite(testClass);
- }
- }
-
- private void checkCompetitiveTestSuite(Class testClass) {
- CompetitiveTestSuite suite = (CompetitiveTestSuite) ReflectionUtil
- .newInstance(testClass);
- Class competitiveInterface = suite.comptitiveInterface();
- Class[] implementors = suite.suite();
- for (int i = 0; i < implementors.length; ++i) {
- Class implementor = implementors[i];
- if (!competitiveInterface.isAssignableFrom(implementor)) {
- throw new IllegalArgumentException(implementor
- + Messages.getString("builder.01") + competitiveInterface); //$NON-NLS-1$
- }
- }
- }
-
- private boolean isCompetitiveTestSuite(Class testClass) {
- return CompetitiveTestSuite.class.isAssignableFrom(testClass);
- }
-
private boolean isAlphabetical(Class testClass) {
return Alphabetical.class.isAssignableFrom(testClass);
}
Modified: trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java
===================================================================
--- trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit/src/org/punit/reporter/stream/StreamLoggerListener.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -30,7 +30,9 @@
public void onRunnerStart(Class clazz, Runner runner) {
_summary.start();
StringBuffer sb = new StringBuffer();
+ sb.append("["); //$NON-NLS-1$
sb.append(runner.punitName());
+ sb.append("] "); //$NON-NLS-1$
sb.append(Messages.getString("logger.01")); //$NON-NLS-1$
sb.append(clazz.getName());
sb.append(LoggerUtil.LINE_SEPERATOR);
Deleted: trunk/punit/src/org/punit/type/Competitive.java
===================================================================
--- trunk/punit/src/org/punit/type/Competitive.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit/src/org/punit/type/Competitive.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -1,5 +0,0 @@
-package org.punit.type;
-
-public interface Competitive {
- public int competitiveID();
-}
Deleted: trunk/punit/src/org/punit/type/CompetitiveTestSuite.java
===================================================================
--- trunk/punit/src/org/punit/type/CompetitiveTestSuite.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit/src/org/punit/type/CompetitiveTestSuite.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -1,5 +0,0 @@
-package org.punit.type;
-
-public interface CompetitiveTestSuite extends TestSuite{
- public Class comptitiveInterface();
-}
Modified: trunk/punit/src/punit.properties
===================================================================
--- trunk/punit/src/punit.properties 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit/src/punit.properties 2007-05-14 17:04:49 UTC (rev 75)
@@ -4,13 +4,13 @@
logger.03=failures:
logger.04=GREEN
logger.05=RED
-runner.01=[SOLO]
-runner.02=[SOLO PARAM]
-runner.03=[CONCURRENT]
-runner.04=[CONCURRENT PARAM]
+runner.01=solo
+runner.02=solo.param
+runner.03=concurrent
+runner.04=concurrent.param
watcher.01=bytes
watcher.02=ms
watcher.03=memory
watcher.04=time
reporter.01=result
-reporter.02=OVERVIEW
\ No newline at end of file
+reporter.02=overview
\ No newline at end of file
Modified: trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java
===================================================================
--- trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit.extension/src/org/punit/reporter/chart/image/OverviewImageReporter.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -60,7 +60,7 @@
}
}
- public void onRunnerEnd(Class clazz, Runner runner) {
+ public void onRunnerEnd(Class clazz, final Runner runner) {
Set entrySet = _overviewDatasets.entrySet();
VisitorUtil.traverse(entrySet.iterator(), new Traverser() {
public void traverse(Object obj) {
@@ -69,7 +69,7 @@
CategoryDataset dataset = (CategoryDataset) entry.getValue();
String yLegendText = watcher.punitName() + " [" + watcher.unit() + "]"; //$NON-NLS-1$//$NON-NLS-2$
JFreeChart chart = renderChart(yLegendText, dataset);
- String fileName = generateOverviewImageFileName(watcher);
+ String fileName = generateOverviewImageFileName(runner, watcher);
saveChartAsPNG(chart, new File(fileName));
}
});
@@ -152,14 +152,16 @@
}
}
- protected final String generateOverviewImageFileName(Watcher watcher) {
+ protected final String generateOverviewImageFileName(Runner runner, Watcher watcher) {
StringBuffer sb = new StringBuffer();
sb.append(Messages.getString("reporter.01")); //$NON-NLS-1$
sb.append(File.separator);
sb.append(Messages.getString("reporter.02")); //$NON-NLS-1$
- sb.append("_"); //$NON-NLS-1$
+ sb.append("."); //$NON-NLS-1$
sb.append(watcher.punitName());
sb.append("."); //$NON-NLS-1$
+ sb.append(runner.punitName());
+ sb.append("."); //$NON-NLS-1$
sb.append(_format);
return sb.toString();
}
Deleted: trunk/punit.test/src/extension/tests/samples/CompetitiveTestSample.java
===================================================================
--- trunk/punit.test/src/extension/tests/samples/CompetitiveTestSample.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit.test/src/extension/tests/samples/CompetitiveTestSample.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -1,14 +0,0 @@
-package extension.tests.samples;
-
-import org.punit.reporter.chart.image.*;
-import org.punit.runner.*;
-
-import tests.api.org.punit.testclasses.*;
-
-public class CompetitiveTestSample {
- public static void main(String[] args) {
- PUnitSoloRunner runner = new PUnitSoloRunner();
- runner.addPUnitEventListener(new OverviewImageReporter());
- runner.run(CompetitiveTestSuite1.class);
- }
-}
Modified: trunk/punit.test/src/extension/tests/samples/PUnitTestSuiteSample.java
===================================================================
--- trunk/punit.test/src/extension/tests/samples/PUnitTestSuiteSample.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit.test/src/extension/tests/samples/PUnitTestSuiteSample.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -7,16 +7,17 @@
import tests.util.*;
public class PUnitTestSuiteSample {
-
+
public static void main(String[] args) {
TestUtil.runUnitTest = false;
- Runner runner;
-// runner = new PUnitSoloRunner();
- runner = new PUnitConcurrentRunner();
-// runner = new PUnitSoloParameterizableRunner();
-// runner = new PUnitConcurrentParameterizableRunner();
- runner.addPUnitEventListener(new OverviewImageReporter());
- runner.run(TestSuiteClass.class);
+ Runner[] runners = new Runner[] { new PUnitSoloRunner(),
+ new PUnitConcurrentRunner(),
+ new PUnitSoloParameterizableRunner(),
+ new PUnitConcurrentParameterizableRunner() };
+ for(int i = 0; i < runners.length; ++i) {
+ runners[i].addPUnitEventListener(new OverviewImageReporter());
+ runners[i].run(TestSuiteClass.class);
+ }
}
-
+
}
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -7,7 +7,6 @@
import tests.api.org.punit.runner.*;
import tests.api.org.punit.util.*;
import tests.api.org.punit.watcher.*;
-import tests.samples.*;
public class AllTests {
public static Test suite() {
@@ -16,8 +15,7 @@
suite.addTestSuite(ConcurrentExceptionTest.class);
suite.addTestSuite(LoggerUtilTest.class);
suite.addTestSuite(MemoryWatcherTest.class);
- suite.addTestSuite(PUnitAbstractTestMethodBuilderTest.class);
- suite.addTestSuite(PUnitConcurrentParameterizableRunnerTest.class);
+ suite.addTestSuite(PUnitConcurrentParameterizableRunnerTest.class);
suite.addTestSuite(PUnitConcurrentRunnerTest.class);
suite.addTestSuite(PUnitLoggerTest.class);
suite.addTestSuite(PUnitParameterizableTestMethodBuilderTest.class);
Deleted: trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -1,37 +0,0 @@
-package tests.api.org.punit.builder;
-
-import java.lang.reflect.*;
-
-import junit.framework.*;
-import org.punit.builder.*;
-import tests.api.org.punit.testclasses.*;
-import tests.util.*;
-
-public class PUnitAbstractTestMethodBuilderTest extends TestCase {
- private MockTestMethodBuilder _build;
-
- protected void setUp() throws Exception {
- _build = new MockTestMethodBuilder();
- }
-
- public void testBuildCompetitive1() {
- _build.buildTestMethods(CompetitiveTestSuite1.class);
- }
-
- public void testBuildCompetitive2() {
- AssertUtil.assertException(IllegalArgumentException.class, new CodeRunner() {
- public void run() throws Throwable {
- _build.buildTestMethods(CompetitiveTestSuite2.class);
- }
- });
- }
-
- static class MockTestMethodBuilder extends PUnitAbstractTestMethodBuilder {
-
- protected boolean isParamValid(Method method) {
- return false;
- }
-
-
- }
-}
Deleted: trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveInterface.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveInterface.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveInterface.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -1,10 +0,0 @@
-package tests.api.org.punit.testclasses;
-
-import org.punit.type.*;
-
-public interface CompetitiveInterface extends Competitive {
-
- public void test1();
-
- public void test2();
-}
Deleted: trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass1.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass1.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass1.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -1,37 +0,0 @@
-package tests.api.org.punit.testclasses;
-
-import org.punit.runner.*;
-import org.punit.util.*;
-
-import tests.util.*;
-
-
-public class CompetitiveTestClass1 implements CompetitiveInterface {
-
- public static void main(String[] args) {
- new PUnitSoloRunner().run(CompetitiveTestClass1.class);
- }
-
- public void setUp() {
-
- }
-
- public void tearDown() {
-
- }
-
- public void test1() {
- TestUtil.consumeMemory(30000);
- TestUtil.consumeTime(30);
- }
-
- public void test2() {
- TestUtil.consumeMemory(1000);
- TestUtil.consumeTime(20);
- }
-
- public int competitiveID() {
- return 10;
- }
-
-}
Deleted: trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass2.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass2.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestClass2.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -1,36 +0,0 @@
-package tests.api.org.punit.testclasses;
-
-import org.punit.runner.*;
-
-import tests.util.*;
-
-
-public class CompetitiveTestClass2 implements CompetitiveInterface {
-
- public static void main(String[] args) {
- new PUnitSoloRunner().run(CompetitiveTestClass2.class);
- }
-
- public void setUp() {
-
- }
-
- public void tearDown() {
-
- }
-
- public void test1() {
- TestUtil.consumeMemory(4000);
- TestUtil.consumeTime(40);
- }
-
- public void test2() {
- TestUtil.consumeMemory(20000);
- TestUtil.consumeTime(10);
- }
-
- public int competitiveID() {
- return 10;
- }
-
-}
Deleted: trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite1.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite1.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite1.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -1,27 +0,0 @@
-package tests.api.org.punit.testclasses;
-
-import org.punit.runner.*;
-import org.punit.type.*;
-
-public class CompetitiveTestSuite1 implements CompetitiveTestSuite {
-
- public static void main(String[] args) {
- new PUnitSoloRunner().run(CompetitiveTestSuite1.class);
- }
-
- public int id() {
- return 10;
- }
-
- public Class[] suite() {
- return new Class[] {
- CompetitiveTestClass1.class,
- CompetitiveTestClass2.class,
- };
- }
-
- public Class comptitiveInterface() {
- return CompetitiveInterface.class;
- }
-
-}
Deleted: trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite2.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite2.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/CompetitiveTestSuite2.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -1,28 +0,0 @@
-package tests.api.org.punit.testclasses;
-
-import org.punit.runner.*;
-import org.punit.type.*;
-
-public class CompetitiveTestSuite2 implements CompetitiveTestSuite {
-
- public static void main(String[] args) {
- new PUnitSoloRunner().run(CompetitiveTestSuite2.class);
- }
-
- public int id() {
- return 10;
- }
-
- public Class[] suite() {
- return new Class[] {
- CompetitiveTestClass1.class,
- CompetitiveTestClass2.class,
- TestClass1.class,
- };
- }
-
- public Class comptitiveInterface() {
- return CompetitiveInterface.class;
- }
-
-}
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -9,7 +9,6 @@
TestClass.class,
PUnitTestClass.class,
ConcurrentTestClass.class,
- CompetitiveTestSuite1.class,
ConcurrentParameterizableTestClass.class,
JUnitTestClass.class,
ParameterizableTestClass.class,
Deleted: trunk/punit.test/src/tests/samples/CompetitiveTestSample.java
===================================================================
--- trunk/punit.test/src/tests/samples/CompetitiveTestSample.java 2007-05-14 15:52:34 UTC (rev 74)
+++ trunk/punit.test/src/tests/samples/CompetitiveTestSample.java 2007-05-14 17:04:49 UTC (rev 75)
@@ -1,11 +0,0 @@
-package tests.samples;
-
-import org.punit.runner.*;
-
-import tests.api.org.punit.testclasses.*;
-
-public class CompetitiveTestSample {
- public static void main(String[] args) {
- new PUnitSoloRunner().run(CompetitiveTestSuite1.class);
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-14 20:48:08
|
Revision: 76
http://p-unit.svn.sourceforge.net/p-unit/?rev=76&view=rev
Author: zhanghuangzhu
Date: 2007-05-14 13:48:10 -0700 (Mon, 14 May 2007)
Log Message:
-----------
Andrew Zhang: refactored test structure.
Modified Paths:
--------------
trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java
trunk/punit/src/org/punit/builder/TestMethodBuilder.java
trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
trunk/punit.test/src/extension/tests/samples/PUnitTestSuiteSample.java
trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
Added Paths:
-----------
trunk/punit/src/org/punit/runner/PUnitRunner.java
trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java
trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterface1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterfaceImpl1.java
Removed Paths:
-------------
trunk/punit/src/org/punit/type/Version.java
trunk/punit/src/org/punit/type/VersionCompetitive.java
Modified: trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java 2007-05-14 17:04:49 UTC (rev 75)
+++ trunk/punit/src/org/punit/builder/PUnitAbstractTestMethodBuilder.java 2007-05-14 20:48:10 UTC (rev 76)
@@ -7,49 +7,66 @@
import org.punit.util.*;
public abstract class PUnitAbstractTestMethodBuilder implements
- TestMethodBuilder {
+ TestMethodBuilder {
+ private HashSet _testMethodNames = new HashSet();
+
public Object[] buildTestMethods(Class testClass) {
- Method[] methods = testClass.getDeclaredMethods();
- Collection testMethods;
- if (isAlphabetical(testClass)) {
- testMethods = new TreeSet(new AlphabeticalMethodNameComparator());
- } else {
- testMethods = new ArrayList();
- }
- for (int i = 0; i < methods.length; ++i) {
- Method method = methods[i];
- if (isTestMethod(method)) {
- testMethods.add(method);
- }
- }
- return testMethods.toArray();
- }
+ Method[] methods = testClass.getDeclaredMethods();
+ Collection testMethods;
+ if (isAlphabetical(testClass)) {
+ testMethods = new TreeSet(new AlphabeticalMethodNameComparator());
+ } else {
+ testMethods = new ArrayList();
+ }
+ for (int i = 0; i < methods.length; ++i) {
+ Method method = methods[i];
+ if (isTestMethod(method)) {
+ testMethods.add(method);
+ }
+ }
+ return testMethods.toArray();
+ }
- protected boolean isTestMethod(Method method) {
- return isModifierValid(method) && isNameValid(method) && isParamValid(method);
- }
-
- protected boolean isModifierValid(Method method) {
- return ReflectionUtil.isPublic(method) && !ReflectionUtil.isStatic(method);
- }
-
- protected boolean isNameValid(Method method) {
- return method.getName().startsWith("test"); //$NON-NLS-1$
- }
-
- protected abstract boolean isParamValid(Method method);
+ protected boolean isTestMethod(Method method) {
+ return isModifierValid(method) && isNameValid(method)
+ && isParamValid(method);
+ }
- private boolean isAlphabetical(Class testClass) {
- return Alphabetical.class.isAssignableFrom(testClass);
- }
+ protected boolean isModifierValid(Method method) {
+ return ReflectionUtil.isPublic(method)
+ && !ReflectionUtil.isStatic(method);
+ }
- private static class AlphabeticalMethodNameComparator implements Comparator {
- public int compare(Object o1, Object o2) {
- Method m1 = (Method) o1;
- Method m2 = (Method) o2;
- return m1.getName().compareTo(m2.getName());
- }
- }
+ protected boolean isNameValid(Method method) {
+ String name = method.getName();
+ return name.startsWith("test") || _testMethodNames.contains(name); //$NON-NLS-1$
+ }
+ protected abstract boolean isParamValid(Method method);
+
+ private boolean isAlphabetical(Class testClass) {
+ return Alphabetical.class.isAssignableFrom(testClass);
+ }
+
+ private static class AlphabeticalMethodNameComparator implements Comparator {
+ public int compare(Object o1, Object o2) {
+ Method m1 = (Method) o1;
+ Method m2 = (Method) o2;
+ return m1.getName().compareTo(m2.getName());
+ }
+ }
+
+ public void addTestInterfaces(Class[] classes) {
+ for (int i = 0; i < classes.length; ++i) {
+ addTestInterface(classes[i]);
+ }
+ }
+
+ private void addTestInterface(Class testInterface) {
+ Method[] methods = testInterface.getDeclaredMethods();
+ for (int i = 0; i < methods.length; ++i) {
+ _testMethodNames.add(methods[i].getName());
+ }
+ }
}
Modified: trunk/punit/src/org/punit/builder/TestMethodBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/TestMethodBuilder.java 2007-05-14 17:04:49 UTC (rev 75)
+++ trunk/punit/src/org/punit/builder/TestMethodBuilder.java 2007-05-14 20:48:10 UTC (rev 76)
@@ -1,5 +1,6 @@
package org.punit.builder;
+
public interface TestMethodBuilder {
/**
* Builds the test methods from the test class. Returns a list of methods.
@@ -10,4 +11,6 @@
* @return
*/
public Object[] buildTestMethods(Class testClass);
+
+ public void addTestInterfaces(Class[] interfaces);
}
Modified: trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-14 17:04:49 UTC (rev 75)
+++ trunk/punit/src/org/punit/runner/PUnitAbstractRunner.java 2007-05-14 20:48:10 UTC (rev 76)
@@ -191,4 +191,8 @@
return _fileLogger;
}
+ public void addTestInterfaces(Class[] interfaces) {
+ _testMethodBuilder.addTestInterfaces(interfaces);
+ }
+
}
Added: trunk/punit/src/org/punit/runner/PUnitRunner.java
===================================================================
--- trunk/punit/src/org/punit/runner/PUnitRunner.java (rev 0)
+++ trunk/punit/src/org/punit/runner/PUnitRunner.java 2007-05-14 20:48:10 UTC (rev 76)
@@ -0,0 +1,24 @@
+package org.punit.runner;
+
+public class PUnitRunner {
+
+ private PUnitRunner() {
+
+ }
+
+ public static void runSolo(Class clazz) {
+ new PUnitSoloRunner().run(clazz);
+ }
+
+ public static void runConcurrent(Class clazz) {
+ new PUnitConcurrentRunner().run(clazz);
+ }
+
+ public static void runSoloParameterized(Class clazz) {
+ new PUnitSoloParameterizableRunner().run(clazz);
+ }
+
+ public static void runConcurrentParameterized(Class clazz) {
+ new PUnitConcurrentParameterizableRunner().run(clazz);
+ }
+}
Deleted: trunk/punit/src/org/punit/type/Version.java
===================================================================
--- trunk/punit/src/org/punit/type/Version.java 2007-05-14 17:04:49 UTC (rev 75)
+++ trunk/punit/src/org/punit/type/Version.java 2007-05-14 20:48:10 UTC (rev 76)
@@ -1,21 +0,0 @@
-package org.punit.type;
-
-public class Version {
-
- private String _resourcePath;
-
- private String _versionName;
-
- public Version(String path, String name) {
- _resourcePath = path;
- _versionName = name;
- }
-
- public String resourcePath() {
- return _resourcePath;
- }
-
- public String versionName() {
- return _versionName;
- }
-}
Deleted: trunk/punit/src/org/punit/type/VersionCompetitive.java
===================================================================
--- trunk/punit/src/org/punit/type/VersionCompetitive.java 2007-05-14 17:04:49 UTC (rev 75)
+++ trunk/punit/src/org/punit/type/VersionCompetitive.java 2007-05-14 20:48:10 UTC (rev 76)
@@ -1,5 +0,0 @@
-package org.punit.type;
-
-public interface VersionCompetitive {
- public Version[] versions();
-}
Modified: trunk/punit.test/src/extension/tests/samples/PUnitTestSuiteSample.java
===================================================================
--- trunk/punit.test/src/extension/tests/samples/PUnitTestSuiteSample.java 2007-05-14 17:04:49 UTC (rev 75)
+++ trunk/punit.test/src/extension/tests/samples/PUnitTestSuiteSample.java 2007-05-14 20:48:10 UTC (rev 76)
@@ -10,10 +10,12 @@
public static void main(String[] args) {
TestUtil.runUnitTest = false;
- Runner[] runners = new Runner[] { new PUnitSoloRunner(),
+ Runner[] runners = new Runner[] {
+ new PUnitSoloRunner(),
new PUnitConcurrentRunner(),
new PUnitSoloParameterizableRunner(),
- new PUnitConcurrentParameterizableRunner() };
+ new PUnitConcurrentParameterizableRunner()
+ };
for(int i = 0; i < runners.length; ++i) {
runners[i].addPUnitEventListener(new OverviewImageReporter());
runners[i].run(TestSuiteClass.class);
Modified: trunk/punit.test/src/tests/api/org/punit/all/AllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-14 17:04:49 UTC (rev 75)
+++ trunk/punit.test/src/tests/api/org/punit/all/AllTests.java 2007-05-14 20:48:10 UTC (rev 76)
@@ -9,23 +9,34 @@
import tests.api.org.punit.watcher.*;
public class AllTests {
+
public static Test suite() {
TestSuite suite = new TestSuite("Test for tests.api.org.punit"); //$NON-NLS-1$
- //$JUnit-BEGIN$
- suite.addTestSuite(ConcurrentExceptionTest.class);
- suite.addTestSuite(LoggerUtilTest.class);
- suite.addTestSuite(MemoryWatcherTest.class);
- suite.addTestSuite(PUnitConcurrentParameterizableRunnerTest.class);
- suite.addTestSuite(PUnitConcurrentRunnerTest.class);
- suite.addTestSuite(PUnitLoggerTest.class);
- suite.addTestSuite(PUnitParameterizableTestMethodBuilderTest.class);
- suite.addTestSuite(PUnitSoloParameterizableRunnerTest.class);
- suite.addTestSuite(PUnitSoloRunnerTest.class);
- suite.addTestSuite(PUnitTestMethodBuilderTest.class);
- suite.addTestSuite(PUnitTestSuiteBuilderTest.class);
- suite.addTestSuite(ReflectionUtilTest.class);
- suite.addTestSuite(TimeWatcherTest.class);
- //$JUnit-END$
+ // $JUnit-BEGIN$
+ Class[] testCases = testCases();
+ for (int i = 0; i < testCases.length; ++i) {
+ suite.addTestSuite(testCases[i]);
+ }
+ // $JUnit-END$
return suite;
}
+
+ public static Class[] testCases() {
+ return new Class[] {
+ ConcurrentExceptionTest.class,
+ LoggerUtilTest.class,
+ MemoryWatcherTest.class,
+ PUnitAbstractTestMethodBuilderTest.class,
+ PUnitConcurrentParameterizableRunnerTest.class,
+ PUnitConcurrentRunnerTest.class,
+ PUnitLoggerTest.class,
+ PUnitParameterizableTestMethodBuilderTest.class,
+ PUnitSoloParameterizableRunnerTest.class,
+ PUnitSoloRunnerTest.class,
+ PUnitTestMethodBuilderTest.class,
+ PUnitTestSuiteBuilderTest.class,
+ ReflectionUtilTest.class,
+ TimeWatcherTest.class,
+ };
+ }
}
Added: trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java 2007-05-14 20:48:10 UTC (rev 76)
@@ -0,0 +1,16 @@
+package tests.api.org.punit.all;
+
+import org.punit.runner.*;
+import org.punit.type.*;
+
+public class PUnitAllTests implements TestSuite {
+
+ public static void main(String[] args) {
+ new PUnitSoloRunner().run(PUnitAllTests.class);
+ }
+
+ public Class[] suite() {
+ return AllTests.testCases();
+ }
+
+}
Added: trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/builder/PUnitAbstractTestMethodBuilderTest.java 2007-05-14 20:48:10 UTC (rev 76)
@@ -0,0 +1,31 @@
+package tests.api.org.punit.builder;
+
+import java.lang.reflect.*;
+
+import junit.framework.*;
+
+import org.punit.builder.*;
+
+import tests.api.org.punit.testclasses.*;
+import tests.util.*;
+
+public class PUnitAbstractTestMethodBuilderTest extends TestCase {
+
+ private MockTestMethodBuilder _builder = new MockTestMethodBuilder();
+
+ public void testAddInterfaces() {
+ _builder.addTestInterfaces(new Class[] { TestInterface1.class });
+ Object[] methods = _builder.buildTestMethods(TestInterfaceImpl1.class);
+ String[] names = TestUtil.toMethodNameArray(methods);
+ AssertUtil.assertArrayContent(names, new String[] {"method1"}); //$NON-NLS-1$
+ }
+
+ static class MockTestMethodBuilder extends PUnitAbstractTestMethodBuilder {
+
+ protected boolean isParamValid(Method method) {
+ return true;
+ }
+
+ }
+
+}
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterface1.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterface1.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterface1.java 2007-05-14 20:48:10 UTC (rev 76)
@@ -0,0 +1,6 @@
+package tests.api.org.punit.testclasses;
+
+
+public interface TestInterface1 {
+ public void method1();
+}
Added: trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterfaceImpl1.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterfaceImpl1.java (rev 0)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestInterfaceImpl1.java 2007-05-14 20:48:10 UTC (rev 76)
@@ -0,0 +1,9 @@
+package tests.api.org.punit.testclasses;
+
+public class TestInterfaceImpl1 implements TestInterface1 {
+
+ public void method1() {
+ throw new UnsupportedOperationException();
+ }
+
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <zha...@us...> - 2007-05-14 20:49:14
|
Revision: 77
http://p-unit.svn.sourceforge.net/p-unit/?rev=77&view=rev
Author: zhanghuangzhu
Date: 2007-05-14 13:49:15 -0700 (Mon, 14 May 2007)
Log Message:
-----------
Andrew Zhang: Refactored TestSuite to PUnitTestSuite
Modified Paths:
--------------
trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java
trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java
trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java
Added Paths:
-----------
trunk/punit/src/org/punit/type/PUnitTestSuite.java
Removed Paths:
-------------
trunk/punit/src/org/punit/type/TestSuite.java
Modified: trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java
===================================================================
--- trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java 2007-05-14 20:48:10 UTC (rev 76)
+++ trunk/punit/src/org/punit/builder/PUnitTestSuiteBuilder.java 2007-05-14 20:49:15 UTC (rev 77)
@@ -21,7 +21,7 @@
}
private void buildTestClassFromTestSuite(List testClasses, Class clazz) {
- TestSuite testSuite = (TestSuite) ReflectionUtil.newInstance(clazz);
+ PUnitTestSuite testSuite = (PUnitTestSuite) ReflectionUtil.newInstance(clazz);
Class[] suite = testSuite.suite();
for(int i = 0; i < suite.length; ++i) {
buildTestClasses(testClasses, suite[i]);
@@ -34,7 +34,7 @@
private boolean isTestSuite(Class clazz) {
- return TestSuite.class.isAssignableFrom(clazz);
+ return PUnitTestSuite.class.isAssignableFrom(clazz);
}
}
Copied: trunk/punit/src/org/punit/type/PUnitTestSuite.java (from rev 61, trunk/punit/src/org/punit/type/TestSuite.java)
===================================================================
--- trunk/punit/src/org/punit/type/PUnitTestSuite.java (rev 0)
+++ trunk/punit/src/org/punit/type/PUnitTestSuite.java 2007-05-14 20:49:15 UTC (rev 77)
@@ -0,0 +1,5 @@
+package org.punit.type;
+
+public interface PUnitTestSuite {
+ public Class[] suite();
+}
Deleted: trunk/punit/src/org/punit/type/TestSuite.java
===================================================================
--- trunk/punit/src/org/punit/type/TestSuite.java 2007-05-14 20:48:10 UTC (rev 76)
+++ trunk/punit/src/org/punit/type/TestSuite.java 2007-05-14 20:49:15 UTC (rev 77)
@@ -1,5 +0,0 @@
-package org.punit.type;
-
-public interface TestSuite {
- public Class[] suite();
-}
Modified: trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java 2007-05-14 20:48:10 UTC (rev 76)
+++ trunk/punit.test/src/tests/api/org/punit/all/PUnitAllTests.java 2007-05-14 20:49:15 UTC (rev 77)
@@ -3,7 +3,7 @@
import org.punit.runner.*;
import org.punit.type.*;
-public class PUnitAllTests implements TestSuite {
+public class PUnitAllTests implements PUnitTestSuite {
public static void main(String[] args) {
new PUnitSoloRunner().run(PUnitAllTests.class);
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java 2007-05-14 20:48:10 UTC (rev 76)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite1.java 2007-05-14 20:49:15 UTC (rev 77)
@@ -1,5 +1,5 @@
package tests.api.org.punit.testclasses;
-public class TestSuite1 implements org.punit.type.TestSuite {
+public class TestSuite1 implements org.punit.type.PUnitTestSuite {
public Class[] suite() {
return new Class[] { TestClass1.class, TestClass2.class, TestClass3.class,
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java 2007-05-14 20:48:10 UTC (rev 76)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuite2.java 2007-05-14 20:49:15 UTC (rev 77)
@@ -1,6 +1,6 @@
package tests.api.org.punit.testclasses;
-public class TestSuite2 implements org.punit.type.TestSuite {
+public class TestSuite2 implements org.punit.type.PUnitTestSuite {
public Class[] suite() {
return new Class[] { TestClass4.class, TestSuite1.class,
TestClass5.class,
Modified: trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java
===================================================================
--- trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java 2007-05-14 20:48:10 UTC (rev 76)
+++ trunk/punit.test/src/tests/api/org/punit/testclasses/TestSuiteClass.java 2007-05-14 20:49:15 UTC (rev 77)
@@ -2,7 +2,7 @@
import org.punit.type.*;
-public class TestSuiteClass implements TestSuite {
+public class TestSuiteClass implements PUnitTestSuite {
public Class[] suite() {
return new Class[] {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|