IBConfig { public String getIBEndPointBulk(String token) { if (mIBEndPointBulk.containsKey(token)) { return mIBEndPointBulk.get(token); } String url = mIBPrefService.load(String.format("%s_%s", KEY_IB_END_POINT_BULK, token)); if (URLUtil.isValidUrl(url)) { mIBEndPointBulk.put(token, url); return url; } return DEFAULT_BULK_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 testGetIBEndPointBulk() throws Exception { String token = "token"; when(mPrefService.load(anyString())).thenReturn(""); assertEquals(mIBConfig.getIBEndPointBulk(token), IBConfig.DEFAULT_BULK_URL); assertEquals(mIBConfig.getIBEndPointBulk(token), IBConfig.DEFAULT_BULK_URL); verify(mPrefService, times(2)).load(anyString()); }
@Test public void testGetEndPointBulk2Times() throws Exception { String token = "token"; String customUrl = "http: String prefKey = String.format("%s_%s", IBConfig.KEY_IB_END_POINT_BULK, token); when(mPrefService.load(startsWith(prefKey))).thenReturn(customUrl); assertEquals(mIBConfig.getIBEndPointBulk(token), customUrl); assertEquals(mIBConfig.getIBEndPointBulk(token), customUrl); verify(mPrefService, times(1)).load(anyString()); }
@Test public void testNotValidUrlWasSavedEndPointBulk() throws Exception { String token = "token"; String customUrl = "blabla.com"; String prefKey = String.format("%s_%s", IBConfig.KEY_IB_END_POINT_BULK, token); when(mPrefService.load(startsWith(prefKey))).thenReturn(customUrl); assertEquals(mIBConfig.getIBEndPointBulk(token), IBConfig.DEFAULT_BULK_URL); }