当前位置: 首页>>代码示例>>Java>>正文


Java Expression.getValue方法代码示例

本文整理汇总了Java中java.beans.Expression.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java Expression.getValue方法的具体用法?Java Expression.getValue怎么用?Java Expression.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.beans.Expression的用法示例。


在下文中一共展示了Expression.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testStatic

import java.beans.Expression; //导入方法依赖的package包/类
/**
 * The test checks the correct static method is initialized
 */
public void testStatic() throws Exception {
    SampleBean theBean = new SampleBean();
    Expression expr = new Expression(SampleBean.class, "create",
            new Object[] { "hello", theBean });

    Object result = expr.getValue();
    if (result != null && result instanceof SampleBean) {
        SampleBean bean = (SampleBean) result;
        assertEquals("hello", bean.getText());
        assertEquals(theBean, bean.getObject());
    } else {
        fail("Cannot instantiate an instance of Bean class by "
                + "static method.");
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:19,代码来源:ExpressionTest.java

示例2: getMethodValue

import java.beans.Expression; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <E,R> R getMethodValue(E obj, Method method, Object... args) {
	R value = null;

	try {
		method.setAccessible(true);

		value = (R) method.invoke(obj, args);
	} catch (InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
		// e.printStackTrace();
		try {
			if (obj != null) {
				Expression expr = new Expression(obj, method.getName(), args);
				expr.execute();
				value = (R) expr.getValue();
			}

			if (value == null) {
				value = (R) method.getDefaultValue();
			}

		} catch (Exception e1) {
			// e1.printStackTrace();
		}
	}

	return value;
}
 
开发者ID:osonus,项目名称:oson,代码行数:29,代码来源:ObjectUtil.java

示例3: testConstructor

import java.beans.Expression; //导入方法依赖的package包/类
/**
 * The test checks the correct constructor is initialized
 */
public void testConstructor() throws Exception {
    Expression expr = new Expression(SampleBean.class, "new",
            new Object[] { "hello" });
    Object result = expr.getValue();
    if (result != null && result instanceof SampleBean) {
        SampleBean bean = (SampleBean) result;
        assertEquals("hello", bean.getText());
    } else {
        fail("Cannot instantiate an instance of Bean class.");
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:15,代码来源:ExpressionTest.java

示例4: testGetter

import java.beans.Expression; //导入方法依赖的package包/类
/**
 * The test checks the correct getter is initialized
 */
public void testGetter() throws Exception {
    Expression expr = new Expression(new SampleBean("hello"), "getText",
            new Object[] {});

    Object result = expr.getValue();
    if (result != null && result instanceof String) {
        assertEquals("hello", result);
    } else {
        fail("Result of SampleBean.getText() call is not "
                + "of String type.");
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:16,代码来源:ExpressionTest.java

示例5: testArrayGetter

import java.beans.Expression; //导入方法依赖的package包/类
/**
 * The test checks the correct array getter is initialized
 */
public void testArrayGetter() throws Exception {
    int[] a = { 1, 2, 3 };
    Expression expr = new Expression(a, "get",
            new Object[] { new Integer(1) });

    Object result = expr.getValue();
    if (result != null && result instanceof Integer) {
        assertEquals(new Integer(2), result);
    } else {
        fail("Result of array getter is not of Integer type.");
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:16,代码来源:ExpressionTest.java

示例6: testGetValue_UnboundedExceptionalMethod

import java.beans.Expression; //导入方法依赖的package包/类
public void testGetValue_UnboundedExceptionalMethod() throws Exception {
    MockObject mo = new MockObject(false);
    Expression t = new Expression(mo, "method", new Object[] { null, null });
    try {
        t.getValue();
        fail("Should throw NullPointerException!");
    } catch (NullPointerException ex) {
        // expected
    }
    MockObject.assertCalled("method4", new Object[] { null, null });
}
 
开发者ID:shannah,项目名称:cn1,代码行数:12,代码来源:ExpressionTest.java

示例7: testGetValue_UnboundedNonExistingMethod

import java.beans.Expression; //导入方法依赖的package包/类
public void testGetValue_UnboundedNonExistingMethod() throws Exception {
    MockObject mo = new MockObject(false);
    Expression t = new Expression(mo, "method_not_existing", new Object[] {
            null, null });
    try {
        t.getValue();
        fail("Should throw NoSuchMethodException!");
    } catch (NoSuchMethodException ex) {
        // expected
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:12,代码来源:ExpressionTest.java

示例8: testGetValue_UnboundedNullTarget

import java.beans.Expression; //导入方法依赖的package包/类
public void testGetValue_UnboundedNullTarget() throws Exception {
    Expression t = new Expression(null, "method_not_existing",
            new Object[] { null, null });
    try {
        t.getValue();
        fail("Should throw NullPointerException!");
    } catch (NullPointerException ex) {
        // expected
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:11,代码来源:ExpressionTest.java

示例9: testGetValue_UnboundedNullMethodName

import java.beans.Expression; //导入方法依赖的package包/类
public void testGetValue_UnboundedNullMethodName() throws Exception {
    MockObject mo = new MockObject(false);
    Expression t = new Expression(mo, null, new Object[] { null, null });
    try {
        t.getValue();
        fail("Should throw NullPointerException!");
    } catch (NullPointerException ex) {
        // expected
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:11,代码来源:ExpressionTest.java

示例10: testGetValue_UnboundedInvalidArguments

import java.beans.Expression; //导入方法依赖的package包/类
public void testGetValue_UnboundedInvalidArguments() throws Exception {
    MockObject mo = new MockObject(false);
    Expression t = new Expression(mo, "method", new Object[] {
            new Object(), new Object(), new Object() });
    try {
        t.getValue();
        fail("Should throw NoSuchMethodException!");
    } catch (NoSuchMethodException ex) {
        // expected
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:12,代码来源:ExpressionTest.java

示例11: testGetValue_UnboundedExceptionalConstructor

import java.beans.Expression; //导入方法依赖的package包/类
public void testGetValue_UnboundedExceptionalConstructor() throws Exception {
    Expression t = new Expression(MockObject.class, "new", new Object[] {
            null, null });
    try {
        t.getValue();
        fail("Should throw NullPointerException!");
    } catch (NullPointerException ex) {
        // expected
    }
    MockObject.assertCalled("new4", new Object[] { null, null });
}
 
开发者ID:shannah,项目名称:cn1,代码行数:12,代码来源:ExpressionTest.java

示例12: testGetValue_UnboundedNonExistingConstructor

import java.beans.Expression; //导入方法依赖的package包/类
public void testGetValue_UnboundedNonExistingConstructor() throws Exception {
    Expression t = new Expression(MockObject.class, "new", new Object[] {
            null, null, null });
    try {
        t.getValue();
        fail("Should throw NoSuchMethodException!");
    } catch (NoSuchMethodException ex) {
        // expected
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:11,代码来源:ExpressionTest.java

示例13: testGetValue_UnboundedArrayInvalidSetInt

import java.beans.Expression; //导入方法依赖的package包/类
public void testGetValue_UnboundedArrayInvalidSetInt() throws Exception {
    int[] array = new int[] { 1 };
    Expression t = new Expression(array, "getInt",
            new Object[] { new Integer(0) });
    try {
        t.getValue();
        fail("Should throw NoSuchMethodException!");
    } catch (NoSuchMethodException ex) {
        // expected
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:12,代码来源:ExpressionTest.java

示例14: testGetValue_UnboundedArrayInvalidName

import java.beans.Expression; //导入方法依赖的package包/类
public void testGetValue_UnboundedArrayInvalidName() throws Exception {
    Object[] array = new Object[] { "test" };
    Expression t = new Expression(array, "gets", new Object[] {
            new Integer(0), new Object() });
    try {
        t.getValue();
        fail("Should throw NoSuchMethodException!");
    } catch (NoSuchMethodException ex) {
        // expected
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:12,代码来源:ExpressionTest.java

示例15: testGetValue_ProtectedMethodWithPackage

import java.beans.Expression; //导入方法依赖的package包/类
public void testGetValue_ProtectedMethodWithPackage() throws Exception {
    DefaultPersistenceDelegate dpd = new DefaultPersistenceDelegate();
    Object[] arguments = new Object[] { "test", "test" };
    Expression t = new Expression(dpd, "mutatesTo", arguments);
    try {
        t.getValue();
        fail("Should throw NoSuchMethodException!");
    } catch (NoSuchMethodException e) {
        // expected
    }
}
 
开发者ID:shannah,项目名称:cn1,代码行数:12,代码来源:ExpressionTest.java


注:本文中的java.beans.Expression.getValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。