@Test public void isOrientationMatched() { NetworkConfig networkConfig = new TestNetworkConfig(null); boolean result = networkConfig.isOrientationMatched(null); assertTrue(result); result = networkConfig.isOrientationMatched(new HashMap<String, String>()); assertTrue(result); result = networkConfig.isOrientationMatched(new HashMap<String, String>() {{ put(NetworkConfig.CONFIG_ORIENTATION, "test_value"); }}); assertTrue(result); result = networkConfig.isOrientationMatched(new HashMap<String, String>() {{ put(NetworkConfig.CONFIG_ORIENTATION, Orientation.Undefined.toString()); }}); assertTrue(result); BidMachineImpl.get().appContext = context; context.getResources().getConfiguration().orientation = Configuration.ORIENTATION_PORTRAIT; result = networkConfig.isOrientationMatched(new HashMap<String, String>() {{ put(NetworkConfig.CONFIG_ORIENTATION, Orientation.Portrait.toString()); }}); assertTrue(result); context.getResources().getConfiguration().orientation = Configuration.ORIENTATION_LANDSCAPE; result = networkConfig.isOrientationMatched(new HashMap<String, String>() {{ put(NetworkConfig.CONFIG_ORIENTATION, Orientation.Landscape.toString()); }}); assertTrue(result); context.getResources().getConfiguration().orientation = Configuration.ORIENTATION_LANDSCAPE; result = networkConfig.isOrientationMatched(new HashMap<String, String>() {{ put(NetworkConfig.CONFIG_ORIENTATION, Orientation.Portrait.toString()); }}); assertFalse(result); context.getResources().getConfiguration().orientation = Configuration.ORIENTATION_PORTRAIT; result = networkConfig.isOrientationMatched(new HashMap<String, String>() {{ put(NetworkConfig.CONFIG_ORIENTATION, Orientation.Landscape.toString()); }}); assertFalse(result); }
@VisibleForTesting boolean isOrientationMatched(@Nullable Map<String, String> config) { if (config == null) { return true; } String orientation = config.get(CONFIG_ORIENTATION); if (TextUtils.isEmpty(orientation)) { return true; } Orientation requiredOrientation; try { requiredOrientation = Orientation.valueOf(orientation); } catch (Exception e) { return true; } if (requiredOrientation == Orientation.Undefined) { return true; } int currentOrientation = Utils.getOrientation(); if (requiredOrientation == Orientation.Portrait && currentOrientation == Configuration.ORIENTATION_PORTRAIT) { return true; } else return requiredOrientation == Orientation.Landscape && currentOrientation == Configuration.ORIENTATION_LANDSCAPE; }
NetworkConfig { @VisibleForTesting boolean isOrientationMatched(@Nullable Map<String, String> config) { if (config == null) { return true; } String orientation = config.get(CONFIG_ORIENTATION); if (TextUtils.isEmpty(orientation)) { return true; } Orientation requiredOrientation; try { requiredOrientation = Orientation.valueOf(orientation); } catch (Exception e) { return true; } if (requiredOrientation == Orientation.Undefined) { return true; } int currentOrientation = Utils.getOrientation(); if (requiredOrientation == Orientation.Portrait && currentOrientation == Configuration.ORIENTATION_PORTRAIT) { return true; } else return requiredOrientation == Orientation.Landscape && currentOrientation == Configuration.ORIENTATION_LANDSCAPE; } }
NetworkConfig { @VisibleForTesting boolean isOrientationMatched(@Nullable Map<String, String> config) { if (config == null) { return true; } String orientation = config.get(CONFIG_ORIENTATION); if (TextUtils.isEmpty(orientation)) { return true; } Orientation requiredOrientation; try { requiredOrientation = Orientation.valueOf(orientation); } catch (Exception e) { return true; } if (requiredOrientation == Orientation.Undefined) { return true; } int currentOrientation = Utils.getOrientation(); if (requiredOrientation == Orientation.Portrait && currentOrientation == Configuration.ORIENTATION_PORTRAIT) { return true; } else return requiredOrientation == Orientation.Landscape && currentOrientation == Configuration.ORIENTATION_LANDSCAPE; } protected  NetworkConfig(@Nullable Map<String, String> networkParams); }
NetworkConfig { @VisibleForTesting boolean isOrientationMatched(@Nullable Map<String, String> config) { if (config == null) { return true; } String orientation = config.get(CONFIG_ORIENTATION); if (TextUtils.isEmpty(orientation)) { return true; } Orientation requiredOrientation; try { requiredOrientation = Orientation.valueOf(orientation); } catch (Exception e) { return true; } if (requiredOrientation == Orientation.Undefined) { return true; } int currentOrientation = Utils.getOrientation(); if (requiredOrientation == Orientation.Portrait && currentOrientation == Configuration.ORIENTATION_PORTRAIT) { return true; } else return requiredOrientation == Orientation.Landscape && currentOrientation == Configuration.ORIENTATION_LANDSCAPE; } protected  NetworkConfig(@Nullable Map<String, String> networkParams); @NonNull String getKey(); @Nullable String getVersion(); @NonNull NetworkAdapter obtainNetworkAdapter(); @SuppressWarnings({"unchecked", "WeakerAccess"}) T withNetworkParams(@Nullable Map<String, String> config); @SuppressWarnings({"unchecked", "unused"}) T setNetworkParam(@NonNull String key, @NonNull String value); @SuppressWarnings({"unchecked", "WeakerAccess", "unused"}) T withBaseMediationConfig(@Nullable Map<String, String> config); @SuppressWarnings({"unchecked", "WeakerAccess", "unused"}) T setBaseMediationParam(@NonNull String key,
                                                             @NonNull String value); @SuppressWarnings({"WeakerAccess"}) T withMediationConfig(@NonNull AdsFormat adsFormat,
                                                           @Nullable Map<String, String> config); T withMediationConfig(@NonNull AdsFormat adsFormat,
                                                           @Nullable Map<String, String> config,
                                                           @NonNull Orientation orientation); NetworkConfig forAdTypes(@NonNull AdsType... adsType); @Nullable Map<String, String> peekMediationConfig(@NonNull AdsType adsType,
                                                                                      @NonNull T adRequestParams,
                                                                                      @NonNull AdContentType adContentType); @Override boolean equals(Object o); @Override int hashCode(); }
