AggregationArguments { public void throwUnlessEmpty(final String name) { if (args.isEmpty() && kw.isEmpty()) { return; } final List<String> parts = new ArrayList<>(); final Joiner on = Joiner.on(" and "); if (!args.isEmpty()) { parts.add( args.size() == 1 ? "argument " + args.iterator().next() : "arguments " + args); } if (!kw.isEmpty()) { parts.add((kw.size() == 1 ? "keyword " + kw.keySet().iterator().next() : "keywords " + kw.keySet())); } throw new IllegalStateException(name + ": has trailing " + on.join(parts)); } AggregationArguments(
        final List<? extends Expression> args, final Map<String, ? extends Expression> kw
    ); List<T> all(final Class<T> expected); Optional<T> positionalOrKeyword(
        final String key, Class<T> expected
    ); Optional<T> positional(Class<T> expected); Optional<T> keyword(final String key, Class<T> expected); void throwUnlessEmpty(final String name);  }
@Test public void throwUnlessEmptySingular() { expected.expect(IllegalStateException.class); expected.expectMessage("foo: has trailing argument a and keyword b"); final AggregationArguments arguments = new AggregationArguments(ImmutableList.of(a), ImmutableMap.of("b", b)); arguments.throwUnlessEmpty("foo"); }
@Test public void throwUnlessEmptyPlural() { expected.expect(IllegalStateException.class); expected.expectMessage("foo: has trailing arguments [a, b] and keywords [a, b]"); final AggregationArguments arguments = new AggregationArguments(ImmutableList.of(a, b), ImmutableMap.of("a", a, "b", b)); arguments.throwUnlessEmpty("foo"); }
@Test public void throwUnlessEmptyArguments() { expected.expect(IllegalStateException.class); expected.expectMessage("foo: has trailing arguments [a, b]"); final AggregationArguments arguments = new AggregationArguments(ImmutableList.of(a, b), ImmutableMap.of()); arguments.throwUnlessEmpty("foo"); }
@Test public void throwUnlessEmptyKeywords() { expected.expect(IllegalStateException.class); expected.expectMessage("foo: has trailing keywords [a, b]"); final AggregationArguments arguments = new AggregationArguments(ImmutableList.of(), ImmutableMap.of("a", a, "b", b)); arguments.throwUnlessEmpty("foo"); }
@Test public void throwUnlessEmpty() { final AggregationArguments arguments = new AggregationArguments(ImmutableList.of(), ImmutableMap.of()); arguments.throwUnlessEmpty("foo"); }