### Question:
ValueFilterFetchOnce extends StringFilter { @Override public String filter(String input) { Preconditions.checkNotNull(input, "input to fetch-once filter must be non-null"); while (true) { String cacheRead = cache; if (cacheRead == null) { if (CACHE_UPDATER.compareAndSet(this, null, input)) { makeHttpRequest(input); } } else if (!cacheRead.equals(input)) { throw new IllegalStateException("fetch attempted on multiple urls " + cacheRead + " and " + input); } else { try { return result.get(timeout, TimeUnit.MILLISECONDS); } catch (ExecutionException ex) { throw Throwables.propagate(ex.getCause()); } catch (Exception ex) { throw Throwables.propagate(ex); } } } } @JsonCreator  ValueFilterFetchOnce(@JsonProperty(value = "timeout", required = true)
                                @Time(TimeUnit.MILLISECONDS) int timeout); @Override String filter(String input);  }### Answer:
@Test public void fetchUrl() { ValueFilterFetchOnce fetch = new ValueFilterFetchOnce(5000); String result1 = fetch.filter("http: assertNotNull(result1); String result2 = fetch.filter("http: assertEquals(result1, result2); }
@Test(expected=IllegalStateException.class) public void fetchOnce() { ValueFilterFetchOnce fetch = new ValueFilterFetchOnce(5000); fetch.filter("http: fetch.filter("http: }
@Test(expected=NullPointerException.class) public void nullInput() { ValueFilterFetchOnce fetch = new ValueFilterFetchOnce(5000); fetch.filter((String) null); }
@Test public void fetchError() { boolean error = false; ValueFilterFetchOnce fetch = new ValueFilterFetchOnce(5000); try { fetch.filter("http: } catch (Exception ex) { error = true; assertTrue(ex.getCause() instanceof UnknownHostException); } assertTrue(error); }