@Test(expected = BeanValidationException.class) public void testReadCookieAsJson_Validation() { storage.readCookieAsJson(null, null); }
public @Valid <T> Optional<T> readCookieAsJson(@NotNull CookieName cookieName, @NotNull Class<T> clazz) { try { Optional<Cookie> cookie = readCookie(cookieName); Optional<String> cookieValue = cookie.map(c -> StringUtils.trimToNull(c.getValue())); if (!cookieValue.isPresent()) { return Optional.empty(); } T obj = marshaller.unmarshal(clazz, cookieValue.get()); return Optional.of(obj); } catch (Exception e) { LOG.warn("Error reading cookie {}, Reason: {}", cookieName, e.getMessage()); LOG.debug(e.getMessage(), e); return Optional.empty(); } }
CookieStorage { public @Valid <T> Optional<T> readCookieAsJson(@NotNull CookieName cookieName, @NotNull Class<T> clazz) { try { Optional<Cookie> cookie = readCookie(cookieName); Optional<String> cookieValue = cookie.map(c -> StringUtils.trimToNull(c.getValue())); if (!cookieValue.isPresent()) { return Optional.empty(); } T obj = marshaller.unmarshal(clazz, cookieValue.get()); return Optional.of(obj); } catch (Exception e) { LOG.warn("Error reading cookie {}, Reason: {}", cookieName, e.getMessage()); LOG.debug(e.getMessage(), e); return Optional.empty(); } } }
CookieStorage { public @Valid <T> Optional<T> readCookieAsJson(@NotNull CookieName cookieName, @NotNull Class<T> clazz) { try { Optional<Cookie> cookie = readCookie(cookieName); Optional<String> cookieValue = cookie.map(c -> StringUtils.trimToNull(c.getValue())); if (!cookieValue.isPresent()) { return Optional.empty(); } T obj = marshaller.unmarshal(clazz, cookieValue.get()); return Optional.of(obj); } catch (Exception e) { LOG.warn("Error reading cookie {}, Reason: {}", cookieName, e.getMessage()); LOG.debug(e.getMessage(), e); return Optional.empty(); } }  }
CookieStorage { public @Valid <T> Optional<T> readCookieAsJson(@NotNull CookieName cookieName, @NotNull Class<T> clazz) { try { Optional<Cookie> cookie = readCookie(cookieName); Optional<String> cookieValue = cookie.map(c -> StringUtils.trimToNull(c.getValue())); if (!cookieValue.isPresent()) { return Optional.empty(); } T obj = marshaller.unmarshal(clazz, cookieValue.get()); return Optional.of(obj); } catch (Exception e) { LOG.warn("Error reading cookie {}, Reason: {}", cookieName, e.getMessage()); LOG.debug(e.getMessage(), e); return Optional.empty(); } }  void storeCookieAsJson(@NotNull CookieName cookieName, @NotNull Object obj); @Valid Optional<T> readCookieAsJson(@NotNull CookieName cookieName, @NotNull Class<T> clazz); }
CookieStorage { public @Valid <T> Optional<T> readCookieAsJson(@NotNull CookieName cookieName, @NotNull Class<T> clazz) { try { Optional<Cookie> cookie = readCookie(cookieName); Optional<String> cookieValue = cookie.map(c -> StringUtils.trimToNull(c.getValue())); if (!cookieValue.isPresent()) { return Optional.empty(); } T obj = marshaller.unmarshal(clazz, cookieValue.get()); return Optional.of(obj); } catch (Exception e) { LOG.warn("Error reading cookie {}, Reason: {}", cookieName, e.getMessage()); LOG.debug(e.getMessage(), e); return Optional.empty(); } }  void storeCookieAsJson(@NotNull CookieName cookieName, @NotNull Object obj); @Valid Optional<T> readCookieAsJson(@NotNull CookieName cookieName, @NotNull Class<T> clazz);  }