1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package lib; 25 26 import java.util.Hashtable; 27 28 /** 29 * The class supports interface tests development and Status calculation. 30 */ 31 public class TestResult { 32 /** 33 * Contains methods having been tested and their results. 34 */ 35 protected Hashtable testedMethods = new Hashtable(); 36 37 /** 38 * The method makes method tested with the result, i.e. it adds to its 39 * state OK (if result == true) or FAILED (if result == false) status 40 * and makes the state of the method completed. It's equal to 41 * tested(method, Status(result)) call. 42 * 43 * @param method reffers to the method whoch was tested 44 * @param result the result of testing the method 45 * 46 * @return the result value 47 * 48 * @throw java.lang.IllegalArgumentException if the method is not 49 * available in the interface. 50 * 51 * @see #tested(String, Status) 52 */ tested( String method, boolean result)53 public boolean tested( String method, boolean result) { 54 System.out.println("Method "+method+" finished with state "+(result?"OK":"FAILED")); 55 return tested( method, Status.passed( result ) ); 56 } 57 58 /** 59 * The method makes the method tested with the status, i.e. it adds the 60 * status to its state and makes it completed. 61 * 62 * @param method refers to the method which was tested 63 * @param status describes the result of testing the method 64 * @return <tt>true</tt> if status is OK, <tt>false</tt> otherwise. 65 * 66 * @throw java.lang.IllegalArgumentException if the method is not 67 * available in the interface. 68 */ tested( String method, Status status )69 public boolean tested( String method, Status status ) { 70 testedMethods.put(method,status); 71 return true; 72 } 73 74 /** 75 * @return methods available in the interface tested. 76 */ getTestedMethods()77 public String[] getTestedMethods() { 78 return (String[])testedMethods.keySet().toArray( 79 new String[testedMethods.size()]); 80 } 81 82 /** 83 * @return <tt>true</tt> if the method belongs to the interface tested, 84 * <tt>false</tt> otherwise. 85 */ hasMethod( String method )86 public boolean hasMethod( String method ) { 87 return testedMethods.containsKey( method ); 88 } 89 90 /** 91 * @return status of testing the method, if it is available (was set by 92 * the tested or assert method), <tt>null</tt> otherwise. 93 * 94 * @see #tested(String, boolean) 95 * @see #tested(String, Status) 96 * @see #assert 97 */ getStatusFor( String method )98 public Status getStatusFor( String method ) { 99 return (Status)testedMethods.get( method ); 100 } 101 102 } 103