Package com.example.test.reflect2

Source Code of com.example.test.reflect2.Test1

package com.example.test.reflect2;

import java.util.List;
import com.example.test.reflect1.IFoo;
import com.example.test.reflect1.MethodRecordingObject;
import com.example.test.reflect1.ThingFactory;

public class Test1 extends InvokeTestHarness
{
   @Override public void checkInvocation(Object obj, String method, Object expectedReturnValue, Object... arguments)
   {
    Object result = ReflectInvocations.invoke(obj, method, arguments);
    boolean success = (expectedReturnValue == null) ? (result == null) : (expectedReturnValue.equals(result));
    if (!success)
      throw new InvokeTestHarness.TestFailure("unexpected return value: "+result);
  }

  @Override public void checkProxyInvocation(MethodRecordingObject obj, String method, String expectedSignature, Object... arguments) {
    Object result = ReflectInvocations.invoke(obj, method, arguments);
    String signature = obj.describeLastMethod();
    boolean success = expectedSignature.equals(signature);
    if (!success)
      throw new InvokeTestHarness.TestFailure("unexpected signature: "+signature);
  }

  @Override public void onFailure(AbstractTestItem<?> item, TestFailure tf) {
    System.err.println(tf.getMessage());
    System.err.println(item);
    tf.printStackTrace(System.err);   
  }
 
  public Test1(List<AbstractTestItem<?>> items)
  {
    super(items);
  }
 
  public static void main(String[] args) {
    ThingFactory factory = new ThingFactory();
    int n = factory.getThingCount();
    Object[] thing = new Object[n+1];
    for (int i = 1; i <= n; ++i)
      thing[i] = factory.getThing(i);
   
    Object object0 = new Object();
    Test1 test = new Test1(
      InvokeTestHarness.testItemsBuilder()
        .setObject(thing[1]).setMethodName("compute")
        .addItem(    1, object0, "hi")
        .addItem(    2, object0, object0)
        .addItem(    3, 1, "hi")       
        .addItem(   11, thing[1], 33)
        .addItem("S12", object0, 3.14159)
        .addItem(   13, "hi there", 22)
        .build());
    test.run();
 
}
TOP

Related Classes of com.example.test.reflect2.Test1

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.