Beispiel #1
0
  /*
   * Test the constructor with null arguments.
   */
  public void testConstructor_NullArguments() {
    Object target = new MockParent();
    Expression t = new Expression(target, "method", null);

    assertSame(target, t.getTarget());
    assertSame("method", t.getMethodName());
    assertEquals(0, t.getArguments().length);

    assertEquals("<unbound>=ExpressionTest$MockParent.method();", t.toString());
  }
Beispiel #2
0
  /*
   * Test the constructor with the method name "new".
   */
  public void testConstructor_NewMethodName() {
    Object target = MockObject.class;
    Object[] oa = new Object[] {new Object()};
    Expression t = new Expression(target, "new", oa);

    assertSame(target, t.getTarget());
    assertSame("new", t.getMethodName());
    assertSame(oa, t.getArguments());

    assertEquals("<unbound>=Class.new(Object);", t.toString());
  }
Beispiel #3
0
  /*
   * Test the constructor(value, ...) with null arguments.
   */
  public void testConstructor_Value_NullArguments() throws Exception {
    Object val = new Object();
    Object target = new Object();
    Expression t = new Expression(val, target, "method", null);

    assertSame(val, t.getValue());
    assertSame(target, t.getTarget());
    assertSame("method", t.getMethodName());
    assertEquals(0, t.getArguments().length);

    assertEquals("Object=Object.method();", t.toString());
  }
Beispiel #4
0
  /*
   * Test the constructor with a null argument.
   */
  public void testConstructor_NullArgument() {
    Object target = new MockParent();
    Object[] oa = new Object[] {null};
    Expression t = new Expression(target, "method", oa);

    assertSame(target, t.getTarget());
    assertSame("method", t.getMethodName());
    assertSame(oa, t.getArguments());
    assertNull(t.getArguments()[0]);

    assertEquals("<unbound>=ExpressionTest$MockParent.method(null);", t.toString());
  }
Beispiel #5
0
  /*
   * Test the constructor(value, ...) with a null value.
   */
  public void testConstructor_Value_NullValue() throws Exception {
    Object target = new Object();
    Object[] oa = new Object[] {null};
    Expression t = new Expression(null, target, "method", oa);

    assertSame(null, t.getValue());
    assertSame(target, t.getTarget());
    assertSame("method", t.getMethodName());
    assertSame(oa, t.getArguments());
    assertNull(t.getArguments()[0]);

    assertEquals("null=Object.method(null);", t.toString());
  }
Beispiel #6
0
  /*
   * Test the constructor(value, ...) with empty method name.
   */
  public void testConstructor_Value_EmptyMethodName() throws Exception {
    Object val = new Object();
    Object target = new Object();
    Object[] oa = new Object[] {new Object()};
    Expression t = new Expression(val, target, "", oa);

    assertSame(val, t.getValue());
    assertSame(target, t.getTarget());
    assertSame("", t.getMethodName());
    assertSame(oa, t.getArguments());

    assertEquals("Object=Object.(Object);", t.toString());
  }
Beispiel #7
0
  /*
   * Test the constructor(value, ...) with null target.
   */
  public void testConstructor_Value_NullTarget() throws Exception {
    Object val = new Object();
    Object arg = new Object();
    Object[] oa = new Object[] {arg};
    Expression t = new Expression(val, null, "method", oa);

    assertSame(val, t.getValue());
    assertSame(null, t.getTarget());
    assertSame("method", t.getMethodName());
    assertSame(oa, t.getArguments());
    assertSame(arg, t.getArguments()[0]);

    assertEquals("Object=null.method(Object);", t.toString());
  }
Beispiel #8
0
  /*
   * Test the constructor(value, ...) with an array target.
   */
  public void testConstructor_Value_ArrayTarget() throws Exception {
    Integer val = new Integer(69);
    Object target = new Integer[] {val};
    Object arg = new Integer(0);
    Object[] oa = new Object[] {arg};
    Expression t = new Expression(val, target, "get", oa);

    assertSame(val, t.getValue());
    assertSame(target, t.getTarget());
    assertSame("get", t.getMethodName());
    assertSame(oa, t.getArguments());
    assertSame(arg, t.getArguments()[0]);

    assertEquals("Integer=IntegerArray.get(Integer);", t.toString());
  }
Beispiel #9
0
  /*
   * Test the constructor under normal conditions.
   */
  public void testConstructor_Normal() {
    Object target = new MockParent();
    Object arg1 = "string1";
    Object arg2 = new Object();
    Object arg3 = "string3";
    Object arg4 = new Integer(117);
    Object[] oa = new Object[] {arg1, arg2, arg3, arg4};
    Expression t = new Expression(target, "method", oa);

    assertSame(target, t.getTarget());
    assertSame("method", t.getMethodName());
    assertSame(oa, t.getArguments());
    assertSame(arg1, t.getArguments()[0]);
    assertSame(arg2, t.getArguments()[1]);
    assertSame(arg3, t.getArguments()[2]);
    assertSame(arg4, t.getArguments()[3]);

    assertEquals(
        "<unbound>=ExpressionTest$MockParent.method("
            + "\"string1\", Object, \"string3\", Integer);",
        t.toString());
  }
Beispiel #10
0
  /*
   * Test the constructor(value, ...) under normal conditions.
   */
  public void testConstructor_Value_Normal() throws Exception {
    Object val = new Object();
    Object target = new MockParent();
    Object arg1 = "mama";
    Object arg2 = new Object();
    Object arg3 = new Object();
    Object arg4 = new Long(7);
    Object[] oa = new Object[] {arg1, arg2, arg3, arg4};
    Expression t = new Expression(val, target, "method", oa);

    assertSame(val, t.getValue());
    assertSame(target, t.getTarget());
    assertSame("method", t.getMethodName());
    assertSame(oa, t.getArguments());
    assertSame(arg1, t.getArguments()[0]);
    assertSame(arg2, t.getArguments()[1]);
    assertSame(arg3, t.getArguments()[2]);
    assertSame(arg4, t.getArguments()[3]);

    assertEquals(
        "Object=ExpressionTest$MockParent.method(" + "\"mama\", Object, Object, Long);",
        t.toString());
  }
Beispiel #11
0
 /*
  * Test the constructor(value, ...) with a expression value.
  */
 public void testConstructor_EmptyTarget_EmptyMethod_ExpressionArguments() {
   Object[] objectArray =
       new Object[] {new Expression((Object) null, (String) null, (Object[]) null)};
   Expression expression = new Expression(objectArray, new String(), new String(), objectArray);
   assertEquals("ObjectArray=\"\".(Expression);", expression.toString());
 }