1 29 package net.sourceforge.groboutils.tp.v1.log; 30 31 32 import net.sourceforge.groboutils.autodoc.v1.AutoDocTP; 33 34 import java.io.PrintWriter ; 35 import java.io.File ; 36 import java.io.FileWriter ; 37 import java.io.IOException ; 38 39 40 47 public class LogTP implements AutoDocTP 48 { 49 private PrintWriter 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 baseDir, Class owner ) 57 { 58 PrintWriter pw = null; 59 if (baseDir != null && owner != null) 60 { 61 try 62 { 63 pw = new PrintWriter ( new FileWriter ( 64 new File ( baseDir, 65 "TP-"+owner.getName()+".log" ) ) ); 66 } 67 catch (IOException ioe) 68 { 69 pw = null; 70 } 71 } 72 if (pw == null) 73 { 74 pw = new PrintWriter ( System.out ); 75 } 76 setOutput( pw ); 77 } 78 79 80 85 public synchronized void setupStep( String description ) 86 { 87 printStep( "setup", description, ++this.setupCount ); 88 } 89 90 91 96 public synchronized void teardownStep( String description ) 97 { 98 printStep( "teardown", description, ++this.teardownCount ); 99 } 100 101 102 107 public synchronized void step( String description ) 108 { 109 printStep( "test step", description, ++this.stepCount ); 110 } 111 112 113 114 protected synchronized void printStep( String stepDesc, String 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 pw ) 124 { 125 this.out = pw; 126 } 127 } 128 129 | Popular Tags |