vendredi 23 janvier 2015

How can I mock GoogleCredential in order to test my business logic

I am writing a unit test for one of my application and part of that requires mocking out the GoogleCredential object of the google-api-java-client. We use service accounts to authenticate between services in our SOA. I would like to do something like:



GoogleCredential cred = mock(GoogleCredential.class);
when(cred.refreshToken()).thenReturn(true);


But I get an error during the "when" call indicating that the "lock" instance inside of the GoogleCredential object is null. Is there some way to get the GoogleCredential to successfully mock the method call?


Aucun commentaire:

Enregistrer un commentaire