1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
// Tags: JDK1.2
// Uses: getBeanInfo2_2TestClass
//Copyright (C) 2004 Robert Schuster <theBohemian@gmx.net>
//Mauve is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2, or (at your option)
//any later version.
//Mauve is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//You should have received a copy of the GNU General Public License
//along with Mauve; see the file COPYING. If not, write to
//the Free Software Foundation, 59 Temple Place - Suite 330,
//Boston, MA 02111-1307, USA. */
package gnu.testlet.java.beans.Introspector;
import gnu.testlet.TestHarness;
import gnu.testlet.Testlet;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.MethodDescriptor;
import java.lang.reflect.Method;
/** This is the second test of the <strong>method</strong> retrieving
* mechanism of the Introspector class.
*
* <p>See {@link getBeanInfo2_2TestClass} for
* details on what is expected.</p>
*
* <p>The test goes like this:</p>
* <p>There is a test class having a number of well-known methods. All
* <code>public</code> methods should be available in a
* <code>MethodDescriptor</code> array.</p>
*
* @author Robert Schuster <theBohemian@gmx.net>
*/
public class getBeanInfo2_2 implements Testlet
{
public void test(TestHarness harness)
{
propertyTest(harness);
}
void propertyTest(TestHarness harness)
{
BeanInfo bi = null;
Class testClass = getBeanInfo2_2TestClass.class;
Method[] expectedMethods = null;
try
{
// these are the method that have to show up
expectedMethods =
new Method[] {
testClass.getMethod(
"setSomething1",
new Class[] {
Integer.TYPE,
Integer.TYPE,
Integer.TYPE }),
testClass.getMethod(
"getSomething2",
new Class[] {
String.class,
String.class,
String.class }),
testClass.getMethod(
"isSomething3",
new Class[] {
String.class,
String.class,
String.class })
};
}
catch (NoSuchMethodException nsme)
{
// if that happens check the test class (compiler?)
harness.fail("TEST_PREPARATION_NOSUCHMETHODEXCEPTION");
}
// checks wether all expected methods have been retrieved successfully
for (int i = 0; i < expectedMethods.length; i++)
{
harness.check(
expectedMethods[i] != null,
"TEST_PREPARATION_METHOD_INSTANCE_AVAILABLE");
}
// retrieves the BeanInfo instance of the test class
try
{
bi = Introspector.getBeanInfo(testClass, testClass.getSuperclass());
}
catch (IntrospectionException ie)
{
harness.fail("TEST_PREPARATION_INTROSPECTION_EXCEPTION");
}
harness.check(bi != null, "TEST_PREPARATION_VALID_BEANINFO");
MethodDescriptor[] methodDescriptors = bi.getMethodDescriptors();
// Since we only introspected the test class the number of method descriptors must match
// the number of expected methods.
harness.check(
methodDescriptors.length,
expectedMethods.length,
"MATCH_EXPECTED_METHOD_COUNT");
for (int i = 0; i < expectedMethods.length; i++)
{
harness.check(
containsMethod(methodDescriptors, expectedMethods[i]),
"EXPECTED_METHOD_AVAILABLE: " + expectedMethods[i].getName());
}
}
/** Returns whether a given method array contains a certain method.
*
* @param methods The array of method to be examined.
* @param key The method which is looked up.
* @return Whether the key method is in the array.
*/
boolean containsMethod(MethodDescriptor[] methodDescriptors, Method key)
{
for (int i = 0; i < methodDescriptors.length; i++)
{
if (key.equals(methodDescriptors[i].getMethod()))
return true;
}
return false;
}
}
|