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