@Test void getMenu() { when(appSettings.getMenu()) .thenReturn( "{\n" + " \"type\": \"menu\",\n" + " \"id\": \"menu\",\n" + " \"label\": \"Menu\",\n" + " \"items\": [{\n" + " \"type\": \"plugin\",\n" + " \"id\": \"plugin0\",\n" + " \"label\": \"Plugin #0\",\n" + " \"params\": \"a=0&b=1\"\n" + " },\n" + " {\n" + " \"type\": \"menu\",\n" + " \"id\": \"submenu\",\n" + " \"label\": \"Submenu\",\n" + " \"items\": [{\n" + " \"type\": \"plugin\",\n" + " \"id\": \"plugin1\",\n" + " \"label\": \"Plugin #1\"\n" + " }]\n" + " }]\n" + "}"); MenuItem plugin0 = MenuItem.create("plugin0", "Plugin #0", "a=0&b=1"); MenuItem plugin1 = MenuItem.create("plugin1", "Plugin #1"); Menu submenu = Menu.create("submenu", "Submenu", Collections.singletonList(plugin1)); Menu menu = Menu.create("menu", "Menu", ImmutableList.of(plugin0, submenu)); when(userPermissionEvaluator.hasPermission(any(), eq(PluginPermission.VIEW_PLUGIN))) .thenReturn(true); assertEquals(of(menu), menuReaderService.getMenu()); }
@Override public Optional<Menu> getMenu() { return Optional.ofNullable(appSettings.getMenu()) .map(menuJson -> gson.fromJson(menuJson, Menu.class)) .flatMap(menu -> menu.filter(this::userHasViewPermission)) .map(Menu.class::cast); }
MenuReaderServiceImpl implements MenuReaderService { @Override public Optional<Menu> getMenu() { return Optional.ofNullable(appSettings.getMenu()) .map(menuJson -> gson.fromJson(menuJson, Menu.class)) .flatMap(menu -> menu.filter(this::userHasViewPermission)) .map(Menu.class::cast); } }
MenuReaderServiceImpl implements MenuReaderService { @Override public Optional<Menu> getMenu() { return Optional.ofNullable(appSettings.getMenu()) .map(menuJson -> gson.fromJson(menuJson, Menu.class)) .flatMap(menu -> menu.filter(this::userHasViewPermission)) .map(Menu.class::cast); } MenuReaderServiceImpl(
      AppSettings appSettings, Gson gson, UserPermissionEvaluator userPermissionEvaluator); }
MenuReaderServiceImpl implements MenuReaderService { @Override public Optional<Menu> getMenu() { return Optional.ofNullable(appSettings.getMenu()) .map(menuJson -> gson.fromJson(menuJson, Menu.class)) .flatMap(menu -> menu.filter(this::userHasViewPermission)) .map(Menu.class::cast); } MenuReaderServiceImpl(
      AppSettings appSettings, Gson gson, UserPermissionEvaluator userPermissionEvaluator); @Override Optional<Menu> getMenu(); @Override @Nullable String findMenuItemPath(String menuItemId); }
MenuReaderServiceImpl implements MenuReaderService { @Override public Optional<Menu> getMenu() { return Optional.ofNullable(appSettings.getMenu()) .map(menuJson -> gson.fromJson(menuJson, Menu.class)) .flatMap(menu -> menu.filter(this::userHasViewPermission)) .map(Menu.class::cast); } MenuReaderServiceImpl(
      AppSettings appSettings, Gson gson, UserPermissionEvaluator userPermissionEvaluator); @Override Optional<Menu> getMenu(); @Override @Nullable String findMenuItemPath(String menuItemId);  }