From a78d2f10f8142af6a4e557588c06546e2231eb3f Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Sun, 14 Oct 2018 13:06:40 -0400 Subject: Move tests --- .../java/bjc/utils/ioutils/ReportWriterTest.java | 30 ++++ .../java/bjc/utils/parserutils/TokenUtilsTest.java | 153 +++++++++++++++++++++ .../bjc/utils/test/ioutils/ReportWriterTest.java | 30 ---- .../bjc/utils/test/parserutils/TokenUtilsTest.java | 153 --------------------- 4 files changed, 183 insertions(+), 183 deletions(-) create mode 100644 base/src/test/java/bjc/utils/ioutils/ReportWriterTest.java create mode 100644 base/src/test/java/bjc/utils/parserutils/TokenUtilsTest.java delete mode 100644 base/src/test/java/bjc/utils/test/ioutils/ReportWriterTest.java delete mode 100644 base/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java (limited to 'base/src/test') diff --git a/base/src/test/java/bjc/utils/ioutils/ReportWriterTest.java b/base/src/test/java/bjc/utils/ioutils/ReportWriterTest.java new file mode 100644 index 0000000..2092ae0 --- /dev/null +++ b/base/src/test/java/bjc/utils/ioutils/ReportWriterTest.java @@ -0,0 +1,30 @@ +package bjc.utils.ioutils; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.io.StringWriter; + +import bjc.utils.ioutils.ReportWriter; + +import org.junit.Test; + +/** + * Tests for ReportWriter. + * + * @author EVE + * + */ +@SuppressWarnings("javadoc") +public class ReportWriterTest { + @Test + public void testWriteString() { + try (ReportWriter rw = new ReportWriter(new StringWriter())) { + rw.write("foo"); + + assertEquals("foo", rw.toString()); + } catch (IOException ioex) { + + } + } +} diff --git a/base/src/test/java/bjc/utils/parserutils/TokenUtilsTest.java b/base/src/test/java/bjc/utils/parserutils/TokenUtilsTest.java new file mode 100644 index 0000000..08606b3 --- /dev/null +++ b/base/src/test/java/bjc/utils/parserutils/TokenUtilsTest.java @@ -0,0 +1,153 @@ +package bjc.utils.parserutils; + +import static bjc.utils.parserutils.TokenUtils.descapeString; +import static bjc.utils.parserutils.TokenUtils.removeDQuotedStrings; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.List; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; + +/* + * Tests for TokenUtils + */ +@SuppressWarnings("javadoc") +public class TokenUtilsTest { + @Rule + public ExpectedException exp = ExpectedException.none(); + + /* + * Test removeDQuoted + */ + + /* + * 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() { + final List onSingleMatchString = removeDQuotedStrings("hello\"there\""); + + assertThat(onSingleMatchString, hasItems("hello", "\"there\"")); + } + + /* + * Check handling of strings with multiple quoted strings in a row. + */ + @Test + public void testRemoveDQuoted_MultipleSerialString() { + final List onMultipleSerialMatchString = removeDQuotedStrings("\"hello\"\"there\""); + + assertThat(onMultipleSerialMatchString, hasItems("\"hello\"", "\"there\"")); + } + + /* + * Check handling of strings with multiple interleaved strings. + */ + @Test + public void testRemoveDQuoted_MultipleInterleavedString() { + final List onMultipleInterleaveMatchString = removeDQuotedStrings("one\"two\"three\"four\""); + + assertThat(onMultipleInterleaveMatchString, hasItems("one", "\"two\"", "three", "\"four\"")); + } + + /* + * Check handling of strings without embedded strings. + */ + @Test + public void testRemoveDQuote_NoString() { + final List onNonmatchingString = removeDQuotedStrings("hello"); + + assertThat(onNonmatchingString, hasItems("hello")); + } + + /* + * Check handling of empty strings. + */ + @Test + public void testRemoveDQuote_EmptyString() { + final List onEmptyString = removeDQuotedStrings(""); + + assertThat(onEmptyString, hasItems("")); + } + + /* + * Test descapeString + */ + /* + * Check handling of empty strings. + */ + @Test + public void testDescapeString_EmptyString() { + final String onEmptyString = descapeString(""); + + assertThat(onEmptyString, is("")); + } + + /* + * Check handling of strings without escapes + */ + @Test + public void testDescapeString_NonescapeString() { + final String onNonescapeString = descapeString("hello there"); + + assertThat(onNonescapeString, is("hello there")); + } + + /* + * Check handling of strings with single escapes. + */ + @Test + public void testDescapeString_SingleEscapeString() { + final String onSingleEscapeString = descapeString("hello\\tthere"); + + assertThat(onSingleEscapeString, is("hello\tthere")); + } + + /* + * Check handling of strings with multiple escapes. + */ + @Test + public void testDescapeString_MultipleEscapeString() { + final String onMultipleEscapeString = descapeString("hello\\tthere\\tworld"); + + assertThat(onMultipleEscapeString, is("hello\tthere\tworld")); + } + + /* + * Check handling of strings with invalid single escapes. + */ + @Test + public void testDescapeString_InvalidSingleEscapeString() throws IllegalArgumentException { + exp.expect(IllegalArgumentException.class); + exp.expectMessage(containsString("at position 0")); + + descapeString("\\x"); + } +} \ No newline at end of file diff --git a/base/src/test/java/bjc/utils/test/ioutils/ReportWriterTest.java b/base/src/test/java/bjc/utils/test/ioutils/ReportWriterTest.java deleted file mode 100644 index afb5448..0000000 --- a/base/src/test/java/bjc/utils/test/ioutils/ReportWriterTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package bjc.utils.test.ioutils; - -import static org.junit.Assert.*; - -import java.io.IOException; -import java.io.StringWriter; - -import bjc.utils.ioutils.ReportWriter; - -import org.junit.Test; - -/** - * Tests for ReportWriter. - * - * @author EVE - * - */ -@SuppressWarnings("javadoc") -public class ReportWriterTest { - @Test - public void testWriteString() { - try (ReportWriter rw = new ReportWriter(new StringWriter())) { - rw.write("foo"); - - assertEquals("foo", rw.toString()); - } catch (IOException ioex) { - - } - } -} diff --git a/base/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java b/base/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java deleted file mode 100644 index 99593ed..0000000 --- a/base/src/test/java/bjc/utils/test/parserutils/TokenUtilsTest.java +++ /dev/null @@ -1,153 +0,0 @@ -package bjc.utils.test.parserutils; - -import static bjc.utils.parserutils.TokenUtils.descapeString; -import static bjc.utils.parserutils.TokenUtils.removeDQuotedStrings; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.CoreMatchers.hasItems; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.List; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -/* - * Tests for TokenUtils - */ -@SuppressWarnings("javadoc") -public class TokenUtilsTest { - @Rule - public ExpectedException exp = ExpectedException.none(); - - /* - * Test removeDQuoted - */ - - /* - * 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() { - final List onSingleMatchString = removeDQuotedStrings("hello\"there\""); - - assertThat(onSingleMatchString, hasItems("hello", "\"there\"")); - } - - /* - * Check handling of strings with multiple quoted strings in a row. - */ - @Test - public void testRemoveDQuoted_MultipleSerialString() { - final List onMultipleSerialMatchString = removeDQuotedStrings("\"hello\"\"there\""); - - assertThat(onMultipleSerialMatchString, hasItems("\"hello\"", "\"there\"")); - } - - /* - * Check handling of strings with multiple interleaved strings. - */ - @Test - public void testRemoveDQuoted_MultipleInterleavedString() { - final List onMultipleInterleaveMatchString = removeDQuotedStrings("one\"two\"three\"four\""); - - assertThat(onMultipleInterleaveMatchString, hasItems("one", "\"two\"", "three", "\"four\"")); - } - - /* - * Check handling of strings without embedded strings. - */ - @Test - public void testRemoveDQuote_NoString() { - final List onNonmatchingString = removeDQuotedStrings("hello"); - - assertThat(onNonmatchingString, hasItems("hello")); - } - - /* - * Check handling of empty strings. - */ - @Test - public void testRemoveDQuote_EmptyString() { - final List onEmptyString = removeDQuotedStrings(""); - - assertThat(onEmptyString, hasItems("")); - } - - /* - * Test descapeString - */ - /* - * Check handling of empty strings. - */ - @Test - public void testDescapeString_EmptyString() { - final String onEmptyString = descapeString(""); - - assertThat(onEmptyString, is("")); - } - - /* - * Check handling of strings without escapes - */ - @Test - public void testDescapeString_NonescapeString() { - final String onNonescapeString = descapeString("hello there"); - - assertThat(onNonescapeString, is("hello there")); - } - - /* - * Check handling of strings with single escapes. - */ - @Test - public void testDescapeString_SingleEscapeString() { - final String onSingleEscapeString = descapeString("hello\\tthere"); - - assertThat(onSingleEscapeString, is("hello\tthere")); - } - - /* - * Check handling of strings with multiple escapes. - */ - @Test - public void testDescapeString_MultipleEscapeString() { - final String onMultipleEscapeString = descapeString("hello\\tthere\\tworld"); - - assertThat(onMultipleEscapeString, is("hello\tthere\tworld")); - } - - /* - * Check handling of strings with invalid single escapes. - */ - @Test - public void testDescapeString_InvalidSingleEscapeString() throws IllegalArgumentException { - exp.expect(IllegalArgumentException.class); - exp.expectMessage(containsString("at position 0")); - - descapeString("\\x"); - } -} \ No newline at end of file -- cgit v1.2.3