diff --git a/support/src/main/java/com/shopify/graphql/support/Query.java b/support/src/main/java/com/shopify/graphql/support/Query.java index f6c53c5..fd9dd4b 100644 --- a/support/src/main/java/com/shopify/graphql/support/Query.java +++ b/support/src/main/java/com/shopify/graphql/support/Query.java @@ -5,6 +5,7 @@ */ public abstract class Query { public static final String ALIAS_SUFFIX_SEPARATOR = "__"; + private static final String BAD_ALIAS_SEPARATOR = "-"; private static final String ALIAS_DELIMITER = ":"; protected final StringBuilder _queryBuilder; private boolean firstSelection = true; @@ -82,6 +83,9 @@ public T withAlias(String aliasSuffix) { if (aliasSuffix.contains(Query.ALIAS_SUFFIX_SEPARATOR)) { throw new IllegalArgumentException("Alias must not contain __"); } + if (aliasSuffix.contains(Query.BAD_ALIAS_SEPARATOR)) { + throw new IllegalArgumentException("Alias must not contain -"); + } this.aliasSuffix = aliasSuffix; // noinspection unchecked return (T) this; diff --git a/support/src/test/java/com/shopify/graphql/support/QueryTest.java b/support/src/test/java/com/shopify/graphql/support/QueryTest.java index 6496140..4764768 100644 --- a/support/src/test/java/com/shopify/graphql/support/QueryTest.java +++ b/support/src/test/java/com/shopify/graphql/support/QueryTest.java @@ -3,7 +3,6 @@ import org.junit.Test; import static junit.framework.Assert.assertEquals; -import static org.junit.Assert.assertTrue; public class QueryTest { @Test @@ -13,29 +12,18 @@ public void testStringEscaping() throws Exception { assertEquals("\"\\u0000 \\r \\n \\\\ \\\" c ꝏ\"", result.toString()); } - @Test - public void testInvalidAlias() { - boolean exceptionThrown = false; - try { - new Query(null) { - }.withAlias("invalid__alias"); - } catch (IllegalArgumentException e) { - exceptionThrown = true; - } finally { - assertTrue(exceptionThrown); - } + @Test(expected = IllegalArgumentException.class) + public void testInvalidAliasWithUnderscore() { + new Query(null) {}.withAlias("invalid__alias"); } - @Test + @Test(expected = IllegalArgumentException.class) + public void testInvalidAliasWithDashes() { + new Query(null) {}.withAlias("invalid-alias"); + } + + @Test(expected = IllegalArgumentException.class) public void testBlankAlias() { - boolean exceptionThrown = false; - try { - new Query(null) { - }.withAlias(""); - } catch (IllegalArgumentException e) { - exceptionThrown = true; - } finally { - assertTrue(exceptionThrown); - } + new Query(null) {}.withAlias(""); } }