@Test public void extractNoAppsService() { Optional<Map<String, List<CoffeeNetApp>>> extractedApps = sut.extractApps(); assertThat(extractedApps).isSameAs(Optional.empty()); }
Optional<Map<String, List<CoffeeNetApp>>> extractApps() { Optional<CoffeeNetAppService> coffeeNetAppService = getCoffeeNetAppService(); if (!coffeeNetAppService.isPresent()) { return Optional.empty(); } Map<String, List<CoffeeNetApp>> preparedCoffeeNetApps = new HashMap<>(); Optional<CoffeeNetCurrentUserService> userService = getCoffeeNetCurrentUserService(); Builder queryBuilder = AppQuery.builder(); userService.ifPresent(coffeeNetCurrentUserService -> coffeeNetCurrentUserService.get() .ifPresent(userDetails -> queryBuilder.withRoles(userDetails.getAuthoritiesAsString()))); Map<String, List<CoffeeNetApp>> filteredCoffeeNetApps = coffeeNetAppService.get() .getApps(queryBuilder.build()); String profileServiceName = coffeeNetNavigationProperties.getProfileServiceName(); List<CoffeeNetApp> profileApps = filteredCoffeeNetApps.get(profileServiceName); if (profileApps != null) { CoffeeNetApp profileApp = profileApps.get(0); filteredCoffeeNetApps.remove(profileServiceName); preparedCoffeeNetApps.put("profile", singletonList(profileApp)); } List<CoffeeNetApp> firstCoffeeNetApps = filteredCoffeeNetApps.entrySet() .stream() .map(entry -> entry.getValue().get(0)) .sorted(Comparator.comparing(CoffeeNetApp::getName, CASE_INSENSITIVE_ORDER)) .collect(toList()); preparedCoffeeNetApps.put("apps", firstCoffeeNetApps); return Optional.of(preparedCoffeeNetApps); }
CoffeeNetNavigationDataExtractor { Optional<Map<String, List<CoffeeNetApp>>> extractApps() { Optional<CoffeeNetAppService> coffeeNetAppService = getCoffeeNetAppService(); if (!coffeeNetAppService.isPresent()) { return Optional.empty(); } Map<String, List<CoffeeNetApp>> preparedCoffeeNetApps = new HashMap<>(); Optional<CoffeeNetCurrentUserService> userService = getCoffeeNetCurrentUserService(); Builder queryBuilder = AppQuery.builder(); userService.ifPresent(coffeeNetCurrentUserService -> coffeeNetCurrentUserService.get() .ifPresent(userDetails -> queryBuilder.withRoles(userDetails.getAuthoritiesAsString()))); Map<String, List<CoffeeNetApp>> filteredCoffeeNetApps = coffeeNetAppService.get() .getApps(queryBuilder.build()); String profileServiceName = coffeeNetNavigationProperties.getProfileServiceName(); List<CoffeeNetApp> profileApps = filteredCoffeeNetApps.get(profileServiceName); if (profileApps != null) { CoffeeNetApp profileApp = profileApps.get(0); filteredCoffeeNetApps.remove(profileServiceName); preparedCoffeeNetApps.put("profile", singletonList(profileApp)); } List<CoffeeNetApp> firstCoffeeNetApps = filteredCoffeeNetApps.entrySet() .stream() .map(entry -> entry.getValue().get(0)) .sorted(Comparator.comparing(CoffeeNetApp::getName, CASE_INSENSITIVE_ORDER)) .collect(toList()); preparedCoffeeNetApps.put("apps", firstCoffeeNetApps); return Optional.of(preparedCoffeeNetApps); } }
CoffeeNetNavigationDataExtractor { Optional<Map<String, List<CoffeeNetApp>>> extractApps() { Optional<CoffeeNetAppService> coffeeNetAppService = getCoffeeNetAppService(); if (!coffeeNetAppService.isPresent()) { return Optional.empty(); } Map<String, List<CoffeeNetApp>> preparedCoffeeNetApps = new HashMap<>(); Optional<CoffeeNetCurrentUserService> userService = getCoffeeNetCurrentUserService(); Builder queryBuilder = AppQuery.builder(); userService.ifPresent(coffeeNetCurrentUserService -> coffeeNetCurrentUserService.get() .ifPresent(userDetails -> queryBuilder.withRoles(userDetails.getAuthoritiesAsString()))); Map<String, List<CoffeeNetApp>> filteredCoffeeNetApps = coffeeNetAppService.get() .getApps(queryBuilder.build()); String profileServiceName = coffeeNetNavigationProperties.getProfileServiceName(); List<CoffeeNetApp> profileApps = filteredCoffeeNetApps.get(profileServiceName); if (profileApps != null) { CoffeeNetApp profileApp = profileApps.get(0); filteredCoffeeNetApps.remove(profileServiceName); preparedCoffeeNetApps.put("profile", singletonList(profileApp)); } List<CoffeeNetApp> firstCoffeeNetApps = filteredCoffeeNetApps.entrySet() .stream() .map(entry -> entry.getValue().get(0)) .sorted(Comparator.comparing(CoffeeNetApp::getName, CASE_INSENSITIVE_ORDER)) .collect(toList()); preparedCoffeeNetApps.put("apps", firstCoffeeNetApps); return Optional.of(preparedCoffeeNetApps); } CoffeeNetNavigationDataExtractor(CoffeeNetNavigationProperties coffeeNetNavigationProperties); }
CoffeeNetNavigationDataExtractor { Optional<Map<String, List<CoffeeNetApp>>> extractApps() { Optional<CoffeeNetAppService> coffeeNetAppService = getCoffeeNetAppService(); if (!coffeeNetAppService.isPresent()) { return Optional.empty(); } Map<String, List<CoffeeNetApp>> preparedCoffeeNetApps = new HashMap<>(); Optional<CoffeeNetCurrentUserService> userService = getCoffeeNetCurrentUserService(); Builder queryBuilder = AppQuery.builder(); userService.ifPresent(coffeeNetCurrentUserService -> coffeeNetCurrentUserService.get() .ifPresent(userDetails -> queryBuilder.withRoles(userDetails.getAuthoritiesAsString()))); Map<String, List<CoffeeNetApp>> filteredCoffeeNetApps = coffeeNetAppService.get() .getApps(queryBuilder.build()); String profileServiceName = coffeeNetNavigationProperties.getProfileServiceName(); List<CoffeeNetApp> profileApps = filteredCoffeeNetApps.get(profileServiceName); if (profileApps != null) { CoffeeNetApp profileApp = profileApps.get(0); filteredCoffeeNetApps.remove(profileServiceName); preparedCoffeeNetApps.put("profile", singletonList(profileApp)); } List<CoffeeNetApp> firstCoffeeNetApps = filteredCoffeeNetApps.entrySet() .stream() .map(entry -> entry.getValue().get(0)) .sorted(Comparator.comparing(CoffeeNetApp::getName, CASE_INSENSITIVE_ORDER)) .collect(toList()); preparedCoffeeNetApps.put("apps", firstCoffeeNetApps); return Optional.of(preparedCoffeeNetApps); } CoffeeNetNavigationDataExtractor(CoffeeNetNavigationProperties coffeeNetNavigationProperties);  }
CoffeeNetNavigationDataExtractor { Optional<Map<String, List<CoffeeNetApp>>> extractApps() { Optional<CoffeeNetAppService> coffeeNetAppService = getCoffeeNetAppService(); if (!coffeeNetAppService.isPresent()) { return Optional.empty(); } Map<String, List<CoffeeNetApp>> preparedCoffeeNetApps = new HashMap<>(); Optional<CoffeeNetCurrentUserService> userService = getCoffeeNetCurrentUserService(); Builder queryBuilder = AppQuery.builder(); userService.ifPresent(coffeeNetCurrentUserService -> coffeeNetCurrentUserService.get() .ifPresent(userDetails -> queryBuilder.withRoles(userDetails.getAuthoritiesAsString()))); Map<String, List<CoffeeNetApp>> filteredCoffeeNetApps = coffeeNetAppService.get() .getApps(queryBuilder.build()); String profileServiceName = coffeeNetNavigationProperties.getProfileServiceName(); List<CoffeeNetApp> profileApps = filteredCoffeeNetApps.get(profileServiceName); if (profileApps != null) { CoffeeNetApp profileApp = profileApps.get(0); filteredCoffeeNetApps.remove(profileServiceName); preparedCoffeeNetApps.put("profile", singletonList(profileApp)); } List<CoffeeNetApp> firstCoffeeNetApps = filteredCoffeeNetApps.entrySet() .stream() .map(entry -> entry.getValue().get(0)) .sorted(Comparator.comparing(CoffeeNetApp::getName, CASE_INSENSITIVE_ORDER)) .collect(toList()); preparedCoffeeNetApps.put("apps", firstCoffeeNetApps); return Optional.of(preparedCoffeeNetApps); } CoffeeNetNavigationDataExtractor(CoffeeNetNavigationProperties coffeeNetNavigationProperties);   }