AdmobAdapterCalculator { public int translateSourceIndexToWrapperPosition(int sourcePos, int fetchedAdsCount) { int adSpacesCount = 0; if(sourcePos >= getOffsetValue() && getNoOfDataBetweenAds() > 0) adSpacesCount = (sourcePos - getOffsetValue())/getNoOfDataBetweenAds() + 1; adSpacesCount = Math.min(fetchedAdsCount, adSpacesCount); adSpacesCount = Math.max(0, adSpacesCount); adSpacesCount = Math.min(adSpacesCount, getLimitOfAds()); int wrappedPosition = sourcePos + adSpacesCount; return wrappedPosition; }  int getNoOfDataBetweenAds(); void setNoOfDataBetweenAds(int mNoOfDataBetweenAds); int getFirstAdIndex(); void setFirstAdIndex(int firstAdIndex); int getLimitOfAds(); void setLimitOfAds(int mLimitOfAds); int getAdsCountToPublish(int fetchedAdsCount, int sourceItemsCount); int getOriginalContentPosition(int position, int fetchedAdsCount, int sourceItemsCount); int translateAdToWrapperPosition(int adPos); int translateSourceIndexToWrapperPosition(int sourcePos, int fetchedAdsCount); boolean canShowAdAtPosition(int position, int fetchedAdsCount); int getAdIndex(int position); boolean isAdPosition(int position); int getOffsetValue(); boolean isAdAvailable(int position, int fetchedAdsCount); boolean hasToFetchAd(int position, int fetchingAdsCount);  }
@Test public void testTranslateSourceIndexToWrapperPosition_Position0_Fetched3_Result1() throws Exception { setupAdmobAdapterCalculatorHelper(10, 0, 10); assertThat(admobAdapterCalculator.translateSourceIndexToWrapperPosition(0, 3), is(1)); }
@Test public void testTranslateSourceIndexToWrapperPosition_Position41_Fetched3_Result44() throws Exception { setupAdmobAdapterCalculatorHelper(10, 0, 10); assertThat(admobAdapterCalculator.translateSourceIndexToWrapperPosition(41,3), is(44)); }
@Test public void testTranslateSourceIndexToWrapperPosition_Position41_Fetched10_Result46() throws Exception { setupAdmobAdapterCalculatorHelper(10, 0, 10); assertThat(admobAdapterCalculator.translateSourceIndexToWrapperPosition(41,10), is(46)); }
@Test public void testTranslateSourceIndexToWrapperPosition_Position90_Fetched10_Result100() throws Exception { setupAdmobAdapterCalculatorHelper(10, 0, 10); assertThat(admobAdapterCalculator.translateSourceIndexToWrapperPosition(90,10), is(100)); }
@Test public void testTranslateSourceIndexToWrapperPosition_Position89_Fetched10_Result98() throws Exception { setupAdmobAdapterCalculatorHelper(10, 0, 10); assertThat(admobAdapterCalculator.translateSourceIndexToWrapperPosition(89,10), is(98)); }
@Test public void testTranslateSourceIndexToWrapperPosition_1stAdAt5_Position0_Fetched3_Result0() throws Exception { setupAdmobAdapterCalculatorHelper(10, 5, 10); assertThat(admobAdapterCalculator.translateSourceIndexToWrapperPosition(0,3), is(0)); }
@Test public void testTranslateSourceIndexToWrapperPosition_1stAdAt5_Position44_Fetched10_Result48() throws Exception { setupAdmobAdapterCalculatorHelper(10, 5, 10); assertThat(admobAdapterCalculator.translateSourceIndexToWrapperPosition(44, 10), is(48)); }
@Test public void testTranslateSourceIndexToWrapperPosition_1stAdAt5_Position45_Fetched10_Result50() throws Exception { setupAdmobAdapterCalculatorHelper(10, 5, 10); assertThat(admobAdapterCalculator.translateSourceIndexToWrapperPosition(45, 10), is(50)); }