From 5e9216d331d0c8c49d505370f90e3d29722df577 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Wed, 18 Dec 2019 16:04:03 -0500 Subject: [PATCH] Remove unnecessary array creation for varargs. --- .../java/org/apache/commons/csv/CSVParserTest.java | 4 ++-- .../org/apache/commons/csv/PerformanceTest.java | 5 ++--- .../apache/commons/csv/issues/JiraCsv203Test.java | 14 +++++++------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/test/java/org/apache/commons/csv/CSVParserTest.java b/src/test/java/org/apache/commons/csv/CSVParserTest.java index 310574ac..0d8dd312 100644 --- a/src/test/java/org/apache/commons/csv/CSVParserTest.java +++ b/src/test/java/org/apache/commons/csv/CSVParserTest.java @@ -296,12 +296,12 @@ public class CSVParserTest { assertThrows( IllegalArgumentException.class, () -> CSVParser.parse("a,b,a\n1,2,3\nx,y,z", - CSVFormat.DEFAULT.withHeader(new String[] {}).withAllowDuplicateHeaderNames(false))); + CSVFormat.DEFAULT.withHeader().withAllowDuplicateHeaderNames(false))); } @Test public void testDuplicateHeadersAllowedByDefault() throws Exception { - CSVParser.parse("a,b,a\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader(new String[] {})); + CSVParser.parse("a,b,a\n1,2,3\nx,y,z", CSVFormat.DEFAULT.withHeader()); } @Test diff --git a/src/test/java/org/apache/commons/csv/PerformanceTest.java b/src/test/java/org/apache/commons/csv/PerformanceTest.java index 0f1bb2c9..1f7884f5 100644 --- a/src/test/java/org/apache/commons/csv/PerformanceTest.java +++ b/src/test/java/org/apache/commons/csv/PerformanceTest.java @@ -264,7 +264,7 @@ public class PerformanceTest { private static Constructor getLexerCtor(final String clazz) throws Exception { @SuppressWarnings("unchecked") final Class lexer = (Class) Class.forName("org.apache.commons.csv." + clazz); - return lexer.getConstructor(new Class[]{CSVFormat.class, ExtendedBufferedReader.class}); + return lexer.getConstructor(CSVFormat.class, ExtendedBufferedReader.class); } private static void testCSVLexer(final boolean newToken, final String test) throws Exception { @@ -317,8 +317,7 @@ public class PerformanceTest { private static Lexer createTestCSVLexer(final String test, final ExtendedBufferedReader input) throws InstantiationException, IllegalAccessException, InvocationTargetException, Exception { - return test.startsWith("CSVLexer") ? getLexerCtor(test) - .newInstance(new Object[] { format, input }) : new Lexer(format, input); + return test.startsWith("CSVLexer") ? getLexerCtor(test).newInstance(format, input) : new Lexer(format, input); } private static Stats iterate(final Iterable it) { diff --git a/src/test/java/org/apache/commons/csv/issues/JiraCsv203Test.java b/src/test/java/org/apache/commons/csv/issues/JiraCsv203Test.java index bb116250..9c887bd1 100644 --- a/src/test/java/org/apache/commons/csv/issues/JiraCsv203Test.java +++ b/src/test/java/org/apache/commons/csv/issues/JiraCsv203Test.java @@ -37,7 +37,7 @@ public class JiraCsv203Test { final StringBuffer buffer = new StringBuffer(); try (final CSVPrinter printer = new CSVPrinter(buffer, format)) { - printer.printRecord(new Object[] { null, "Hello", null, "World" }); + printer.printRecord(null, "Hello", null, "World"); } assertEquals("\"N/A\",\"Hello\",\"N/A\",\"World\"\r\n", buffer.toString()); } @@ -51,7 +51,7 @@ public class JiraCsv203Test { final StringBuffer buffer = new StringBuffer(); try (final CSVPrinter printer = new CSVPrinter(buffer, format)) { - printer.printRecord(new Object[] { null, "Hello", null, "World" }); + printer.printRecord(null, "Hello", null, "World"); } assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString()); } @@ -64,7 +64,7 @@ public class JiraCsv203Test { final StringBuffer buffer = new StringBuffer(); try (final CSVPrinter printer = new CSVPrinter(buffer, format)) { - printer.printRecord(new Object[] { null, "Hello", null, "World" }); + printer.printRecord(null, "Hello", null, "World"); } assertEquals("N/A,Hello,N/A,World\r\n", buffer.toString()); } @@ -78,7 +78,7 @@ public class JiraCsv203Test { final StringBuffer buffer = new StringBuffer(); try (final CSVPrinter printer = new CSVPrinter(buffer, format)) { - printer.printRecord(new Object[] { null, "Hello", null, "World" }); + printer.printRecord(null, "Hello", null, "World"); } assertEquals("N/A,Hello,N/A,World\r\n", buffer.toString()); } @@ -92,7 +92,7 @@ public class JiraCsv203Test { final StringBuffer buffer = new StringBuffer(); try (final CSVPrinter printer = new CSVPrinter(buffer, format)) { - printer.printRecord(new Object[] { null, "Hello", null, "World" }); + printer.printRecord(null, "Hello", null, "World"); } assertEquals("N/A,\"Hello\",N/A,\"World\"\r\n", buffer.toString()); } @@ -106,7 +106,7 @@ public class JiraCsv203Test { final StringBuffer buffer = new StringBuffer(); try (final CSVPrinter printer = new CSVPrinter(buffer, format)) { - printer.printRecord(new Object[] { null, "Hello", null, "World" }); + printer.printRecord(null, "Hello", null, "World"); } assertEquals(",\"Hello\",,\"World\"\r\n", buffer.toString()); } @@ -120,7 +120,7 @@ public class JiraCsv203Test { final StringBuffer buffer = new StringBuffer(); try (final CSVPrinter printer = new CSVPrinter(buffer, format)) { - printer.printRecord(new Object[] { "", "Hello", "", "World" }); + printer.printRecord("", "Hello", "", "World"); //printer.printRecord(new Object[] { null, "Hello", null, "World" }); } assertEquals("\"\",\"Hello\",\"\",\"World\"\r\n", buffer.toString());