IBConfig { public String getIBEndPoint(String token) { if (mIBEndPoint.containsKey(token)) { return mIBEndPoint.get(token); } String url = mIBPrefService.load(String.format("%s_%s", KEY_IB_END_POINT, token)); if (URLUtil.isValidUrl(url)) { mIBEndPoint.put(token, url); return url; } return DEFAULT_URL; } IBConfig(Context context); String getIBEndPoint(String token); String getIBEndPointBulk(String token); int getBulkSize(); int getFlushInterval(); long getMaximumRequestLimit(); long getMaximumDatabaseLimit(); int getNumOfRetries(); void enableErrorReporting(); boolean isErrorReportingEnabled(); boolean isAllowedOverRoaming(); void setAllowedOverRoaming(boolean allowed); void setAllowedNetworkTypes(int flags); @Override String toString();  }
@Test public void testGetIBEndPoint() throws Exception { String token = "token"; String prefKey = String.format("%s_%s", IBConfig.KEY_IB_END_POINT, token); when(mPrefService.load(startsWith(prefKey))).thenReturn(""); assertEquals(mIBConfig.getIBEndPoint(token), IBConfig.DEFAULT_URL); verify(mPrefService, times(1)).load(startsWith(prefKey)); }
@Test public void testGetIBEndPoint2Times() throws Exception { String token = "token"; String customUrl = "http: String prefKey = String.format("%s_%s", IBConfig.KEY_IB_END_POINT, token); when(mPrefService.load(startsWith(prefKey))).thenReturn(customUrl); assertEquals(mIBConfig.getIBEndPoint(token), customUrl); assertEquals(mIBConfig.getIBEndPoint(token), customUrl); verify(mPrefService, times(1)).load(startsWith(prefKey)); }
@Test public void testNotValidUrlWasSavedEndPoint() throws Exception { String token = "token"; String customUrl = "blabla.com"; String prefKey = String.format("%s_%s", IBConfig.KEY_IB_END_POINT, token); when(mPrefService.load(startsWith(prefKey))).thenReturn(customUrl); assertEquals(mIBConfig.getIBEndPoint(token), IBConfig.DEFAULT_URL); }