AdminPageImpl implements AdminPage { @Override public void addTool(final String screen, final String title, final Set<String> iconCss, final String category, final Command command, final ParameterizedCommand<ParameterizedCommand<Integer>> counterCommand) { if (screen == null || screen.isEmpty()) { throw new RuntimeException("The screen identifier must be not empty."); } if (screenTitleByIdentifier.get(screen) == null) { throw new RuntimeException("The screen must be added before it is used."); } if (category == null || category.isEmpty()) { throw new RuntimeException("The category identifier must be not empty."); } Map<String, List<AdminTool>> toolsByCategory = toolsByCategoryByScreen.get(screen); List<AdminTool> tools = toolsByCategory.get(category); if (tools == null) { tools = new ArrayList<>(); toolsByCategory.put(category, tools); } AdminTool tool = new AdminTool(title, iconCss, category, command, counterCommand); tools.add(tool); } AdminPageImpl(); @Inject  AdminPageImpl(final PlaceManager placeManager,
                         final Event<PreferencesCentralInitializationEvent> preferencesCentralInitializationEvent,
                         @Customizable final PreferenceScopeResolutionStrategy resolutionStrategy,
                         final UberfireBreadcrumbs breadcrumbs,
                         final TranslationService translationService); @Override void addScreen(final String identifier,
                          final String title); @Override void addTool(final String screen,
                        final String title,
                        final Set<String> iconCss,
                        final String category,
                        final Command command,
                        final ParameterizedCommand<ParameterizedCommand<Integer>> counterCommand); @Override void addTool(final String screen,
                        final String title,
                        final Set<String> iconCss,
                        final String category,
                        final Command command); @Override void addPreference(final String screen,
                              final String identifier,
                              final String title,
                              final Set<String> iconCss,
                              final String category,
                              final AdminPageOptions... options); @Override void addPreference(final String screen,
                              final String identifier,
                              final String title,
                              final Set<String> iconCss,
                              final String category,
                              final Supplier<PreferenceScopeResolutionStrategyInfo> customScopeResolutionStrategySupplier,
                              final AdminPageOptions... options); @Override void addPreference(final String screen,
                              final String identifier,
                              final String title,
                              final Set<String> iconCss,
                              final String category,
                              final PreferenceScope preferenceScope,
                              final AdminPageOptions... options); @Override void addPreference(final String screen,
                              final String identifier,
                              final String title,
                              final Set<String> iconCss,
                              final String category,
                              final Supplier<PreferenceScopeResolutionStrategyInfo> customScopeResolutionStrategySupplier,
                              final PreferenceScope preferenceScope,
                              final AdminPageOptions... options); @Override Map<String, List<AdminTool>> getToolsByCategory(final String screen); @Override String getScreenTitle(final String screen); @Override String getDefaultScreen(); @Override void setDefaultScreen(final String defaultScreen);  }
@Test public void addToolTest() { adminPage.addScreen("screen1", "Screen 1"); adminPage.addScreen("screen2", "Screen 2"); adminPage.addTool("screen1", "title1", singleton("iconCss1"), "category1", () -> { }); adminPage.addTool("screen1", "title2", singleton("iconCss2"), "category1", () -> { }); adminPage.addTool("screen1", "title3", singleton("iconCss3"), "category2", () -> { }); adminPage.addTool("screen2", "title4", singleton("iconCss4"), "category3", () -> { }); final Map<String, List<AdminTool>> toolsByCategory1 = adminPage.getToolsByCategory("screen1"); assertNotNull(toolsByCategory1); assertEquals(2, toolsByCategory1.size()); final List<AdminTool> category1Tools = toolsByCategory1.get("category1"); assertEquals(2, category1Tools.size()); assertEquals("title1", category1Tools.get(0).getTitle()); assertEquals(1, category1Tools.get(0).getIconCss().size()); assertThat(category1Tools.get(0).getIconCss(), hasItem("iconCss1")); assertEquals("title2", category1Tools.get(1).getTitle()); assertEquals(1, category1Tools.get(1).getIconCss().size()); assertThat(category1Tools.get(1).getIconCss(), hasItem("iconCss2")); final List<AdminTool> category2Tools = toolsByCategory1.get("category2"); assertEquals(1, category2Tools.size()); assertEquals("title3", category2Tools.get(0).getTitle()); assertThat(category2Tools.get(0).getIconCss(), hasItem("iconCss3")); final Map<String, List<AdminTool>> toolsByCategory2 = adminPage.getToolsByCategory("screen2"); assertNotNull(toolsByCategory2); assertEquals(1, toolsByCategory2.size()); final List<AdminTool> category3Tools = toolsByCategory2.get("category3"); assertEquals(1, category3Tools.size()); assertEquals("title4", category3Tools.get(0).getTitle()); assertThat(category3Tools.get(0).getIconCss(), hasItem("iconCss4")); }
@Test(expected = RuntimeException.class) public void addToolWithNullScreenTest() { adminPage.addTool(null, "title", singleton("iconCss"), null, () -> { }); }
@Test(expected = RuntimeException.class) public void addToolWithNullCategoryTest() { adminPage.addTool("screen", "title", singleton("iconCss"), null, () -> { }); }