Skip to content

Commit e2e0196

Browse files
authored
Merge branch 'master' into dependabot/github_actions/github-action-dependencies-d18f096e8d
2 parents e161b5e + 1b68d1e commit e2e0196

3 files changed

Lines changed: 54 additions & 98 deletions

File tree

‎.github/workflows/main.yml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ env:
88
on:
99
push:
1010
pull_request:
11-
branches: [ master ]
1211

1312
jobs:
1413
build-and-test:

‎ion-java-cli/src/main/java/com/amazon/tools/cli/OutputFormat.java‎

Lines changed: 35 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -11,78 +11,39 @@
1111
* Represents the different Ion output formats supported by the command line com.amazon.tools in this package.
1212
*/
1313
public enum OutputFormat {
14-
/**
15-
* Nicely spaced, 'prettified' text Ion.
16-
*/
17-
PRETTY {
18-
@Override
19-
public IonWriter createIonWriter(OutputStream outputStream) {
20-
return IonTextWriterBuilder.pretty().build(outputStream);
21-
}
22-
23-
@Override
24-
public IonWriter createIonWriterWithImports(OutputStream outputStream, SymbolTable[] imports) {
25-
return IonTextWriterBuilder.pretty().withImports(imports).build(outputStream);
26-
}
27-
},
28-
/**
29-
* Minimally spaced text Ion.
30-
*/
31-
TEXT {
32-
@Override
33-
public IonWriter createIonWriter(OutputStream outputStream) {
34-
return IonTextWriterBuilder.standard().build(outputStream);
35-
}
36-
37-
@Override
38-
public IonWriter createIonWriterWithImports(OutputStream outputStream, SymbolTable[] imports) {
39-
return IonTextWriterBuilder.standard().withImports(imports).build(outputStream);
40-
}
41-
},
42-
/**
43-
* Compact, read-optimized binary Ion.
44-
*/
45-
BINARY {
46-
@Override
47-
public IonWriter createIonWriter(OutputStream outputStream) {
48-
return IonBinaryWriterBuilder.standard().build(outputStream);
49-
}
50-
51-
@Override
52-
public IonWriter createIonWriterWithImports(OutputStream outputStream, SymbolTable[] imports) {
53-
return IonBinaryWriterBuilder.standard().withImports(imports).build(outputStream);
54-
}
55-
},
56-
/**
57-
* Event Stream
58-
*/
59-
EVENTS {
60-
@Override
61-
public IonWriter createIonWriter(OutputStream outputStream) {
62-
return IonTextWriterBuilder.pretty().build(outputStream);
63-
}
64-
65-
@Override
66-
public IonWriter createIonWriterWithImports(OutputStream outputStream, SymbolTable[] imports) {
67-
return IonTextWriterBuilder.pretty().withImports(imports).build(outputStream);
68-
}
69-
},
70-
/**
71-
* None
72-
*/
73-
NONE {
74-
@Override
75-
public IonWriter createIonWriter(OutputStream outputStream) {
76-
NoOpOutputStream out = new NoOpOutputStream();
77-
return IonTextWriterBuilder.pretty().build(out);
78-
}
79-
80-
@Override
81-
public IonWriter createIonWriterWithImports(OutputStream outputStream, SymbolTable[] imports) {
82-
return IonTextWriterBuilder.pretty().withImports(imports).build(outputStream);
83-
}
84-
};
85-
86-
abstract IonWriter createIonWriter(OutputStream outputStream);
87-
abstract IonWriter createIonWriterWithImports(OutputStream outputStream, SymbolTable[] symbolTable);
14+
/** Nicely spaced, 'prettified' text Ion */ PRETTY,
15+
/** Minimally spaced text Ion */ TEXT,
16+
/** Compact, read-optimized binary Ion */ BINARY,
17+
/** Event Stream */ EVENTS,
18+
/** No output, /dev/null */ NONE;
19+
20+
IonWriter createIonWriter(OutputStream outputStream) {
21+
return createIonWriter(this, outputStream);
22+
}
23+
24+
IonWriter createIonWriterWithImports(OutputStream outputStream, SymbolTable[] symbolTable) {
25+
return createIonWriter(this, outputStream, symbolTable);
26+
}
27+
28+
private static IonWriter createIonWriter(OutputFormat format, OutputStream outputStream) {
29+
switch (format) {
30+
case TEXT: return IonTextWriterBuilder.standard().build(outputStream);
31+
case PRETTY: return IonTextWriterBuilder.pretty().build(outputStream);
32+
case EVENTS: return IonTextWriterBuilder.pretty().build(outputStream);
33+
case BINARY: return IonBinaryWriterBuilder.standard().build(outputStream);
34+
case NONE: return IonTextWriterBuilder.standard().build(new NoOpOutputStream());
35+
default: throw new IllegalStateException("Unsupported output format: " + format);
36+
}
37+
}
38+
39+
private static IonWriter createIonWriter(OutputFormat format, OutputStream out, SymbolTable... symbols) {
40+
switch (format) {
41+
case TEXT: return IonTextWriterBuilder.standard().withImports(symbols).build(out);
42+
case PRETTY: return IonTextWriterBuilder.pretty().withImports(symbols).build(out);
43+
case EVENTS: return IonTextWriterBuilder.pretty().withImports(symbols).build(out);
44+
case BINARY: return IonBinaryWriterBuilder.standard().withImports(symbols).build(out);
45+
case NONE: return IonTextWriterBuilder.standard().withImports(symbols).build(new NoOpOutputStream());
46+
default: throw new IllegalStateException("Unsupported output format: " + format);
47+
}
48+
}
8849
}

‎src/test/java/com/amazon/ion/impl/IonReaderBinaryLargeStreamTest.java‎

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
43
package com.amazon.ion.impl;
54

65
import com.amazon.ion.BufferConfiguration;
@@ -13,22 +12,27 @@
1312
import com.amazon.ion.system.IonBinaryWriterBuilder;
1413
import com.amazon.ion.system.IonReaderBuilder;
1514
import 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

2018
import java.io.ByteArrayInputStream;
2119
import java.io.ByteArrayOutputStream;
2220
import java.io.IOException;
2321
import java.io.InputStream;
2422
import java.io.SequenceInputStream;
2523
import java.math.BigDecimal;
24+
import java.nio.charset.StandardCharsets;
2625

2726
import 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+
)
3236
public 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

Comments
 (0)