39
39
import java .util .HexFormat ;
40
40
import java .util .List ;
41
41
import java .util .Map ;
42
+ import java .util .stream .Collectors ;
42
43
43
44
import static net .javacrumbs .jsonunit .JsonAssert .assertJsonEquals ;
44
45
import static org .hamcrest .CoreMatchers .is ;
@@ -149,7 +150,7 @@ public void bigNumsBinaryRoundtrip() throws Exception {
149
150
150
151
@ Test
151
152
public void deserializeStringrefExtensionEnabled () throws Exception {
152
- byte [] stringrefCBOR = loadAnnotatedCBORFixture ("stringref-enabled.annotated-cbor.txt " );
153
+ byte [] stringrefCBOR = loadAnnotatedCBORFixture ("stringref-enabled.annotated-cbor.asc " );
153
154
Event event = Event .deserialize (stringrefCBOR );
154
155
event .getField ("[event][original]" );
155
156
assertEquals ("stringref" , event .getField ("test" ));
@@ -158,7 +159,7 @@ public void deserializeStringrefExtensionEnabled() throws Exception {
158
159
159
160
@ Test
160
161
public void deserializeStringrefExtensionDisabled () throws Exception {
161
- byte [] stringrefCBOR = loadAnnotatedCBORFixture ("stringref-disabled.annotated-cbor.txt " );
162
+ byte [] stringrefCBOR = loadAnnotatedCBORFixture ("stringref-disabled.annotated-cbor.asc " );
162
163
Event event = Event .deserialize (stringrefCBOR );
163
164
event .getField ("[event][original]" );
164
165
assertEquals ("stringref" , event .getField ("test" ));
@@ -592,9 +593,13 @@ static byte[] loadAnnotatedCBORFixture(String name) throws IOException {
592
593
try (InputStream resourceAsStream = EventTest .class .getResourceAsStream (name )) {
593
594
assertNotNull (resourceAsStream );
594
595
595
- String annotated = new String (resourceAsStream .readAllBytes (), StandardCharsets .UTF_8 );
596
- // annotated CBOR: strip #-initiated line comments, then strip whitespace to get hex
597
- String hexBytes = annotated .replaceAll ("#.*(\\ n|$)" , "" ).replaceAll ("\\ s" , "" );
596
+ final String annotatedFixture = new String (resourceAsStream .readAllBytes (), StandardCharsets .US_ASCII );
597
+ final String hexBytes = annotatedFixture .lines ()
598
+ // strip #-prefixed annotations
599
+ .map (line -> line .split ("#" , 2 )[0 ])
600
+ // strip all remaining whitespace
601
+ .map (line -> line .replaceAll ("\\ s" , "" ))
602
+ .collect (Collectors .joining ());
598
603
599
604
// result should be even number of hex digits
600
605
assert hexBytes .matches ("(?i:[0-9a-f]{2})*" );
0 commit comments