本文整理汇总了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.");
}
}
示例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;
}
示例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.");
}
}
示例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.");
}
}
示例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.");
}
}
示例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 });
}
示例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
}
}
示例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
}
}
示例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
}
}
示例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
}
}
示例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 });
}
示例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
}
}
示例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
}
}
示例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
}
}
示例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
}
}