■ MyAbstractClass.java
public abstract class MyAbstractClass {
publicMyAbstractClass(){
}
public abstract int notifyAbs(inta);
}
■ MyClassAbstractInnerClass.java
publicclassMyClassAbstractInnerClass{
privateMyAbstractClass testAbstract=newMyAbstractClass(){
@ Override
public int notifyAbs(inta){
return a;
}
};
}
Is it possible to have external access to the method (notifyAbs) of the private class instance (testAbstract) that inherits the above abstract class?
I'd like to test notifyAbs on JUnit, but I don't know how to access it.
"If you search the net in ""junit private method test"", you will find many things."
For example:
Method method=Sample.class.getDeclaredMethod("getName", Integer.class);
method.setAccessible(true);
String resetl=(String)method.invoke(new Sample(), new Integer(1));
Note: http://javatechnology.net/java/private-junit/
Thank you for your reply.Access to private classes, private methods, and inner classes has been realized, but it has never been possible in a field that inherits an abstract class such as the subject and has a method inside it.
publicclassMyClassAbstractInnerClass{
private InnerClass testAbstract = new InnerClass();
public class InnerClass extensions MyAbstractClass{
@ Override
public int notifyAbs(inta){
return a;
}
}
}
Thus, by separating the declaration and processing of the fields as described above, we have achieved access to notifyAbs().
542 Unable to install versioned in Google Colab
546 Understanding How to Configure Google API Key
537 Uncaught (inpromise) Error on Electron: An object could not be cloned
549 PHP ssh2_scp_send fails to send files as intended
709 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.