Exemplo n.º 1
0
 private GenericField[] fields(ReflectClass personClass) {
   return new GenericField[] {
     new GenericField("surname", _reflector.forClass(String.class), false),
     new GenericField("birthdate", _reflector.forClass(Date.class), false),
     new GenericField("bestFriend", personClass, false)
   };
 }
Exemplo n.º 2
0
 public GenericObjects() throws ClassNotFoundException {
   _reflector =
       new GenericReflector(
           null, new JdkReflector(Thread.currentThread().getContextClassLoader()));
   _reflector.configuration(new MockReflectorConfiguration());
   _objectIClass = (GenericClass) _reflector.forClass(Object.class);
 }
Exemplo n.º 3
0
  public void test() throws ClassNotFoundException {
    _reflector.register(acmeDataClass());
    _iClass = (GenericClass) _reflector.forName("com.acme.Person");
    _assert(_iClass.getName().equals("com.acme.Person"));
    _assert(_iClass.getSuperclass() == _objectIClass);

    _assert(_iClass.isAssignableFrom(subclass()));
    _assert(!_iClass.isAssignableFrom(otherDataClass()));
    _assert(!_iClass.isAssignableFrom(_objectIClass));

    _assert(_iClass.isInstance(_iClass.newInstance()));
    _assert(_iClass.isInstance(subclass().newInstance()));
    _assert(!_iClass.isInstance(otherDataClass().newInstance()));
    _assert(!_iClass.isInstance("whatever"));

    _assert(_reflector.forObject(_iClass.newInstance()) == _iClass);

    tstFields();
    tstReflectionDelegation();
  }