11// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
3-
43package com .amazon .ion .impl ;
54
65import com .amazon .ion .BufferConfiguration ;
1312import com .amazon .ion .system .IonBinaryWriterBuilder ;
1413import com .amazon .ion .system .IonReaderBuilder ;
1514import com .amazon .ion .util .RepeatInputStream ;
16- import org .junit .Rule ;
17- import org .junit .Test ;
18- import org .junit .rules .ExpectedException ;
15+ import org .junit .jupiter .api .Test ;
16+ import org .junit .jupiter .api .condition .EnabledIfEnvironmentVariable ;
1917
2018import java .io .ByteArrayInputStream ;
2119import java .io .ByteArrayOutputStream ;
2220import java .io .IOException ;
2321import java .io .InputStream ;
2422import java .io .SequenceInputStream ;
2523import java .math .BigDecimal ;
24+ import java .nio .charset .StandardCharsets ;
2625
2726import static com .amazon .ion .impl ._Private_IonConstants .BINARY_VERSION_MARKER_1_0 ;
28- import static junit .framework .TestCase .assertNull ;
29- import static org .junit .Assert .assertEquals ;
30-
31- // NOTE: these tests each take several seconds to complete.
27+ import static org .junit .jupiter .api .Assertions .assertEquals ;
28+ import static org .junit .jupiter .api .Assertions .assertNull ;
29+ import static org .junit .jupiter .api .Assertions .assertThrows ;
30+
31+ @ EnabledIfEnvironmentVariable (
32+ // GitHub actions and other CI systems will set CI=true
33+ named = "CI" , matches = "true" ,
34+ disabledReason = "It regularly takes about 1 minute to run all the tests in this class."
35+ )
3236public class IonReaderBinaryLargeStreamTest {
3337
3438 private byte [] testData (Timestamp timestamp ) throws IOException {
@@ -295,11 +299,8 @@ public void skipLargeAnnotatedContainer() throws Exception {
295299 // when they *do* fail due to limitations of the current implementation, they fail by throwing an IonException
296300 // and not something unexpected and ugly.
297301
298- @ Rule
299- public ExpectedException thrown = ExpectedException .none ();
300-
301302 private void cleanlyFailsOnLargeScalar (IonReaderBuilder readerBuilder ) throws Exception {
302- byte [] data = "foobarbaz" .getBytes ("UTF-8" );
303+ byte [] data = "foobarbaz" .getBytes (StandardCharsets . UTF_8 );
303304 final int totalNumberOfBatches = (Integer .MAX_VALUE / data .length ) + 123 ; // 123 makes the value exceed Integer.MAX_VALUE by an arbitrary amount.
304305 ByteArrayOutputStream header = new ByteArrayOutputStream ();
305306 header .write (BINARY_VERSION_MARKER_1_0 );
@@ -313,12 +314,10 @@ private void cleanlyFailsOnLargeScalar(IonReaderBuilder readerBuilder) throws Ex
313314 // If support for large scalars is added, the following will be deleted and the rest of the test
314315 // completed to assert the correctness of the value.
315316 if (readerBuilder .isIncrementalReadingEnabled ()) {
316- thrown .expect (IonException .class );
317- reader .next ();
317+ assertThrows (IonException .class , reader ::next );
318318 } else {
319319 assertEquals (IonType .STRING , reader .next ());
320- thrown .expect (IonException .class );
321- reader .stringValue ();
320+ assertThrows (IonException .class , reader ::stringValue );
322321 }
323322 }
324323
@@ -333,7 +332,7 @@ public void cleanlyFailsOnLargeScalarIncremental() throws Exception {
333332 }
334333
335334 private void cleanlyFailsOnLargeAnnotatedScalar (IonReaderBuilder readerBuilder ) throws Exception {
336- byte [] data = "foobarbaz" .getBytes ("UTF-8" );
335+ byte [] data = "foobarbaz" .getBytes (StandardCharsets . UTF_8 );
337336 final int totalNumberOfBatches = (Integer .MAX_VALUE / data .length ) + 9999 ; // 9999 makes the value exceed Integer.MAX_VALUE by an arbitrary amount.
338337 final long stringLength = (long ) totalNumberOfBatches * data .length ;
339338 ByteArrayOutputStream header = new ByteArrayOutputStream ();
@@ -352,12 +351,10 @@ private void cleanlyFailsOnLargeAnnotatedScalar(IonReaderBuilder readerBuilder)
352351 // If support for large scalars is added, the following will be deleted and the rest of the test
353352 // completed to assert the correctness of the value.
354353 if (readerBuilder .isIncrementalReadingEnabled ()) {
355- thrown .expect (IonException .class );
356- reader .next ();
354+ assertThrows (IonException .class , reader ::next );
357355 } else {
358356 assertEquals (IonType .STRING , reader .next ());
359- thrown .expect (IonException .class );
360- reader .stringValue ();
357+ assertThrows (IonException .class , reader ::stringValue );
361358 }
362359 }
363360
@@ -388,8 +385,7 @@ public void cleanlyFailsOnLargeContainerIncremental() throws Exception {
388385 );
389386
390387 IonReader reader = newReaderBuilderThatThrowsOnOversizedValues (true ).build (inputStream );
391- thrown .expect (IonException .class );
392- reader .next ();
388+ assertThrows (IonException .class , reader ::next );
393389 }
394390
395391}
0 commit comments