MessageHashCodeFunctionSupplier implements Supplier<Function<JsonNode, Integer>>, AutoCloseable { @Override public Function<JsonNode, Integer> get() { return Optional .ofNullable(partitionPathSupplier.get()) .map(path -> new PartitionNodeFunction(path).andThen(new JsonNodeHashCodeFunction(random))) .orElse(path -> random.nextInt()); } MessageHashCodeFunctionSupplier(Supplier<Path> partitionPathSupplier); @Override Function<JsonNode, Integer> get(); @Override void close();  }
@Test public void randomOnNullPath() { @SuppressWarnings("resource") Function<JsonNode, Integer> fn = new MessageHashCodeFunctionSupplier(() -> null, random).get(); assertThat(fn.apply(message), is(RANDOM_VALUE)); }
@Test public void jsonNodeHashcode() throws Exception { @SuppressWarnings("resource") Function<JsonNode, Integer> fn = new MessageHashCodeFunctionSupplier(() -> KeyPathParser.parse("$.a"), random) .get(); assertThat(fn.apply(message), is(message.get("a").hashCode())); }