@Test public void throwUnlessEmpty() { final AggregationArguments arguments = new AggregationArguments(ImmutableList.of(), ImmutableMap.of()); arguments.throwUnlessEmpty("foo"); }
@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 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 positionalOrKeyword() { final AggregationArguments arguments = new AggregationArguments(ImmutableList.of(a), ImmutableMap.of("key", b)); assertEquals(Optional.of(a), arguments.positionalOrKeyword("key", Expression.class)); assertEquals(Optional.of(b), arguments.positionalOrKeyword("key", Expression.class)); assertEquals(Optional.empty(), arguments.positionalOrKeyword("key", Expression.class)); verify(a).cast(Expression.class); verify(b).cast(Expression.class); }
@Test public void all() { final AggregationArguments arguments = new AggregationArguments(ImmutableList.of(a, b), ImmutableMap.of()); final List<Expression> result = arguments.all(Expression.class); assertEquals(ImmutableList.of(a, b), result); verify(a).cast(Expression.class); verify(b).cast(Expression.class); }