@@ -33,7 +33,7 @@ public class ExponentialHistogramXContentTests extends ExponentialHistogramTestC
3333
3434 public void testEmptyHistogram () {
3535 ExponentialHistogram emptyHistogram = ExponentialHistogram .empty ();
36- assertSerializedHistogram ( ExponentialHistogram . empty ( ), "{\" scale\" :" + emptyHistogram .scale () + "}" );
36+ assertThat ( toJson ( emptyHistogram ), equalTo ( "{\" scale\" :" + emptyHistogram .scale () + "}" ) );
3737 }
3838
3939 public void testFullHistogram () {
@@ -44,14 +44,16 @@ public void testFullHistogram() {
4444 histo .tryAddBucket (10 , 5 , false );
4545 histo .tryAddBucket (-11 , 10 , true );
4646 histo .tryAddBucket (11 , 20 , true );
47- assertSerializedHistogram (
48- histo ,
49- "{"
50- + "\" scale\" :7,"
51- + "\" zero\" :{\" count\" :42,\" threshold\" :0.1234},"
52- + "\" positive\" :{\" indices\" :[-11,11],\" counts\" :[10,20]},"
53- + "\" negative\" :{\" indices\" :[-10,10],\" counts\" :[15,5]}"
54- + "}"
47+ assertThat (
48+ toJson (histo ),
49+ equalTo (
50+ "{"
51+ + "\" scale\" :7,"
52+ + "\" zero\" :{\" count\" :42,\" threshold\" :0.1234},"
53+ + "\" positive\" :{\" indices\" :[-11,11],\" counts\" :[10,20]},"
54+ + "\" negative\" :{\" indices\" :[-10,10],\" counts\" :[15,5]}"
55+ + "}"
56+ )
5557 );
5658
5759 }
@@ -60,36 +62,36 @@ public void testOnlyZeroThreshold() {
6062 FixedCapacityExponentialHistogram histo = createAutoReleasedHistogram (10 );
6163 histo .setZeroBucket (new ZeroBucket (5.0 , 0 ));
6264 histo .resetBuckets (3 );
63- assertSerializedHistogram ( histo , "{\" scale\" :3,\" zero\" :{\" threshold\" :5.0}}" );
65+ assertThat ( toJson ( histo ), equalTo ( "{\" scale\" :3,\" zero\" :{\" threshold\" :5.0}}" ) );
6466 }
6567
6668 public void testOnlyZeroCount () {
6769 FixedCapacityExponentialHistogram histo = createAutoReleasedHistogram (10 );
6870 histo .setZeroBucket (new ZeroBucket (0.0 , 7 ));
6971 histo .resetBuckets (2 );
70- assertSerializedHistogram ( histo , "{\" scale\" :2,\" zero\" :{\" count\" :7}}" );
72+ assertThat ( toJson ( histo ), equalTo ( "{\" scale\" :2,\" zero\" :{\" count\" :7}}" ) );
7173 }
7274
7375 public void testOnlyPositiveBuckets () {
7476 FixedCapacityExponentialHistogram histo = createAutoReleasedHistogram (10 );
7577 histo .resetBuckets (4 );
7678 histo .tryAddBucket (-1 , 3 , true );
7779 histo .tryAddBucket (2 , 5 , true );
78- assertSerializedHistogram ( histo , "{\" scale\" :4,\" positive\" :{\" indices\" :[-1,2],\" counts\" :[3,5]}}" );
80+ assertThat ( toJson ( histo ), equalTo ( "{\" scale\" :4,\" positive\" :{\" indices\" :[-1,2],\" counts\" :[3,5]}}" ) );
7981 }
8082
8183 public void testOnlyNegativeBuckets () {
8284 FixedCapacityExponentialHistogram histo = createAutoReleasedHistogram (10 );
8385 histo .resetBuckets (5 );
8486 histo .tryAddBucket (-1 , 4 , false );
8587 histo .tryAddBucket (2 , 6 , false );
86- assertSerializedHistogram ( histo , "{\" scale\" :5,\" negative\" :{\" indices\" :[-1,2],\" counts\" :[4,6]}}" );
88+ assertThat ( toJson ( histo ), equalTo ( "{\" scale\" :5,\" negative\" :{\" indices\" :[-1,2],\" counts\" :[4,6]}}" ) );
8789 }
8890
89- private static void assertSerializedHistogram (ExponentialHistogram histo , String expectedJson ) {
91+ private static String toJson (ExponentialHistogram histo ) {
9092 try (XContentBuilder builder = JsonXContent .contentBuilder ()) {
9193 ExponentialHistogramXContent .serialize (builder , histo );
92- assertThat ( Strings .toString (builder ), equalTo ( expectedJson ) );
94+ return Strings .toString (builder );
9395 } catch (IOException e ) {
9496 throw new RuntimeException (e );
9597 }
0 commit comments