3939import java .util .HexFormat ;
4040import java .util .List ;
4141import java .util .Map ;
42+ import java .util .stream .Collectors ;
4243
4344import static net .javacrumbs .jsonunit .JsonAssert .assertJsonEquals ;
4445import static org .hamcrest .CoreMatchers .is ;
@@ -149,7 +150,7 @@ public void bigNumsBinaryRoundtrip() throws Exception {
149150
150151 @ Test
151152 public void deserializeStringrefExtensionEnabled () throws Exception {
152- byte [] stringrefCBOR = loadAnnotatedCBORFixture ("stringref-enabled.annotated-cbor.txt " );
153+ byte [] stringrefCBOR = loadAnnotatedCBORFixture ("stringref-enabled.annotated-cbor.asc " );
153154 Event event = Event .deserialize (stringrefCBOR );
154155 event .getField ("[event][original]" );
155156 assertEquals ("stringref" , event .getField ("test" ));
@@ -158,7 +159,7 @@ public void deserializeStringrefExtensionEnabled() throws Exception {
158159
159160 @ Test
160161 public void deserializeStringrefExtensionDisabled () throws Exception {
161- byte [] stringrefCBOR = loadAnnotatedCBORFixture ("stringref-disabled.annotated-cbor.txt " );
162+ byte [] stringrefCBOR = loadAnnotatedCBORFixture ("stringref-disabled.annotated-cbor.asc " );
162163 Event event = Event .deserialize (stringrefCBOR );
163164 event .getField ("[event][original]" );
164165 assertEquals ("stringref" , event .getField ("test" ));
@@ -592,9 +593,13 @@ static byte[] loadAnnotatedCBORFixture(String name) throws IOException {
592593 try (InputStream resourceAsStream = EventTest .class .getResourceAsStream (name )) {
593594 assertNotNull (resourceAsStream );
594595
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 ());
598603
599604 // result should be even number of hex digits
600605 assert hexBytes .matches ("(?i:[0-9a-f]{2})*" );
0 commit comments