Use final.
This commit is contained in:
parent
de4508c6c9
commit
6bfd380cb1
|
@ -91,10 +91,10 @@ public class CSVParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseWithDelimiterWithQuote() throws IOException {
|
public void testParseWithDelimiterWithQuote() throws IOException {
|
||||||
String source = "'a,b,c',xyz";
|
final String source = "'a,b,c',xyz";
|
||||||
CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\'');
|
final CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\'');
|
||||||
try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) {
|
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("a,b,c", csvRecord.get(0));
|
||||||
assertEquals("xyz", csvRecord.get(1));
|
assertEquals("xyz", csvRecord.get(1));
|
||||||
}
|
}
|
||||||
|
@ -102,8 +102,8 @@ public class CSVParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseWithDelimiterStringWithQuote() throws IOException {
|
public void testParseWithDelimiterStringWithQuote() throws IOException {
|
||||||
String source = "'a[|]b[|]c'[|]xyz\r\nabc[abc][|]xyz";
|
final String source = "'a[|]b[|]c'[|]xyz\r\nabc[abc][|]xyz";
|
||||||
CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setQuote('\'').build();
|
final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setQuote('\'').build();
|
||||||
try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) {
|
try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) {
|
||||||
CSVRecord csvRecord = csvParser.nextRecord();
|
CSVRecord csvRecord = csvParser.nextRecord();
|
||||||
assertEquals("a[|]b[|]c", csvRecord.get(0));
|
assertEquals("a[|]b[|]c", csvRecord.get(0));
|
||||||
|
@ -116,10 +116,10 @@ public class CSVParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseWithDelimiterWithEscape() throws IOException {
|
public void testParseWithDelimiterWithEscape() throws IOException {
|
||||||
String source = "a!,b!,c,xyz";
|
final String source = "a!,b!,c,xyz";
|
||||||
CSVFormat csvFormat = CSVFormat.DEFAULT.withEscape('!');
|
final CSVFormat csvFormat = CSVFormat.DEFAULT.withEscape('!');
|
||||||
try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) {
|
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("a,b,c", csvRecord.get(0));
|
||||||
assertEquals("xyz", csvRecord.get(1));
|
assertEquals("xyz", csvRecord.get(1));
|
||||||
}
|
}
|
||||||
|
@ -127,8 +127,8 @@ public class CSVParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseWithDelimiterStringWithEscape() throws IOException {
|
public void testParseWithDelimiterStringWithEscape() throws IOException {
|
||||||
String source = "a![!|!]b![|]c[|]xyz\r\nabc[abc][|]xyz";
|
final String source = "a![!|!]b![|]c[|]xyz\r\nabc[abc][|]xyz";
|
||||||
CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setEscape('!').build();
|
final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").setEscape('!').build();
|
||||||
try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) {
|
try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) {
|
||||||
CSVRecord csvRecord = csvParser.nextRecord();
|
CSVRecord csvRecord = csvParser.nextRecord();
|
||||||
assertEquals("a[|]b![|]c", csvRecord.get(0));
|
assertEquals("a[|]b![|]c", csvRecord.get(0));
|
||||||
|
@ -141,10 +141,10 @@ public class CSVParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseWithQuoteWithEscape() throws IOException {
|
public void testParseWithQuoteWithEscape() throws IOException {
|
||||||
String source = "'a?,b?,c?d',xyz";
|
final String source = "'a?,b?,c?d',xyz";
|
||||||
CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\'').withEscape('?');
|
final CSVFormat csvFormat = CSVFormat.DEFAULT.withQuote('\'').withEscape('?');
|
||||||
try (CSVParser csvParser = csvFormat.parse(new StringReader(source))) {
|
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("a,b,c?d", csvRecord.get(0));
|
||||||
assertEquals("xyz", csvRecord.get(1));
|
assertEquals("xyz", csvRecord.get(1));
|
||||||
}
|
}
|
||||||
|
@ -152,7 +152,7 @@ public class CSVParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseWithQuoteThrowsException() {
|
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','")).nextRecord());
|
||||||
assertThrows(IOException.class, () -> csvFormat.parse(new StringReader("'a,b,c'abc,xyz")).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());
|
assertThrows(IOException.class, () -> csvFormat.parse(new StringReader("'abc'a,b,c',xyz")).nextRecord());
|
||||||
|
@ -160,13 +160,13 @@ public class CSVParserTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotValueCSV() throws IOException {
|
public void testNotValueCSV() throws IOException {
|
||||||
String source = "#";
|
final String source = "#";
|
||||||
CSVFormat csvFormat = CSVFormat.DEFAULT.withCommentMarker('#');
|
final CSVFormat csvFormat = CSVFormat.DEFAULT.withCommentMarker('#');
|
||||||
CSVParser csvParser = csvFormat.parse(new StringReader(source));
|
final CSVParser csvParser = csvFormat.parse(new StringReader(source));
|
||||||
CSVRecord csvRecord = csvParser.nextRecord();
|
final CSVRecord csvRecord = csvParser.nextRecord();
|
||||||
assertNull(csvRecord);
|
assertNull(csvRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBackslashEscaping() throws IOException {
|
public void testBackslashEscaping() throws IOException {
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ public class ExtendedBufferedReaderTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testReadingInDifferentBuffer() throws Exception {
|
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")) {
|
try (ExtendedBufferedReader reader = createBufferedReader("1\r\n2\r\n")) {
|
||||||
reader.read(tmp1, 0, 2);
|
reader.read(tmp1, 0, 2);
|
||||||
reader.read(tmp2, 2, 2);
|
reader.read(tmp2, 2, 2);
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class JiraCsv206Test {
|
||||||
final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").build();
|
final CSVFormat csvFormat = CSVFormat.DEFAULT.builder().setDelimiter("[|]").build();
|
||||||
CSVRecord record = null;
|
CSVRecord record = null;
|
||||||
try (final CSVParser csvParser = new CSVParser(reader, csvFormat)) {
|
try (final CSVParser csvParser = new CSVParser(reader, csvFormat)) {
|
||||||
Iterator<CSVRecord> iterator = csvParser.iterator();
|
final Iterator<CSVRecord> iterator = csvParser.iterator();
|
||||||
record = iterator.next();
|
record = iterator.next();
|
||||||
assertEquals("FirstName", record.get(0));
|
assertEquals("FirstName", record.get(0));
|
||||||
assertEquals("LastName", record.get(1));
|
assertEquals("LastName", record.get(1));
|
||||||
|
|
Loading…
Reference in New Issue