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