Skip to content
Permalink
Browse files
Use final.
  • Loading branch information
garydgregory committed Jul 8, 2021
1 parent de4508c commit 6bfd380cb18d9b5a27f4466edad4226acce288a0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
@@ -91,19 +91,19 @@ private void parseFully(final CSVParser parser) {

@Test
public void testParseWithDelimiterWithQuote() throws IOException {
String source = "'a,b,c',xyz";
CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\'');
final String source = "'a,b,c',xyz";
final CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\'');
try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) {
CSVRecord csvRecord = csvParser.nextRecord();
final CSVRecord csvRecord = csvParser.nextRecord();
assertEquals("a,b,c", csvRecord.get(0));
assertEquals("xyz", csvRecord.get(1));
}
}

@Test
public void testParseWithDelimiterStringWithQuote() throws IOException {
String source = "'a[|]b[|]c'[|]xyz\r\nabc[abc][|]xyz";
CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setQuote('\'').build();
final String source = "'a[|]b[|]c'[|]xyz\r\nabc[abc][|]xyz";
final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setQuote('\'').build();
try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) {
CSVRecord csvRecord = csvParser.nextRecord();
assertEquals("a[|]b[|]c", csvRecord.get(0));
@@ -116,19 +116,19 @@ public void testParseWithDelimiterStringWithQuote() throws IOException {

@Test
public void testParseWithDelimiterWithEscape() throws IOException {
String source = "a!,b!,c,xyz";
CSVFormat csvFormat = CSVFormat.DEFAULT.withEscape('!');
final String source = "a!,b!,c,xyz";
final CSVFormat csvFormat = CSVFormat.DEFAULT.withEscape('!');
try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) {
CSVRecord csvRecord = csvParser.nextRecord();
final CSVRecord csvRecord = csvParser.nextRecord();
assertEquals("a,b,c", csvRecord.get(0));
assertEquals("xyz", csvRecord.get(1));
}
}

@Test
public void testParseWithDelimiterStringWithEscape() throws IOException {
String source = "a![!|!]b![|]c[|]xyz\r\nabc[abc][|]xyz";
CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setEscape('!').build();
final String source = "a![!|!]b![|]c[|]xyz\r\nabc[abc][|]xyz";
final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setEscape('!').build();
try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) {
CSVRecord csvRecord = csvParser.nextRecord();
assertEquals("a[|]b![|]c", csvRecord.get(0));
@@ -141,32 +141,32 @@ public void testParseWithDelimiterStringWithEscape() throws IOException {

@Test
public void testParseWithQuoteWithEscape() throws IOException {
String source = "'a?,b?,c?d',xyz";
CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\'').withEscape('?');
final String source = "'a?,b?,c?d',xyz";
final CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\'').withEscape('?');
try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) {
CSVRecord csvRecord = csvParser.nextRecord();
final CSVRecord csvRecord = csvParser.nextRecord();
assertEquals("a,b,c?d", csvRecord.get(0));
assertEquals("xyz", csvRecord.get(1));
}
}

@Test
public void testParseWithQuoteThrowsException() {
CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\'');
final CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\'');
assertThrows(IOException.class, () -> csvFormat.parse(new StringReader("'a,b,c','")).nextRecord());
assertThrows(IOException.class, () -> csvFormat.parse(new StringReader("'a,b,c'abc,xyz")).nextRecord());
assertThrows(IOException.class, () -> csvFormat.parse(new StringReader("'abc'a,b,c',xyz")).nextRecord());
}

@Test
public void testNotValueCSV() throws IOException {
String source = "#";
CSVFormat csvFormat = CSVFormat.DEFAULT.withCommentMarker('#');
CSVParser csvParser = csvFormat.parse(new StringReader(source));
CSVRecord csvRecord = csvParser.nextRecord();
final String source = "#";
final CSVFormat csvFormat = CSVFormat.DEFAULT.withCommentMarker('#');
final CSVParser csvParser = csvFormat.parse(new StringReader(source));
final CSVRecord csvRecord = csvParser.nextRecord();
assertNull(csvRecord);
}

@Test
public void testBackslashEscaping() throws IOException {

@@ -87,7 +87,7 @@ public void testReadChar() throws Exception {

@Test
public void testReadingInDifferentBuffer() throws Exception {
char[] tmp1 = new char[2], tmp2 = new char[4];
final char[] tmp1 = new char[2], tmp2 = new char[4];
try (ExtendedBufferedReader reader = createBufferedReader("1\r\n2\r\n")) {
reader.read(tmp1, 0, 2);
reader.read(tmp2, 2, 2);
@@ -38,7 +38,7 @@ public void testJiraCsv206MultipleCharacterDelimiter() throws IOException {
final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").build();
CSVRecord record = null;
try (final CSVParser csvParser = new CSVParser(reader, csvFormat)) {
Iterator<CSVRecord> iterator = csvParser.iterator();
final Iterator<CSVRecord> iterator = csvParser.iterator();
record = iterator.next();
assertEquals("FirstName", record.get(0));
assertEquals("LastName", record.get(1));

0 comments on commit 6bfd380

Please sign in to comment.