From d6deb190e61b9b891af2fe67198a18b4ddb2057f Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Sat, 2 Jan 2016 13:24:02 +0100 Subject: Simplify pgm tests: allow varargs and trim output for toString() Change-Id: Ia5bcd9e560b90cf872fef75c2800c889ef1cc85a Signed-off-by: Andrey Loskutov --- .../src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'org.eclipse.jgit.pgm.test/src') diff --git a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java index a72af9a1c4..a3436a0179 100644 --- a/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java +++ b/org.eclipse.jgit.pgm.test/src/org/eclipse/jgit/lib/CLIRepositoryTestCase.java @@ -223,20 +223,24 @@ public class CLIRepositoryTestCase extends LocalDiskRepositoryTestCase { assertEquals(toString(expected), toString(actual)); } - public static String toString(String[] lines) { + public static String toString(String... lines) { return toString(Arrays.asList(lines)); } public static String toString(List lines) { StringBuilder b = new StringBuilder(); for (String s : lines) { + // trim indentation, to simplify tests + s = s.trim(); if (s != null && !s.isEmpty()) { b.append(s); - if (!s.endsWith("\n")) { - b.append('\n'); - } + b.append('\n'); } } + // delete last line break to allow simpler tests with one line compare + if (b.length() > 0 && b.charAt(b.length() - 1) == '\n') { + b.deleteCharAt(b.length() - 1); + } return b.toString(); } -- cgit v1.2.3