23
23
import org .elasticsearch .search .aggregations .bucket .histogram .HistogramAggregationBuilder ;
24
24
import org .elasticsearch .search .aggregations .bucket .histogram .Histogram .Order ;
25
25
26
+ import static org .hamcrest .Matchers .equalTo ;
27
+ import static org .hamcrest .Matchers .startsWith ;
28
+
26
29
public class HistogramTests extends BaseAggregationTestCase <HistogramAggregationBuilder > {
27
30
28
31
@ Override
@@ -31,7 +34,9 @@ protected HistogramAggregationBuilder createTestAggregatorBuilder() {
31
34
factory .field (INT_FIELD_NAME );
32
35
factory .interval (randomDouble () * 1000 );
33
36
if (randomBoolean ()) {
34
- factory .extendedBounds (randomDouble (), randomDouble ());
37
+ double minBound = randomDouble ();
38
+ double maxBound = randomDoubleBetween (minBound , 1 , true );
39
+ factory .extendedBounds (minBound , maxBound );
35
40
}
36
41
if (randomBoolean ()) {
37
42
factory .format ("###.##" );
@@ -74,4 +79,27 @@ protected HistogramAggregationBuilder createTestAggregatorBuilder() {
74
79
return factory ;
75
80
}
76
81
82
+ public void testInvalidBounds () {
83
+ HistogramAggregationBuilder factory = new HistogramAggregationBuilder ("foo" );
84
+ factory .field (INT_FIELD_NAME );
85
+ factory .interval (randomDouble () * 1000 );
86
+
87
+ IllegalArgumentException ex = expectThrows (IllegalArgumentException .class , () -> { factory .extendedBounds (Double .NaN , 1.0 ); });
88
+ assertThat (ex .getMessage (), startsWith ("minBound must be finite, got: " ));
89
+ ex = expectThrows (IllegalArgumentException .class , () -> { factory .extendedBounds (Double .POSITIVE_INFINITY , 1.0 ); });
90
+ assertThat (ex .getMessage (), startsWith ("minBound must be finite, got: " ));
91
+ ex = expectThrows (IllegalArgumentException .class , () -> { factory .extendedBounds (Double .NEGATIVE_INFINITY , 1.0 ); });
92
+ assertThat (ex .getMessage (), startsWith ("minBound must be finite, got: " ));
93
+
94
+ ex = expectThrows (IllegalArgumentException .class , () -> { factory .extendedBounds (0.0 , Double .NaN ); });
95
+ assertThat (ex .getMessage (), startsWith ("maxBound must be finite, got: " ));
96
+ ex = expectThrows (IllegalArgumentException .class , () -> { factory .extendedBounds (0.0 , Double .POSITIVE_INFINITY ); });
97
+ assertThat (ex .getMessage (), startsWith ("maxBound must be finite, got: " ));
98
+ ex = expectThrows (IllegalArgumentException .class , () -> { factory .extendedBounds (0.0 , Double .NEGATIVE_INFINITY ); });
99
+ assertThat (ex .getMessage (), startsWith ("maxBound must be finite, got: " ));
100
+
101
+ ex = expectThrows (IllegalArgumentException .class , () -> { factory .extendedBounds (0.5 , 0.4 ); });
102
+ assertThat (ex .getMessage (), equalTo ("maxBound [0.4] must be greater than minBound [0.5]" ));
103
+ }
104
+
77
105
}
0 commit comments