Commit 5c216977 by andrewlewis Committed by Oliver Woodman

Replace IMA ad tag fakes with mocks

The mocking setup is quite messy/unclear compared to the fakes, but it seems
worth switching over because IMA API changes have already required changes
to fakes in the past, and there are more API changes in the version we are
about to upgrade to. This change should generally remove the need to keep
the fakes up-to-date.

PiperOrigin-RevId: 308819176
parent 1c34029e
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ext.ima;
import com.google.ads.interactivemedia.v3.api.Ad;
import com.google.ads.interactivemedia.v3.api.AdPodInfo;
import com.google.ads.interactivemedia.v3.api.CompanionAd;
import com.google.ads.interactivemedia.v3.api.UiElement;
import java.util.List;
import java.util.Set;
/** A fake ad for testing. */
/* package */ final class FakeAd implements Ad {
private final boolean skippable;
private final AdPodInfo adPodInfo;
public FakeAd(boolean skippable, int podIndex, int totalAds, int adPosition) {
this.skippable = skippable;
adPodInfo =
new AdPodInfo() {
@Override
public int getTotalAds() {
return totalAds;
}
@Override
public int getAdPosition() {
return adPosition;
}
@Override
public int getPodIndex() {
return podIndex;
}
@Override
public boolean isBumper() {
throw new UnsupportedOperationException();
}
@Override
public double getMaxDuration() {
throw new UnsupportedOperationException();
}
@Override
public double getTimeOffset() {
throw new UnsupportedOperationException();
}
};
}
@Override
public int getVastMediaWidth() {
throw new UnsupportedOperationException();
}
@Override
public int getVastMediaHeight() {
throw new UnsupportedOperationException();
}
@Override
public int getVastMediaBitrate() {
throw new UnsupportedOperationException();
}
@Override
public boolean isSkippable() {
return skippable;
}
@Override
public AdPodInfo getAdPodInfo() {
return adPodInfo;
}
@Override
public String getAdId() {
throw new UnsupportedOperationException();
}
@Override
public String getCreativeId() {
throw new UnsupportedOperationException();
}
@Override
public String getCreativeAdId() {
throw new UnsupportedOperationException();
}
@Override
public String getUniversalAdIdValue() {
throw new UnsupportedOperationException();
}
@Override
public String getUniversalAdIdRegistry() {
throw new UnsupportedOperationException();
}
@Override
public String getAdSystem() {
throw new UnsupportedOperationException();
}
@Override
public String[] getAdWrapperIds() {
throw new UnsupportedOperationException();
}
@Override
public String[] getAdWrapperSystems() {
throw new UnsupportedOperationException();
}
@Override
public String[] getAdWrapperCreativeIds() {
throw new UnsupportedOperationException();
}
@Override
public boolean isLinear() {
throw new UnsupportedOperationException();
}
@Override
public double getSkipTimeOffset() {
throw new UnsupportedOperationException();
}
@Override
public boolean isUiDisabled() {
throw new UnsupportedOperationException();
}
@Override
public String getDescription() {
throw new UnsupportedOperationException();
}
@Override
public String getTitle() {
throw new UnsupportedOperationException();
}
@Override
public String getContentType() {
throw new UnsupportedOperationException();
}
@Override
public String getAdvertiserName() {
throw new UnsupportedOperationException();
}
@Override
public String getSurveyUrl() {
throw new UnsupportedOperationException();
}
@Override
public String getDealId() {
throw new UnsupportedOperationException();
}
@Override
public int getWidth() {
throw new UnsupportedOperationException();
}
@Override
public int getHeight() {
throw new UnsupportedOperationException();
}
@Override
public String getTraffickingParameters() {
throw new UnsupportedOperationException();
}
@Override
public double getDuration() {
throw new UnsupportedOperationException();
}
@Override
public Set<UiElement> getUiElements() {
throw new UnsupportedOperationException();
}
@Override
public List<CompanionAd> getCompanionAds() {
throw new UnsupportedOperationException();
}
}
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ext.ima;
import com.google.ads.interactivemedia.v3.api.AdErrorEvent.AdErrorListener;
import com.google.ads.interactivemedia.v3.api.AdsManager;
import com.google.ads.interactivemedia.v3.api.AdsManagerLoadedEvent;
import com.google.ads.interactivemedia.v3.api.AdsRequest;
import com.google.ads.interactivemedia.v3.api.ImaSdkSettings;
import com.google.ads.interactivemedia.v3.api.StreamManager;
import com.google.ads.interactivemedia.v3.api.StreamRequest;
import com.google.android.exoplayer2.util.Assertions;
import java.util.ArrayList;
/** Fake {@link com.google.ads.interactivemedia.v3.api.AdsLoader} implementation for tests. */
public final class FakeAdsLoader implements com.google.ads.interactivemedia.v3.api.AdsLoader {
private final ImaSdkSettings imaSdkSettings;
private final AdsManager adsManager;
private final ArrayList<AdsLoadedListener> adsLoadedListeners;
private final ArrayList<AdErrorListener> adErrorListeners;
public FakeAdsLoader(ImaSdkSettings imaSdkSettings, AdsManager adsManager) {
this.imaSdkSettings = Assertions.checkNotNull(imaSdkSettings);
this.adsManager = Assertions.checkNotNull(adsManager);
adsLoadedListeners = new ArrayList<>();
adErrorListeners = new ArrayList<>();
}
@Override
public void contentComplete() {
// Do nothing.
}
@Override
public ImaSdkSettings getSettings() {
return imaSdkSettings;
}
@Override
public void requestAds(AdsRequest adsRequest) {
for (AdsLoadedListener listener : adsLoadedListeners) {
listener.onAdsManagerLoaded(
new AdsManagerLoadedEvent() {
@Override
public AdsManager getAdsManager() {
return adsManager;
}
@Override
public StreamManager getStreamManager() {
throw new UnsupportedOperationException();
}
@Override
public Object getUserRequestContext() {
return adsRequest.getUserRequestContext();
}
});
}
}
@Override
public String requestStream(StreamRequest streamRequest) {
throw new UnsupportedOperationException();
}
@Override
public void addAdsLoadedListener(AdsLoadedListener adsLoadedListener) {
adsLoadedListeners.add(adsLoadedListener);
}
@Override
public void removeAdsLoadedListener(AdsLoadedListener adsLoadedListener) {
adsLoadedListeners.remove(adsLoadedListener);
}
@Override
public void addAdErrorListener(AdErrorListener adErrorListener) {
adErrorListeners.add(adErrorListener);
}
@Override
public void removeAdErrorListener(AdErrorListener adErrorListener) {
adErrorListeners.remove(adErrorListener);
}
}
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.exoplayer2.ext.ima;
import com.google.ads.interactivemedia.v3.api.AdDisplayContainer;
import com.google.ads.interactivemedia.v3.api.AdsRequest;
import com.google.ads.interactivemedia.v3.api.player.ContentProgressProvider;
import java.util.List;
import java.util.Map;
/** Fake {@link AdsRequest} implementation for tests. */
public final class FakeAdsRequest implements AdsRequest {
private String adTagUrl;
private String adsResponse;
private Object userRequestContext;
private AdDisplayContainer adDisplayContainer;
private ContentProgressProvider contentProgressProvider;
@Override
public void setAdTagUrl(String adTagUrl) {
this.adTagUrl = adTagUrl;
}
@Override
public String getAdTagUrl() {
return adTagUrl;
}
@Override
public void setExtraParameter(String s, String s1) {
throw new UnsupportedOperationException();
}
@Override
public String getExtraParameter(String s) {
throw new UnsupportedOperationException();
}
@Override
public Map<String, String> getExtraParameters() {
throw new UnsupportedOperationException();
}
@Override
public void setUserRequestContext(Object userRequestContext) {
this.userRequestContext = userRequestContext;
}
@Override
public Object getUserRequestContext() {
return userRequestContext;
}
@Override
public AdDisplayContainer getAdDisplayContainer() {
return adDisplayContainer;
}
@Override
public void setAdDisplayContainer(AdDisplayContainer adDisplayContainer) {
this.adDisplayContainer = adDisplayContainer;
}
@Override
public ContentProgressProvider getContentProgressProvider() {
return contentProgressProvider;
}
@Override
public void setContentProgressProvider(ContentProgressProvider contentProgressProvider) {
this.contentProgressProvider = contentProgressProvider;
}
@Override
public String getAdsResponse() {
return adsResponse;
}
@Override
public void setAdsResponse(String adsResponse) {
this.adsResponse = adsResponse;
}
@Override
public void setAdWillAutoPlay(boolean b) {
throw new UnsupportedOperationException();
}
@Override
public void setAdWillPlayMuted(boolean b) {
throw new UnsupportedOperationException();
}
@Override
public void setContentDuration(float v) {
throw new UnsupportedOperationException();
}
@Override
public void setContentKeywords(List<String> list) {
throw new UnsupportedOperationException();
}
@Override
public void setContentTitle(String s) {
throw new UnsupportedOperationException();
}
@Override
public void setVastLoadTimeout(float v) {
throw new UnsupportedOperationException();
}
@Override
public void setLiveStreamPrefetchSeconds(float v) {
throw new UnsupportedOperationException();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment