summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/test/java/bjc
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/test/java/bjc')
-rw-r--r--BJC-Utils2/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java89
-rw-r--r--BJC-Utils2/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest_removeDQuoted.java74
2 files changed, 74 insertions, 89 deletions
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<String> onEmptyString = TokenUtils.removeDQuotedStrings("");
- assertThat(onEmptyString.size(), is(1));
- assertThat(onEmptyString.get(0), is(""));
-
- /*
- * Check handling of strings without embedded strings.
- */
- List<String> 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<String> 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<String> 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<String> onSingleMatchString = removeDQuotedStrings("hello\"there\"");
+
+ assertThat(onSingleMatchString, hasItems("hello", "\"there\""));
+ }
+
+ /*
+ * Check handling of strings without embedded strings.
+ */
+ @Test
+ public void testRemoveDQuote_NoString() {
+ List<String> onNonmatchingString = removeDQuotedStrings("hello");
+
+ assertThat(onNonmatchingString, hasItems("hello"));
+ }
+
+ /*
+ * Check handling of empty strings.
+ */
+ @Test
+ public void testRemoveDQuote_EmptyString() {
+ List<String> onEmptyString = removeDQuotedStrings("");
+
+ assertThat(onEmptyString, hasItems(""));
+ }
+} \ No newline at end of file