1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package lib;
29 
30 import java.util.Hashtable;
31 
32 /**
33  * The class supports interface tests development and Status calculation.
34  */
35 public class TestResult {
36     /**
37      * Contains methods having been tested and their results.
38      */
39     protected Hashtable testedMethods = new Hashtable();
40 
41     /**
42      * The method makes method tested with the result, i.e. it adds to its
43      * state OK (if result == true) or FAILED (if result == false) status
44      * and makes the state of the method completed. It's equal to
45      * tested(method, Status(result)) call.
46      *
47      * @param method reffers to the method whoch was tested
48      * @param result the result of testing the method
49      *
50      * @return the result value
51      *
52      * @throw java.lang.IllegalArgumentException if the method is not
53      * available in the interface.
54      *
55      * @see #tested(String, Status)
56      */
57     public boolean tested( String method, boolean result) {
58         System.out.println("Method "+method+" finished with state "+(result?"OK":"FAILED"));
59         return tested( method, Status.passed( result ) );
60     }
61 
62     /**
63      * The method makes the method tested with the status, i.e. it adds the
64      * status to its state and makes it completed.
65      *
66      * @param method reffers to the method whoch was tested
67      * @param status describes the result of testing the method
68      * @return <tt>true</tt> if status is OK, <tt>false</tt> otherwise.
69      *
70      * @throw java.lang.IllegalArgumentException if the method is not
71      * available in the interface.
72      */
73     public boolean tested( String method, Status status ) {
74     	testedMethods.put(method,status);
75         return true;
76     }
77 
78     /**
79      * @return methods available in the interface tested.
80      */
81     public String[] getTestedMethods() {
82         return (String[])testedMethods.keySet().toArray(
83                 new String[testedMethods.size()]);
84     }
85 
86     /**
87      * @return <tt>true</tt> if the method belongs to the interface tested,
88      * <tt>false</tt> otherwise.
89      */
90     public boolean hasMethod( String method ) {
91         return testedMethods.containsKey( method );
92     }
93 
94     /**
95      * @return status of testing the method, if it is available (was set by
96      * the tested or assert method), <tt>null</tt> otherwise.
97      *
98      * @see #tested(String, boolean)
99      * @see #tested(String, Status)
100      * @see #assert
101      */
102     public Status getStatusFor( String method ) {
103         return (Status)testedMethods.get( method );
104     }
105 
106 }