Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: making object "fit" with type where base class implements no interface and can't be inherited from
    primarykey
    data
    text
    <p>I am using the Twilio library and specifically I'm trying to inject a mock of TwilioRestClient when testing.</p> <p>It doesn't implement any interface. And I can't add one.</p> <p>I can't inherit from it, it does stuff in the constructor I'm not a fan of.</p> <p>I need to have a couple of methods in the mock that override or replace certain behavior of TwilioRestClient. </p> <p>How do I do this?</p> <p>I have tried inner anonymous classes to no avail. I have tried subclassing but obviously doesn't work. Any Java guru out there?</p> <p>edit, version of twilio sdk;</p> <pre><code>public class TwilioRestClient { /** The Constant VERSION. */ private static final String VERSION = "3.3.15"; </code></pre> <p>constructors:</p> <pre><code> /** * Explcitly construct a TwilioRestClient with the given API credentials. * * @param accountSid * the 34 character Account identifier (starting with 'AC'). This * can be found on your Twilio dashboard page. * @param authToken * the 32 character AuthToken. This can be found on your Twilio * dashboard page. * */ public TwilioRestClient(String accountSid, String authToken) { this(accountSid, authToken, null); } /** * Explcitly construct a TwilioRestClient with the given API credentials and * endpoint. * * @param accountSid * the 34 character Account identifier (starting with 'AC'). This * can be found on your Twilio dashboard page. * @param authToken * the 32 character AuthToken. This can be found on your Twilio * dashboard page. * @param endpoint * the url of API endpoint you wish to use. (e.g. - * 'https://api.twilio.com') */ public TwilioRestClient(String accountSid, String authToken, String endpoint) { validateAccountSid(accountSid); validateAuthToken(authToken); this.accountSid = accountSid; this.authToken = authToken; if ((endpoint != null) &amp;&amp; (!endpoint.equals(""))) { this.endpoint = endpoint; } //Grab the proper connection manager, based on runtime environment ClientConnectionManager mgr = null; try { Class.forName("com.google.appengine.api.urlfetch.HTTPRequest"); mgr = new AppEngineClientConnectionManager(); } catch (ClassNotFoundException e) { //Not GAE mgr = new ThreadSafeClientConnManager(); ((ThreadSafeClientConnManager) mgr).setDefaultMaxPerRoute(10); } setHttpclient(new DefaultHttpClient(mgr)); httpclient.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1); httpclient.getParams().setParameter("http.socket.timeout", new Integer(CONNECTION_TIMEOUT)); httpclient.getParams().setParameter("http.connection.timeout", new Integer(CONNECTION_TIMEOUT)); httpclient.getParams().setParameter("http.protocol.content-charset", "UTF-8"); this.authAccount = new Account(this); this.authAccount.setSid(this.accountSid); this.authAccount.setAuthToken(this.authToken); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload