@Test public void testGet() throws Exception { final ThemeService themeServiceDefault = mockery.mock(ThemeService.class, "themeServiceDefault"); final ThemeService themeServiceTheme1 = mockery.mock(ThemeService.class, "themeServiceTheme1"); final ThemeService themeServiceTheme2 = mockery.mock(ThemeService.class, "themeServiceTheme2"); final ThemePageProvider page = new ThemePageProvider(new HashMap() {{ put("default", IRequestablePage.class); put("theme1", IRequestablePageTheme1.class); put("theme2", IRequestablePageTheme2.class); }}); final Shop shopDefault = mockery.mock(Shop.class, "default"); final Shop shopTheme1 = mockery.mock(Shop.class, "theme1,default"); final Shop shopTheme2 = mockery.mock(Shop.class, "theme2,theme1,default"); mockery.checking(new Expectations() {{ allowing(shopDefault).getShopId(); will(returnValue(1L)); allowing(themeServiceDefault).getThemeChainByShopId(1L, null); will(returnValue(Arrays.asList("default"))); allowing(shopTheme1).getShopId(); will(returnValue(2L)); allowing(themeServiceTheme1).getThemeChainByShopId(2L, null); will(returnValue(Arrays.asList("theme1","default"))); allowing(shopTheme2).getShopId(); will(returnValue(3L)); allowing(themeServiceTheme2).getThemeChainByShopId(3L, null); will(returnValue(Arrays.asList("theme2","theme1","default"))); }}); new ApplicationDirector(); ApplicationDirector.setCurrentThemeChain(Arrays.asList("default")); ApplicationDirector.setCurrentShop(shopDefault); assertSame(IRequestablePage.class, page.get()); ApplicationDirector.clear(); ApplicationDirector.setCurrentThemeChain(Arrays.asList("theme1","default")); ApplicationDirector.setCurrentShop(shopTheme1); assertSame(IRequestablePageTheme1.class, page.get()); ApplicationDirector.clear(); ApplicationDirector.setCurrentThemeChain(Arrays.asList("theme2","theme1","default")); ApplicationDirector.setCurrentShop(shopTheme2); assertSame(IRequestablePageTheme2.class, page.get()); ApplicationDirector.clear(); }
@Override public Class<IRequestablePage> get() { List<String> themeChain = ApplicationDirector.getCurrentThemeChain(); for (final String theme : themeChain) { if (this.pages.containsKey(theme)) { return this.pages.get(theme).get(); } } return this.pages.get("default").get(); }
ThemePageProvider extends ClassReference<IRequestablePage> { @Override public Class<IRequestablePage> get() { List<String> themeChain = ApplicationDirector.getCurrentThemeChain(); for (final String theme : themeChain) { if (this.pages.containsKey(theme)) { return this.pages.get(theme).get(); } } return this.pages.get("default").get(); } }
ThemePageProvider extends ClassReference<IRequestablePage> { @Override public Class<IRequestablePage> get() { List<String> themeChain = ApplicationDirector.getCurrentThemeChain(); for (final String theme : themeChain) { if (this.pages.containsKey(theme)) { return this.pages.get(theme).get(); } } return this.pages.get("default").get(); } ThemePageProvider(final Map<String, Class<IRequestablePage>> pages); }
ThemePageProvider extends ClassReference<IRequestablePage> { @Override public Class<IRequestablePage> get() { List<String> themeChain = ApplicationDirector.getCurrentThemeChain(); for (final String theme : themeChain) { if (this.pages.containsKey(theme)) { return this.pages.get(theme).get(); } } return this.pages.get("default").get(); } ThemePageProvider(final Map<String, Class<IRequestablePage>> pages); @Override Class<IRequestablePage> get(); }
ThemePageProvider extends ClassReference<IRequestablePage> { @Override public Class<IRequestablePage> get() { List<String> themeChain = ApplicationDirector.getCurrentThemeChain(); for (final String theme : themeChain) { if (this.pages.containsKey(theme)) { return this.pages.get(theme).get(); } } return this.pages.get("default").get(); } ThemePageProvider(final Map<String, Class<IRequestablePage>> pages); @Override Class<IRequestablePage> get();  }