@Test void findMenuItemPath() { String menuString = gson.toJson(menu); when(appSettings.getMenu()).thenReturn(menuString); when(userPermissionEvaluator.hasPermission( any(PluginIdentity.class), eq(PluginPermission.VIEW_PLUGIN))) .thenReturn(true); assertEquals("/menu/root/p1_0", menuReaderService.findMenuItemPath("p1_0")); assertEquals("/menu/root/p1_1", menuReaderService.findMenuItemPath("p1_1")); assertEquals("/menu/p1_1/p2_0", menuReaderService.findMenuItemPath("p2_0")); assertEquals("/menu/p1_1/p2_1", menuReaderService.findMenuItemPath("p2_1")); assertEquals("/menu/p2_0/p3_0", menuReaderService.findMenuItemPath("p3_0")); assertEquals("/menu/p2_0/p3_1", menuReaderService.findMenuItemPath("p3_1")); assertNull(menuReaderService.findMenuItemPath("non_existing")); }
@Override @Nullable public String findMenuItemPath(String menuItemId) { return getMenu() .flatMap(it -> it.getPath(menuItemId)) .map(Collection::stream) .map(stream -> stream.collect(joining("/", "/menu/", ""))) .orElse(null); }
MenuReaderServiceImpl implements MenuReaderService { @Override @Nullable public String findMenuItemPath(String menuItemId) { return getMenu() .flatMap(it -> it.getPath(menuItemId)) .map(Collection::stream) .map(stream -> stream.collect(joining("/", "/menu/", ""))) .orElse(null); } }
MenuReaderServiceImpl implements MenuReaderService { @Override @Nullable public String findMenuItemPath(String menuItemId) { return getMenu() .flatMap(it -> it.getPath(menuItemId)) .map(Collection::stream) .map(stream -> stream.collect(joining("/", "/menu/", ""))) .orElse(null); } MenuReaderServiceImpl(
      AppSettings appSettings, Gson gson, UserPermissionEvaluator userPermissionEvaluator); }
MenuReaderServiceImpl implements MenuReaderService { @Override @Nullable public String findMenuItemPath(String menuItemId) { return getMenu() .flatMap(it -> it.getPath(menuItemId)) .map(Collection::stream) .map(stream -> stream.collect(joining("/", "/menu/", ""))) .orElse(null); } MenuReaderServiceImpl(
      AppSettings appSettings, Gson gson, UserPermissionEvaluator userPermissionEvaluator); @Override Optional<Menu> getMenu(); @Override @Nullable String findMenuItemPath(String menuItemId); }
MenuReaderServiceImpl implements MenuReaderService { @Override @Nullable public String findMenuItemPath(String menuItemId) { return getMenu() .flatMap(it -> it.getPath(menuItemId)) .map(Collection::stream) .map(stream -> stream.collect(joining("/", "/menu/", ""))) .orElse(null); } MenuReaderServiceImpl(
      AppSettings appSettings, Gson gson, UserPermissionEvaluator userPermissionEvaluator); @Override Optional<Menu> getMenu(); @Override @Nullable String findMenuItemPath(String menuItemId);  }