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