java - Mocking a static method which calls another static method of the same class -


i have write unit test static method requires mocking static method of same class. sample code:

public class {    public static boolean foo(){}    public static boolean bar(){        return foo();    } }  @preparefortest({a.class}) public atest{    testmethod(){        mockstatic(a.class);        when(a.foo()).thenreturn(true);        asserttrue(a.bar());    } 

}

i have been trying unit test bar method far not been successful.

issue: debug doesn't reach return foo(); statement in code , assertion fails. please advice. cannot modify code @ point of time

any in mocking foo method appreciated.thanks!

the fact false default value boolean played bad trick. expecting wrong foo called, while in fact bar not called. long story short:

when(a.bar()).thencallrealmethod(); 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -