Filter { public Uri.Builder appendParams(Uri.Builder builder) { getWhitelist().ifPresent(strings -> { for (String association : strings) { builder.appendQueryParameter("association[]", association); } if (strings.isEmpty()) { builder.appendQueryParameter("association[]", ""); } }); if (getAfter() != null) { builder.appendQueryParameter("start_time", getAfter().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)); } if (getBefore() != null) { builder.appendQueryParameter("end_time", getBefore().format(DateTimeFormatter.ISO_OFFSET_DATE_TIME)); } if (getTerm() != null) { builder.appendQueryParameter("search_string", getTerm()); } return builder; } Filter(); @NonNull Optional<Set<String>> getWhitelist(); OffsetDateTime getAfter(); OffsetDateTime getBefore(); String getTerm(); void addStoredWhitelist(Context context); Uri.Builder appendParams(Uri.Builder builder); @Override String toString(); static Comparator<Pair<Association, Boolean>> selectionComparator();  }
@Test public void urlGeneration() { OffsetDateTime now = OffsetDateTime.now(); Filter.Live filter = new Filter.Live(); filter.setWhitelist(new HashSet<>(Arrays.asList("test", "hallo"))); filter.setTerm("search"); filter.setAfter(now); filter.setBefore(now); Uri.Builder builder = Uri.parse("http: filter.filter.appendParams(builder); Uri uri = builder.build(); assertEquals("search", uri.getQueryParameter("search_string")); Set<String> expected = Stream.of("test", "hallo").collect(Collectors.toSet()); Set<String> actual = new HashSet<>(uri.getQueryParameters("association[]")); assertEquals(expected, actual); assertEquals(now.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME), uri.getQueryParameter("start_time")); assertEquals(now.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME), uri.getQueryParameter("end_time")); }