EventController { List<Cookie> cookies(Request request) { if (collectCookies == null) return null; List<Cookie> cookies = new ArrayList<>(collectCookies.size()); for (String name : collectCookies) { request.cookie(new CookieSpec(name)) .ifPresent(value -> cookies.add(new Cookie(name, value))); } return cookies; } EventController(List<String> allowedOrigins, List<String> collectCookies); Response options(Request request); Response post(Request request);  }
@Test void cookies() { var controller = new EventController(List.of(), List.of("visitor_id")); when(request.cookie(new CookieSpec("visitor_id"))).thenReturn(Optional.empty()); List<Cookie> cookies = controller.cookies(request); assertThat(cookies).hasSize(0); when(request.cookie(new CookieSpec("visitor_id"))).thenReturn(Optional.of("value")); cookies = controller.cookies(request); assertThat(cookies).hasSize(1); Cookie cookie = cookies.get(0); assertThat(cookie.name).isEqualTo("visitor_id"); assertThat(cookie.value).isEqualTo("value"); }