diff options
author | Javen O'Neal <onealj@apache.org> | 2017-04-15 02:19:24 +0000 |
---|---|---|
committer | Javen O'Neal <onealj@apache.org> | 2017-04-15 02:19:24 +0000 |
commit | 5e81082b937db500ddbe47afc82dacefc98f1208 (patch) | |
tree | 9316d6a8b2734a9bbee1abbd92b2be17fbcadf1b /src/testcases/org/apache/poi/POITestCase.java | |
parent | d572959cd33189b1c70b9069c7312753d979411d (diff) | |
download | poi-5e81082b937db500ddbe47afc82dacefc98f1208.tar.gz poi-5e81082b937db500ddbe47afc82dacefc98f1208.zip |
use assertStartsWith and assertEndsWith for better unit test error messages
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1791440 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache/poi/POITestCase.java')
-rw-r--r-- | src/testcases/org/apache/poi/POITestCase.java | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/testcases/org/apache/poi/POITestCase.java b/src/testcases/org/apache/poi/POITestCase.java index 3664da686e..a5895c4f0e 100644 --- a/src/testcases/org/apache/poi/POITestCase.java +++ b/src/testcases/org/apache/poi/POITestCase.java @@ -44,12 +44,47 @@ import org.apache.poi.util.Internal; */ @Internal public final class POITestCase { + /* + * Returns the first {@code length} characters from the string {@code s} + */ + private static String head(String s, int length) { + if (length <= 0) { + return ""; + } + if (s.length() <= length) { + return s; + } + final StringBuilder sb = new StringBuilder(s.substring(0, length)); + sb.append("... (length=").append(s.length()).append(")"); + return sb.toString(); + } + + /* + * Returns the last {@code length} characters from the string {@code s} + */ + private static String tail(String s, int length) { + if (length <= 0) { + return ""; + } + if (s.length() <= length) { + return s; + } + final StringBuilder sb = new StringBuilder(); + sb.append("(length=").append(s.length()).append(") ..."); + sb.append(s.substring(s.length() - length)); + return sb.toString(); + } + public static void assertStartsWith(String string, String prefix) { assertNotNull(string); assertNotNull(prefix); - - final int len = Math.min(string.length(), prefix.length()); - assertEquals("string does not start with prefix", prefix, string.substring(0, len)); + assertEquals("string does not start with prefix", prefix, head(string, prefix.length()+5)); + } + + public static void assertEndsWith(String string, String suffix) { + assertNotNull(string); + assertNotNull(suffix); + assertEquals("string does not end with suffix", suffix, tail(string, suffix.length()+5)); } public static void assertContains(String haystack, String needle) { |