NetworkConfig { @VisibleForTesting boolean isOrientationMatched(@Nullable Map<String, String> config) { if (config == null) { return true; } String orientation = config.get(CONFIG_ORIENTATION); if (TextUtils.isEmpty(orientation)) { return true; } Orientation requiredOrientation; try { requiredOrientation = Orientation.valueOf(orientation); } catch (Exception e) { return true; } if (requiredOrientation == Orientation.Undefined) { return true; } int currentOrientation = Utils.getOrientation(); if (requiredOrientation == Orientation.Portrait && currentOrientation == Configuration.ORIENTATION_PORTRAIT) { return true; } else return requiredOrientation == Orientation.Landscape && currentOrientation == Configuration.ORIENTATION_LANDSCAPE; } protected  NetworkConfig(@Nullable Map<String, String> networkParams); @NonNull String getKey(); @Nullable String getVersion(); @NonNull NetworkAdapter obtainNetworkAdapter(); @SuppressWarnings({"unchecked", "WeakerAccess"}) T withNetworkParams(@Nullable Map<String, String> config); @SuppressWarnings({"unchecked", "unused"}) T setNetworkParam(@NonNull String key, @NonNull String value); @SuppressWarnings({"unchecked", "WeakerAccess", "unused"}) T withBaseMediationConfig(@Nullable Map<String, String> config); @SuppressWarnings({"unchecked", "WeakerAccess", "unused"}) T setBaseMediationParam(@NonNull String key,
                                                             @NonNull String value); @SuppressWarnings({"WeakerAccess"}) T withMediationConfig(@NonNull AdsFormat adsFormat,
                                                           @Nullable Map<String, String> config); T withMediationConfig(@NonNull AdsFormat adsFormat,
                                                           @Nullable Map<String, String> config,
                                                           @NonNull Orientation orientation); NetworkConfig forAdTypes(@NonNull AdsType... adsType); @Nullable Map<String, String> peekMediationConfig(@NonNull AdsType adsType,
                                                                                      @NonNull T adRequestParams,
                                                                                      @NonNull AdContentType adContentType); @Override boolean equals(Object o); @Override int hashCode();  }