KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > groboutils > tp > v1 > log > LogTP


1 /*
2  * @(#)LogTPLog.java
3  *
4  * Copyright (C) 2002-2003 Matt Albrecht
5  * groboclown@users.sourceforge.net
6  * http://groboutils.sourceforge.net
7  *
8  * Part of the GroboUtils package at:
9  * http://groboutils.sourceforge.net
10  *
11  * Permission is hereby granted, free of charge, to any person obtaining a
12  * copy of this software and associated documentation files (the "Software"),
13  * to deal in the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  * and/or sell copies of the Software, and to permit persons to whom the
16  * Software is furnished to do so, subject to the following conditions:
17  *
18  * The above copyright notice and this permission notice shall be included in
19  * all copies or substantial portions of the Software.
20  *
21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  * DEALINGS IN THE SOFTWARE.
28  */

29 package net.sourceforge.groboutils.tp.v1.log;
30
31
32 import net.sourceforge.groboutils.autodoc.v1.AutoDocTP;
33
34 import java.io.PrintWriter JavaDoc;
35 import java.io.File JavaDoc;
36 import java.io.FileWriter JavaDoc;
37 import java.io.IOException JavaDoc;
38
39
40 /**
41  * Test Procedure entry point. Generates Test Procedure documentation.
42  *
43  * @author Matt Albrecht <a HREF="mailto:groboclown@users.sourceforge.net">groboclown@users.sourceforge.net</a>
44  * @version $Date: 2003/02/10 22:52:29 $
45  * @since July 21, 2002
46  */

47 public class LogTP implements AutoDocTP
48 {
49     private PrintWriter JavaDoc out;
50     
51     private int overalCount = 0;
52     private int stepCount = 0;
53     private int setupCount = 0;
54     private int teardownCount = 0;
55     
56     public LogTP( String JavaDoc baseDir, Class JavaDoc owner )
57     {
58         PrintWriter JavaDoc pw = null;
59         if (baseDir != null && owner != null)
60         {
61             try
62             {
63                 pw = new PrintWriter JavaDoc( new FileWriter JavaDoc(
64                     new File JavaDoc( baseDir,
65                     "TP-"+owner.getName()+".log" ) ) );
66             }
67             catch (IOException JavaDoc ioe)
68             {
69                 pw = null;
70             }
71         }
72         if (pw == null)
73         {
74             pw = new PrintWriter JavaDoc( System.out );
75         }
76         setOutput( pw );
77     }
78     
79     
80     /**
81      * Defines a step which occurs during the test setup phase.
82      *
83      * @param description the text describing the step.
84      */

85     public synchronized void setupStep( String JavaDoc description )
86     {
87         printStep( "setup", description, ++this.setupCount );
88     }
89     
90     
91     /**
92      * Defines a step which occurs during the test tear-down phase.
93      *
94      * @param description the text describing the step.
95      */

96     public synchronized void teardownStep( String JavaDoc description )
97     {
98         printStep( "teardown", description, ++this.teardownCount );
99     }
100     
101     
102     /**
103      * Defines a step which occurs during the test proper.
104      *
105      * @param description the text describing the step.
106      */

107     public synchronized void step( String JavaDoc description )
108     {
109         printStep( "test step", description, ++this.stepCount );
110     }
111     
112     
113     
114     protected synchronized void printStep( String JavaDoc stepDesc, String JavaDoc text,
115         int thisStepCount )
116     {
117         ++this.overalCount;
118         this.out.println( this.overalCount +
119             ". "+stepDesc+": " +thisStepCount+". "+text );
120     }
121     
122     
123     protected void setOutput( PrintWriter JavaDoc pw )
124     {
125         this.out = pw;
126     }
127 }
128
129
Popular Tags