@Test public void testGenerateUserAgent_multipleUtilitiesRegistered_includeUtilitiesTrue() { when(adsLibConfiguration.isIncludeAdsUtilitiesInUserAgent()).thenReturn(true); List<AdsUtility> adsUtilities = Arrays.asList( AdsUtility.PRODUCT_PARTITION_TREE, AdsUtility.SELECTOR_BUILDER, AdsUtility.REPORT_DOWNLOADER); for (int i = 0; i < adsUtilities.size(); i++) { Collections.shuffle(adsUtilities); for (AdsUtility adsUtility : adsUtilities) { adsUtilityRegistry.addUtility(adsUtility); } String expectedUserAgent = "ProductPartitionTree, ReportDownloader, SelectorBuilder"; String actualUserAgent = userAgentProvider.getUserAgent(); assertEquals( "User agent should include registered utilities in alphabetical order if include " + "utilities is true", expectedUserAgent, actualUserAgent); assertTrue("User agent provider should clear utilities", adsUtilityRegistry.popRegisteredUtilities().isEmpty()); } }
@Override public String getUserAgent() { Set<AdsUtility> adsUtilities = adsUtilityRegistry.popRegisteredUtilities(); if (!adsLibConfiguration.isIncludeAdsUtilitiesInUserAgent() || adsUtilities.isEmpty()) { return null; } return Joiner.on(", ").skipNulls().join( Sets.newTreeSet(Collections2.transform(adsUtilities, ADS_UTILITY_FUNCTION))); }
AdsUtilitiesUserAgentProvider implements UserAgentProvider { @Override public String getUserAgent() { Set<AdsUtility> adsUtilities = adsUtilityRegistry.popRegisteredUtilities(); if (!adsLibConfiguration.isIncludeAdsUtilitiesInUserAgent() || adsUtilities.isEmpty()) { return null; } return Joiner.on(", ").skipNulls().join( Sets.newTreeSet(Collections2.transform(adsUtilities, ADS_UTILITY_FUNCTION))); } }
AdsUtilitiesUserAgentProvider implements UserAgentProvider { @Override public String getUserAgent() { Set<AdsUtility> adsUtilities = adsUtilityRegistry.popRegisteredUtilities(); if (!adsLibConfiguration.isIncludeAdsUtilitiesInUserAgent() || adsUtilities.isEmpty()) { return null; } return Joiner.on(", ").skipNulls().join( Sets.newTreeSet(Collections2.transform(adsUtilities, ADS_UTILITY_FUNCTION))); } @Inject  AdsUtilitiesUserAgentProvider(
      AdsUtilityRegistry adsUtilityRegistry, AdsLibConfiguration adsLibConfiguration); }
AdsUtilitiesUserAgentProvider implements UserAgentProvider { @Override public String getUserAgent() { Set<AdsUtility> adsUtilities = adsUtilityRegistry.popRegisteredUtilities(); if (!adsLibConfiguration.isIncludeAdsUtilitiesInUserAgent() || adsUtilities.isEmpty()) { return null; } return Joiner.on(", ").skipNulls().join( Sets.newTreeSet(Collections2.transform(adsUtilities, ADS_UTILITY_FUNCTION))); } @Inject  AdsUtilitiesUserAgentProvider(
      AdsUtilityRegistry adsUtilityRegistry, AdsLibConfiguration adsLibConfiguration); @Override String getUserAgent(); }
AdsUtilitiesUserAgentProvider implements UserAgentProvider { @Override public String getUserAgent() { Set<AdsUtility> adsUtilities = adsUtilityRegistry.popRegisteredUtilities(); if (!adsLibConfiguration.isIncludeAdsUtilitiesInUserAgent() || adsUtilities.isEmpty()) { return null; } return Joiner.on(", ").skipNulls().join( Sets.newTreeSet(Collections2.transform(adsUtilities, ADS_UTILITY_FUNCTION))); } @Inject  AdsUtilitiesUserAgentProvider(
      AdsUtilityRegistry adsUtilityRegistry, AdsLibConfiguration adsLibConfiguration); @Override String getUserAgent();  }