From 533e6b9eadd86a34328f85965d0c16b9eee19ccc Mon Sep 17 00:00:00 2001 From: Marcin Grzejszczak Date: Mon, 15 Feb 2016 18:35:56 +0100 Subject: [PATCH] Applied changes following review --- .../accurest/SingleTestGenerator.groovy | 2 +- .../util/DelegatingJsonVerifiable.java | 36 +++++++++---------- .../util/MethodBufferingJsonVerifiable.java | 2 +- .../util/MethodBufferingReadyToCheck.java | 8 ----- 4 files changed, 20 insertions(+), 28 deletions(-) delete mode 100644 accurest-core/src/main/groovy/io/codearte/accurest/util/MethodBufferingReadyToCheck.java diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/SingleTestGenerator.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/SingleTestGenerator.groovy index afb839a3ef..bca38a0b1b 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/SingleTestGenerator.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/SingleTestGenerator.groovy @@ -92,7 +92,7 @@ class SingleTestGenerator { Class.forName(JSON_ASSERT_CLASS) return true } catch (ClassNotFoundException e) { - log.debug("JsonAssert is not present on classpath. Will not add a static import") + log.debug("JsonAssert is not present on classpath. Will not add a static import.") return false } } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/DelegatingJsonVerifiable.java b/accurest-core/src/main/groovy/io/codearte/accurest/util/DelegatingJsonVerifiable.java index 28a95c8a8b..3148dc6a97 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/DelegatingJsonVerifiable.java +++ b/accurest-core/src/main/groovy/io/codearte/accurest/util/DelegatingJsonVerifiable.java @@ -32,11 +32,19 @@ class DelegatingJsonVerifiable implements MethodBufferingJsonVerifiable { value.toString(); } + private void appendMethodWithValue(String methodName, Object value) { + methodsBuffer.append(".").append(methodName).append("(").append(value) + .append(")"); + } + + private void appendMethodWithQuotedValue(String methodName, Object value) { + appendMethodWithValue(methodName, wrapValueWithQuotes(value)); + } + @Override public MethodBufferingJsonVerifiable contains(Object value) { DelegatingJsonVerifiable verifiable = new FinishedDelegatingJsonVerifiable(delegate.contains(value), methodsBuffer); - verifiable.methodsBuffer.append(".contains(").append(wrapValueWithQuotes(value)) - .append(")"); + verifiable.appendMethodWithQuotedValue("contains", value); if (isAssertingAValueInArray()) { verifiable.methodsBuffer.append(".value()"); } @@ -48,11 +56,9 @@ class DelegatingJsonVerifiable implements MethodBufferingJsonVerifiable { Object valueToPut = value instanceof ShouldTraverse ? ((ShouldTraverse) value).value : value; DelegatingJsonVerifiable verifiable = new DelegatingJsonVerifiable(delegate.field(valueToPut), methodsBuffer); if (delegate.isIteratingOverArray() && !(value instanceof ShouldTraverse)) { - verifiable.methodsBuffer.append(".contains(").append(wrapValueWithQuotes(valueToPut)) - .append(")"); + verifiable.appendMethodWithQuotedValue("contains", valueToPut); } else { - verifiable.methodsBuffer.append(".field(").append(wrapValueWithQuotes(valueToPut)) - .append(")"); + verifiable.appendMethodWithQuotedValue("field", valueToPut); } return verifiable; } @@ -60,16 +66,14 @@ class DelegatingJsonVerifiable implements MethodBufferingJsonVerifiable { @Override public MethodBufferingJsonVerifiable array(Object value) { DelegatingJsonVerifiable verifiable = new DelegatingJsonVerifiable(delegate.array(value), methodsBuffer); - verifiable.methodsBuffer.append(".array(").append(wrapValueWithQuotes(value)) - .append(")"); + verifiable.appendMethodWithQuotedValue("array", value); return verifiable; } @Override public MethodBufferingJsonVerifiable arrayField(Object value) { DelegatingJsonVerifiable verifiable = new DelegatingJsonVerifiable(delegate.field(value).arrayField(), methodsBuffer); - verifiable.methodsBuffer.append(".array(").append(wrapValueWithQuotes(value)) - .append(")"); + verifiable.appendMethodWithQuotedValue("array", value); return verifiable; } @@ -96,8 +100,7 @@ class DelegatingJsonVerifiable implements MethodBufferingJsonVerifiable { if (delegate.isAssertingAValueInArray()) { readyToCheck.methodsBuffer.append(".value()"); } else { - readyToCheck.methodsBuffer.append(".isEqualTo(") - .append(wrapValueWithQuotes(value)).append(")"); + readyToCheck.appendMethodWithQuotedValue("isEqualTo", value); } return readyToCheck; } @@ -116,8 +119,7 @@ class DelegatingJsonVerifiable implements MethodBufferingJsonVerifiable { if (delegate.isAssertingAValueInArray()) { readyToCheck.methodsBuffer.append(".value()"); } else { - readyToCheck.methodsBuffer.append(".isEqualTo(").append(String.valueOf(value)) - .append(")"); + readyToCheck.appendMethodWithValue("isEqualTo", String.valueOf(value)); } return readyToCheck; } @@ -135,8 +137,7 @@ class DelegatingJsonVerifiable implements MethodBufferingJsonVerifiable { if (delegate.isAssertingAValueInArray()) { readyToCheck.methodsBuffer.append(".value()"); } else { - readyToCheck.methodsBuffer.append(".matches(").append(wrapValueWithQuotes(value)) - .append(")"); + readyToCheck.appendMethodWithQuotedValue("matches", value); } return readyToCheck; } @@ -147,8 +148,7 @@ class DelegatingJsonVerifiable implements MethodBufferingJsonVerifiable { if (delegate.isAssertingAValueInArray()) { readyToCheck.methodsBuffer.append(".value()"); } else { - readyToCheck.methodsBuffer.append(".isEqualTo(").append(String.valueOf(value)) - .append(")"); + readyToCheck.appendMethodWithValue("isEqualTo", String.valueOf(value)); } return readyToCheck; } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/MethodBufferingJsonVerifiable.java b/accurest-core/src/main/groovy/io/codearte/accurest/util/MethodBufferingJsonVerifiable.java index d19a24f99a..c46e0f61b7 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/MethodBufferingJsonVerifiable.java +++ b/accurest-core/src/main/groovy/io/codearte/accurest/util/MethodBufferingJsonVerifiable.java @@ -6,7 +6,7 @@ import com.blogspot.toomuchcoding.jsonassert.JsonVerifiable; * @author Marcin Grzejszczak */ public interface MethodBufferingJsonVerifiable - extends JsonVerifiable, MethodBuffering, MethodBufferingReadyToCheck { + extends JsonVerifiable, MethodBuffering { @Override MethodBufferingJsonVerifiable contains(Object value); diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/util/MethodBufferingReadyToCheck.java b/accurest-core/src/main/groovy/io/codearte/accurest/util/MethodBufferingReadyToCheck.java deleted file mode 100644 index b885692ead..0000000000 --- a/accurest-core/src/main/groovy/io/codearte/accurest/util/MethodBufferingReadyToCheck.java +++ /dev/null @@ -1,8 +0,0 @@ -package io.codearte.accurest.util; - -/** - * @author Marcin Grzejszczak - */ -interface MethodBufferingReadyToCheck extends MethodBuffering { - -}