use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ClassReflectionTests method test_NoSuchMethodException.
/**
* Test getting a declared method with multiple params that doesn't exist.
*/
@Test
public void test_NoSuchMethodException() throws Exception {
try {
// Result r =
getDeclaredMethod("bogus", String.class, int.class);
fail("getting bogus method should fail");
} catch (ResultException e) {
assertNoSuchMethodException(TARGET_CLASS_NAME + ".bogus(java.lang.String, int)", e);
}
Result r = getDeclaredMethod("deleteThem", String.class, int.class);
assertMethod("public java.lang.String " + TARGET_CLASS_NAME + ".deleteThem(java.lang.String,int)", r);
reloadType("002");
try {
r = getDeclaredMethod("deleteThem", String.class, int.class);
fail("getting deleted method should fail");
} catch (ResultException e) {
assertNoSuchMethodException(TARGET_CLASS_NAME + ".deleteThem(java.lang.String, int)", e);
}
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ClassReflectionTests method test_getDeclaredMethodChangedAndInvoke.
/**
* Testing Class.getDeclaredMethod and Method.invoke
*
* Can we retrieve and invoke a method that existed before we reloaded the type, and was changed later.
*/
@Test
public void test_getDeclaredMethodChangedAndInvoke() throws Exception {
Result r = getDeclaredMethodAndInvoke("methodChanged");
Assert.assertEquals(1, r.returnValue);
reloadType("002");
r = getDeclaredMethodAndInvoke("methodChanged");
Assert.assertEquals(2, r.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ClassReflectionTests method test_getDeclaredProtectedMethod.
// Believe now failing due to quick fix to copy method/field for grails (~build 113)
/**
* Test to see if Method objects for 'protected' methods are correct (w.r.t. to modifier flags)
*/
@Test
public void test_getDeclaredProtectedMethod() throws Exception {
Result r = getDeclaredMethod("protectedMethod");
assertMethod("protected java.lang.String " + TARGET_CLASS_NAME + ".protectedMethod()", r);
reloadType("002");
r = getDeclaredMethod("protectedMethod");
assertMethod("protected java.lang.String " + TARGET_CLASS_NAME + ".protectedMethod()", r);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ClassReflectionTests method test_invokeProtectedInheritedMethod.
/**
* Test getDeclaredMethod and invoke for protected inherited method.
*/
@Test
public void test_invokeProtectedInheritedMethod() throws Exception {
String subClassName = TARGET_PACKAGE + ".SubClassTarget";
ReloadableType subTarget = registry.addType(subClassName, loadBytesForClass(subClassName));
try {
getDeclaredMethod(subTarget.getClazz(), "protectedMethod");
Assert.fail("A protected inherited method should not be considered 'declared' in the subclass");
} catch (ResultException e) {
assertNoSuchMethodException(subClassName + ".protectedMethod()", e);
}
//Next check if we can call the super class method on the sub instance
Object subInstance = subTarget.getClazz().newInstance();
Method m = (Method) getDeclaredMethod("protectedMethod").returnValue;
// because call is from different package!
m.setAccessible(true);
Result r = invokeOn(subInstance, m);
Assert.assertEquals("protectedMethod result", r.returnValue);
//Reload the subclass, method should now be defined on the subclass
reloadType(subTarget, "002");
r = getDeclaredMethod(subTarget.getClazz(), "protectedMethod");
assertMethod("protected java.lang.String " + subClassName + ".protectedMethod()", r);
m = (Method) r.returnValue;
try {
invokeOn(subInstance, m);
Assert.fail("invoker class is in different package than target class shouldn't be allowed to invoke protected method!");
} catch (ResultException e) {
assertIllegalAccess("Class " + callerClazz.getName() + " can not access a member of class " + subTarget.dottedtypename + " with modifiers \"protected\"", e);
}
m.setAccessible(true);
r = invokeOn(subInstance, m);
Assert.assertEquals("SubClassTarget002.protectedMethod", r.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ClassReflectionTests method test_invokePrivateMethodAllowed.
/**
* Invoking a private method by means of "invoke" call, from within the class containing the target method should be
* allowed.
*/
@Test
public void test_invokePrivateMethodAllowed() throws Exception {
Result r = getDeclaredMethodAndInvoke("callPrivateMethod");
Assert.assertEquals("privateMethod result", r.returnValue);
reloadType("002");
r = getDeclaredMethodAndInvoke("callPrivateMethod");
Assert.assertEquals("new privateMethod result", r.returnValue);
}
Aggregations