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 import com.sun.star.uno.XInterface; 26 27 import java.util.Hashtable; 28 29 30 /** 31 * The class contains an instance of a given implementation object and 32 * auxiliary objects associated with it and required for the object testing. 33 * 34 * @see TestCase 35 */ 36 37 public final class TestEnvironment { 38 /** 39 * Contains object relations - auxiliary objects associated with the 40 * tested object and required for testing. 41 */ 42 private final Hashtable relations = new Hashtable(10); 43 44 /** 45 * An instance of the tested implementation object. 46 */ 47 private final XInterface testObject; 48 49 /** 50 * Indicates that the testObject is in invalid state and should notbe 51 * used for testing anymore. 52 */ 53 private boolean disposed = false; 54 55 /** 56 * A reference to TestCase which has created the test environment. 57 */ 58 private TestCase tCase; 59 60 /** 61 * Creates an instance of test environment with testObject. 62 * 63 * @param testObject object to test 64 * 65 * @throws java.lang.IllegalArgumentException if the testObject is 66 * <tt>null</tt>. 67 */ TestEnvironment( XInterface testObject )68 public TestEnvironment( XInterface testObject ) { 69 if (testObject == null) { 70 throw new IllegalArgumentException( 71 "Couldn't create a test object"); 72 } 73 this.testObject = testObject; 74 } 75 76 /** 77 * @return the object to test. 78 */ getTestObject()79 public XInterface getTestObject() { 80 return testObject; 81 } 82 83 /** 84 * Adds to the environment an auxiliary object required for testing. 85 * 86 * @param name a name to reference the auxiliary object 87 * 88 * @param relation the auxiliary object related to the tested one 89 */ addObjRelation( String name, Object relation)90 public void addObjRelation( String name, Object relation) { 91 relations.put( name, relation ); 92 } 93 94 /** 95 * Returns an auxiliary object referenced by tname. 96 * 97 * @param name a name of the object relation 98 * 99 * @return the auxiliary object(object relation) 100 */ getObjRelation( String name )101 public Object getObjRelation( String name ) { 102 return relations.get( name ); 103 } 104 105 /** 106 * Checks if an auxiliary object has been registered with name 107 * 108 * @param name a name referencing an auxiliarx object 109 * 110 * @return <tt>true</tt> if the object has been associated, <tt>false</tt> 111 * otherwise. 112 */ hasObjRelation(String name)113 public boolean hasObjRelation(String name) { 114 return (relations.get(name) != null) ; 115 } 116 117 /** 118 * Sets the <code>TestCase</code> that created the environment. 119 */ setTestCase( TestCase tCase)120 public void setTestCase( TestCase tCase) { 121 this.tCase = tCase; 122 } 123 124 /** 125 * @return the <code>TestCase</code> created the environment. 126 */ getTestCase()127 public TestCase getTestCase() { 128 return tCase; 129 } 130 131 /** 132 * Makes the environment invalid, i.e. it should not be used for 133 * testing anymore. 134 */ dispose()135 public void dispose() { 136 disposed = true; 137 } 138 139 /** 140 * Checks if the environment has been disposed. 141 * 142 * @return <tt>true</tt< if it has been disposed, <tt>false</tt> otherwise. 143 * 144 * @see #dispose() 145 */ isDisposed()146 public boolean isDisposed() { 147 return disposed; 148 } 149 }