@Test public void testGetImageNameStrategy() throws Exception { final MediaFileNameStrategy defStrategy = context.mock(MediaFileNameStrategy.class, "defStrategy"); final MediaFileNameStrategy oneStrategy = context.mock(MediaFileNameStrategy.class, "oneStrategy"); final MediaFileNameStrategy twoStrategy = context.mock(MediaFileNameStrategy.class, "twoStrategy"); context.checking(new Expectations() {{ oneOf(defStrategy).getUrlPath(); will(returnValue("/def/")); oneOf(oneStrategy).getUrlPath(); will(returnValue("/one/")); oneOf(twoStrategy).getUrlPath(); will(returnValue("/two/")); }}); final MediaFileNameStrategyResolverImpl resolver = new MediaFileNameStrategyResolverImpl(defStrategy, Arrays.asList( oneStrategy, twoStrategy, defStrategy )); assertSame(oneStrategy, resolver.getMediaFileNameStrategy("/one/somefile.jpeg")); assertSame(oneStrategy, resolver.getMediaFileNameStrategy("/yes-cart/one/somefile.jpeg")); assertSame(twoStrategy, resolver.getMediaFileNameStrategy("/two/somefile.jpeg")); assertSame(twoStrategy, resolver.getMediaFileNameStrategy("/yes-cart/two/somefile.jpeg")); assertSame(defStrategy, resolver.getMediaFileNameStrategy("/def/somefile.jpeg")); assertSame(defStrategy, resolver.getMediaFileNameStrategy("/yes-cart/def/somefile.jpeg")); assertSame(defStrategy, resolver.getMediaFileNameStrategy("/yes-cart/somefile.jpeg")); }
@Override public MediaFileNameStrategy getMediaFileNameStrategy(final String mediaUrl) { for (final String url : urls) { if (mediaUrl.contains(url)) { return urlToStrategyMap.get(url); } } return defaultStrategy; }
MediaFileNameStrategyResolverImpl implements MediaFileNameStrategyResolver { @Override public MediaFileNameStrategy getMediaFileNameStrategy(final String mediaUrl) { for (final String url : urls) { if (mediaUrl.contains(url)) { return urlToStrategyMap.get(url); } } return defaultStrategy; } }
MediaFileNameStrategyResolverImpl implements MediaFileNameStrategyResolver { @Override public MediaFileNameStrategy getMediaFileNameStrategy(final String mediaUrl) { for (final String url : urls) { if (mediaUrl.contains(url)) { return urlToStrategyMap.get(url); } } return defaultStrategy; } MediaFileNameStrategyResolverImpl(final MediaFileNameStrategy defaultStrategy,
                                             final List<MediaFileNameStrategy> urlToStrategies); }
MediaFileNameStrategyResolverImpl implements MediaFileNameStrategyResolver { @Override public MediaFileNameStrategy getMediaFileNameStrategy(final String mediaUrl) { for (final String url : urls) { if (mediaUrl.contains(url)) { return urlToStrategyMap.get(url); } } return defaultStrategy; } MediaFileNameStrategyResolverImpl(final MediaFileNameStrategy defaultStrategy,
                                             final List<MediaFileNameStrategy> urlToStrategies); @Override MediaFileNameStrategy getMediaFileNameStrategy(final String mediaUrl); }
MediaFileNameStrategyResolverImpl implements MediaFileNameStrategyResolver { @Override public MediaFileNameStrategy getMediaFileNameStrategy(final String mediaUrl) { for (final String url : urls) { if (mediaUrl.contains(url)) { return urlToStrategyMap.get(url); } } return defaultStrategy; } MediaFileNameStrategyResolverImpl(final MediaFileNameStrategy defaultStrategy,
                                             final List<MediaFileNameStrategy> urlToStrategies); @Override MediaFileNameStrategy getMediaFileNameStrategy(final String mediaUrl);  }