1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at 
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software 
11   * distributed under the License is distributed on an "AS IS" BASIS, 
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
13   * See the License for the specific language governing permissions and 
14   * limitations under the License.
15   */
16  
17  package javax.jdo.util;
18  
19  import java.io.PrintStream;
20  
21  import junit.framework.TestCase;
22  
23  /*** */
24  public class AbstractTest extends TestCase {
25  
26      /*** */
27      protected static PrintStream out = System.out;
28      
29      /*** If true, print extra messages. */
30      protected boolean verbose;
31  
32      /***
33       * Construct and initialize from properties.
34       */
35      protected AbstractTest() {
36          super(null);
37          verbose = Boolean.getBoolean("verbose");
38      }
39      
40      /***
41       */
42      protected void println(String s) {
43          if (verbose) 
44              out.println(s);
45      }
46      
47      /*** New line.
48       */
49      public static final String NL = System.getProperty("line.separator");
50      
51      /*** A buffer of of error messages.
52       */
53      protected static StringBuffer messages;
54      
55      /*** Appends to error messages.
56       */
57      protected static synchronized void appendMessage(String message) {
58          if (messages == null) {
59              messages = new StringBuffer();
60          }
61          messages.append(message);
62          messages.append(NL);
63      }
64      
65      /***
66       * Returns collected error messages, or <code>null</code> if there
67       * are none, and clears the buffer.
68       */
69      protected static synchronized String retrieveMessages() {
70          if (messages == null) {
71              return null;
72          }
73          final String msg = messages.toString();
74          messages = null;
75          return msg;
76      }
77      
78  }
79