diff --git a/jOOQ/src/test/java/org/jooq/impl/PostgresArrayEscapingTest.java b/jOOQ/src/test/java/org/jooq/impl/PostgresArrayEscapingTest.java new file mode 100644 index 0000000000..2dd7f57943 --- /dev/null +++ b/jOOQ/src/test/java/org/jooq/impl/PostgresArrayEscapingTest.java @@ -0,0 +1,33 @@ +package org.jooq.impl; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class PostgresArrayEscapingTest { + @Test(expected=NullPointerException.class) + public void nullObjectShouldNotWork() { + DefaultBindContext.postgresArrayString(null); + } + + @Test + public void simpleStrings() { + assertEquals("{\"foo\"}", DefaultBindContext.postgresArrayString(new String[]{"foo"})); + assertEquals("{\"foo\", \"bar\"}", DefaultBindContext.postgresArrayString(new String[]{"foo", "bar"})); + } + + @Test + public void stringsWithSingleQuotesAreFine() { + assertEquals("{\"'foo\"}", DefaultBindContext.postgresArrayString(new String[]{"'foo"})); + } + + @Test + public void numbers() { + assertEquals("{\"1\", \"2\"}", DefaultBindContext.postgresArrayString(new Object[]{1, 2})); + } + + @Test + public void nulls() { + assertEquals("{null}", DefaultBindContext.postgresArrayString(new Object[]{null})); + } +}