diff --git a/src/main/kotlin/Field.kt b/src/main/kotlin/Field.kt index 11fb00d..924944d 100644 --- a/src/main/kotlin/Field.kt +++ b/src/main/kotlin/Field.kt @@ -14,17 +14,19 @@ class Field private constructor( val parameterName: String? = null, val qualifier: String? = null) { + init { + if (parameterName != null && !parameterName.startsWith(':') && !parameterName.startsWith('@')) + throw DocumentException("Parameter Name must start with : or @ ($name)") + } + /** * Specify the parameter name for the field * * @param paramName The parameter name to use for this field * @return A new `Field` with the parameter name specified */ - fun withParameterName(paramName: String): Field { - if (!paramName.startsWith(':') && !paramName.startsWith('@')) - throw DocumentException("Parameter must start with : or @ ($paramName)") - return Field(name, comparison, paramName, qualifier) - } + fun withParameterName(paramName: String) = + Field(name, comparison, paramName, qualifier) /** * Specify a qualifier (alias) for the document table diff --git a/src/test/kotlin/FieldTest.kt b/src/test/kotlin/FieldTest.kt index 9782532..5aeff2a 100644 --- a/src/test/kotlin/FieldTest.kt +++ b/src/test/kotlin/FieldTest.kt @@ -530,6 +530,12 @@ class FieldTest { assertNull(field.qualifier, "The qualifier should have been null") } + @Test + @DisplayName("static constructors fail for invalid parameter name") + fun staticCtorsFailOnParamName() { + assertThrows { Field.equal("a", "b", "that ain't it, Jack...") } + } + @Test @DisplayName("nameToPath creates a simple PostgreSQL SQL name") fun nameToPathPostgresSimpleSQL() =