lundi 6 juin 2016

NoSuchMethodException using getDeclaredMethod on abstract class

I am trying to test a method using reflection. I have tried setting it to private, protected and public (always using getDeclaredMethod(s)) but it doesn't seem to show up in the list, for some reason.

The class being tested:

public abstract class ParentClass
{
    ...
    public Response aMethod()
    {
        return doThings(argument1, argument2);
    }
    ...
}

Contents of the test (JUnit):

ChildClass child = new ChildClass(stuff);
Method method = ParentClass.class.getDeclaredMethod("aMethod");
method.setAccessible(true);
return method.invoke(child);

Or simply getDeclaredMethods();, it doesn't show up in there either.

What could be going wrong? I thought it might not be building correctly since I have just added the method, but I tried to rebuild the project manually in Eclipse, and it has not solved anything. If it matters, I run the test through Maven, though it doesn't work when ran directly in Eclipse's JUnit module either.





Aucun commentaire:

Enregistrer un commentaire