use of org.springsource.loaded.test.infra.ResultException in project spring-loaded by spring-projects.
the class ClassReflectionTests method test_invokeStaticMethodAdded.
/**
* Test invoking a static method that didn't initialy exist.
*/
@Test
public void test_invokeStaticMethodAdded() throws Exception {
String methodName = "staticMethodAdded";
try {
Result r = getDeclaredMethod(methodName);
fail("Method shouldn't exist at first!\n" + r.toString());
} catch (ResultException e) {
assertNoSuchMethodException(TARGET_CLASS_NAME + "." + methodName + "()", e);
}
reloadType("002");
Result r = getDeclaredMethod(methodName);
assertMethod("public static int " + TARGET_CLASS_NAME + "." + methodName + "()", r);
Method m = (Method) r.returnValue;
// Calling the static method
//pass in null, it shouldn't need an instance since it's static!
r = invokeOn(null, m);
assertEquals(2, r.returnValue);
reloadType("003");
// Invoke again, using 'cached' copy of the method
//pass in null, it shouldn't need an instance since it's static!
r = invokeOn(null, m);
assertEquals(3, r.returnValue);
// Invoke again, using 'fresh' copy of the method
m = (Method) getDeclaredMethod(methodName).returnValue;
//pass in null, it shouldn't need an instance since it's static!
r = invokeOn(null, m);
assertEquals(3, r.returnValue);
}
use of org.springsource.loaded.test.infra.ResultException in project spring-loaded by spring-projects.
the class ClassReflectionTests method test_getDeclaredMethod_param_Added.
/**
* Testing Class.getDeclaredMethod and Method.invoke
*
* A method with a parameter - first it didn't exist - then is was added
*/
@Test
public void test_getDeclaredMethod_param_Added() throws Exception {
try {
getDeclaredMethod("doubleIt", String.class);
Assert.fail("Method shouldn't have existed");
} catch (ResultException e) {
assertNoSuchMethodException(TARGET_CLASS_NAME + ".doubleIt(java.lang.String)", e);
}
reloadType("002");
Result r = getDeclaredMethod("doubleIt", String.class);
assertMethod("public java.lang.String " + TARGET_CLASS_NAME + ".doubleIt(java.lang.String)", r);
r = invoke((Method) r.returnValue, "hi");
Assert.assertEquals("hihi", r.returnValue);
}
use of org.springsource.loaded.test.infra.ResultException in project spring-loaded by spring-projects.
the class ClassReflectionTests method test_cacheGetDeclaredMethodDeletedAndInvoke.
/**
* Testing Class.getDeclaredMethod and Method.invoke
*
* What happens if we invoke a cached Method object when the method it refers to was deleted?
*/
@Test
public void test_cacheGetDeclaredMethodDeletedAndInvoke() throws Exception {
Method m = (Method) getDeclaredMethod("methodDeleted").returnValue;
Result r = invoke(m);
Assert.assertEquals(37, r.returnValue);
reloadType("002");
try {
invoke(m);
fail("Invoking a deleted method should fail");
} catch (ResultException e) {
assertNoSuchMethodError(TARGET_CLASS_NAME + ".methodDeleted()I", e);
}
}
use of org.springsource.loaded.test.infra.ResultException in project spring-loaded by spring-projects.
the class ClassReflectionTests method test_invokeStaticMethodAddedWithNullParams.
/**
* Test invoking a static method that didn't initialy exist.
*/
@Test
public void test_invokeStaticMethodAddedWithNullParams() throws Exception {
String methodName = "staticMethodAdded";
try {
Result r = getDeclaredMethod(methodName);
fail("Method shouldn't exist at first!\n" + r.toString());
} catch (ResultException e) {
assertNoSuchMethodException(TARGET_CLASS_NAME + "." + methodName + "()", e);
}
reloadType("002");
Result r = getDeclaredMethod(methodName);
assertMethod("public static int " + TARGET_CLASS_NAME + "." + methodName + "()", r);
Method m = (Method) r.returnValue;
// This should be ok, since the method expects no params (should not cause an NPE)
Object[] params = null;
// Calling the static method
//pass in null, it shouldn't need an instance since it's static!
r = invokeOn(null, m, params);
assertEquals(2, r.returnValue);
reloadType("003");
// Invoke again, using 'cached' copy of the method
//pass in null, it shouldn't need an instance since it's static!
r = invokeOn(null, m, params);
assertEquals(3, r.returnValue);
// Invoke again, using 'fresh' copy of the method
m = (Method) getDeclaredMethod(methodName).returnValue;
//pass in null, it shouldn't need an instance since it's static!
r = invokeOn(null, m, params);
assertEquals(3, r.returnValue);
}
use of org.springsource.loaded.test.infra.ResultException in project spring-loaded by spring-projects.
the class ClassReflectionTests method test_getDeclaredMethodDeleted.
/**
* Testing Class.getDeclaredMethod() - first the method exists - then it is deleted
*/
@Test
public void test_getDeclaredMethodDeleted() throws Exception {
Result r = getDeclaredMethod("methodDeleted");
assertMethod("public int " + TARGET_CLASS_NAME + ".methodDeleted()", r);
reloadType("002");
try {
r = getDeclaredMethod("methodDeleted");
Assert.fail("The method shouldn't exist anymore!");
} catch (ResultException e) {
assertNoSuchMethodException(TARGET_CLASS_NAME + ".methodDeleted()", e);
}
}
Aggregations