From ad2a312a3cff9aced3e56ef1440c9d30d981fea0 Mon Sep 17 00:00:00 2001 From: student Date: Mon, 20 Mar 2017 10:51:27 -0400 Subject: Test removeDQuotedStrings --- .../bjc/utils/test/parserutils/TokenUtilsTest.java | 89 ---------------------- .../parserutils/TokenUtilsTest_removeDQuoted.java | 74 ++++++++++++++++++ 2 files changed, 74 insertions(+), 89 deletions(-) delete mode 100644 BJC-Utils2/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java create mode 100644 BJC-Utils2/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest_removeDQuoted.java (limited to 'BJC-Utils2/src/test/java/bjc') diff --git a/BJC-Utils2/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java b/BJC-Utils2/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java deleted file mode 100644 index 125811d..0000000 --- a/BJC-Utils2/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * - */ -package bjc.utils.test.parserutils; - -import static org.junit.Assert.*; - -import bjc.utils.parserutils.TokenUtils; - -import java.util.List; - -import static org.hamcrest.CoreMatchers.*; - -import org.junit.Test; - -/** - * Tests on token utils. - * - * @author EVE - * - */ -public class TokenUtilsTest { - - /** - * Test method for - * {@link bjc.utils.parserutils.TokenUtils#removeDQuotedStrings(java.lang.String)}. - */ - @Test - public void testRemoveDQuotedStrings() { - /* - * Check handling of empty strings. - */ - List onEmptyString = TokenUtils.removeDQuotedStrings(""); - assertThat(onEmptyString.size(), is(1)); - assertThat(onEmptyString.get(0), is("")); - - /* - * Check handling of strings without embedded strings. - */ - List onNonmatchingString = TokenUtils.removeDQuotedStrings("hello"); - assertThat(onNonmatchingString.size(), is(1)); - assertThat(onNonmatchingString.get(0), is("hello")); - - /* - * Check handling of strings with a single embedded string. - */ - List onSingleMatchString = TokenUtils.removeDQuotedStrings("hello\"there\""); - assertThat(onSingleMatchString.size(), is(2)); - assertThat(onSingleMatchString.get(0), is("hello")); - assertThat(onSingleMatchString.get(1), is("\"there\"")); - - /* - * Check handling a string with mismatched quotes. - * - * TODO is this the right behavior, or should we fail instead? - */ - List onMismatchString = TokenUtils.removeDQuotedStrings("hello\"there"); - assertThat(onMismatchString.size(), is(1)); - assertThat(onMismatchString.get(0), is("hello\"there")); - } - - /** - * Test method for - * {@link bjc.utils.parserutils.TokenUtils#descapeString(java.lang.String)}. - */ - @Test - public void testDescapeString() { - fail("Not yet implemented"); // TODO - } - - /** - * Test method for - * {@link bjc.utils.parserutils.TokenUtils#isDouble(java.lang.String)}. - */ - @Test - public void testIsDouble() { - fail("Not yet implemented"); // TODO - } - - /** - * Test method for - * {@link bjc.utils.parserutils.TokenUtils#isInt(java.lang.String)}. - */ - @Test - public void testIsInt() { - fail("Not yet implemented"); // TODO - } - -} diff --git a/BJC-Utils2/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest_removeDQuoted.java b/BJC-Utils2/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest_removeDQuoted.java new file mode 100644 index 0000000..371a50a --- /dev/null +++ b/BJC-Utils2/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest_removeDQuoted.java @@ -0,0 +1,74 @@ +package bjc.utils.test.parserutils; + +import static org.junit.Assert.*; + +import java.util.List; + +import static org.hamcrest.CoreMatchers.*; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +import static bjc.utils.parserutils.TokenUtils.*; + +public class TokenUtilsTest_removeDQuoted { + @Rule + public ExpectedException exp; + + public TokenUtilsTest_removeDQuoted(ExpectedException exp) { + this.exp = exp; + } + + /* + * Check handling of mismatched strings with no matching strings. + */ + @Test + public void testRemoveDQuoted_MismatchedStringNoMatch() throws IllegalArgumentException { + exp.expect(IllegalArgumentException.class); + exp.expectMessage(containsString("Opening quote was at position 0")); + + removeDQuotedStrings("\"hello"); + } + + /* + * Check handling of mismatched strings with a matching string. + */ + @Test + public void testRemoveDQuoted_MismatchedStringMatch() throws IllegalArgumentException { + exp.expect(IllegalArgumentException.class); + exp.expectMessage(containsString("Opening quote was at position 7")); + + removeDQuotedStrings("\"hello\"\""); + } + + /* + * Check handling of strings with a single embedded string. + */ + @Test + public void testRemoveDQuoted_SingleString() { + List onSingleMatchString = removeDQuotedStrings("hello\"there\""); + + assertThat(onSingleMatchString, hasItems("hello", "\"there\"")); + } + + /* + * Check handling of strings without embedded strings. + */ + @Test + public void testRemoveDQuote_NoString() { + List onNonmatchingString = removeDQuotedStrings("hello"); + + assertThat(onNonmatchingString, hasItems("hello")); + } + + /* + * Check handling of empty strings. + */ + @Test + public void testRemoveDQuote_EmptyString() { + List onEmptyString = removeDQuotedStrings(""); + + assertThat(onEmptyString, hasItems("")); + } +} \ No newline at end of file -- cgit v1.2.3