diff --git a/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/CollectionFieldDescription.java b/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/CollectionFieldDescription.java index 78077bfb5..122e11760 100644 --- a/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/CollectionFieldDescription.java +++ b/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/CollectionFieldDescription.java @@ -97,10 +97,11 @@ public String getFieldCopy(String lhs, String rhs) { public String getFieldCopyForList(String lhs, String rhs) { String fieldAccessor = getFieldAccessor(); - return "if(" + rhs + "." + fieldAccessor + "==null) {" + lhs + "." + getFieldName() + "(" + MATCHERS - + ".nullValue()); } else if (" + rhs + "." + fieldAccessor + ".isEmpty()) {" + lhs + "." - + getFieldName() + "IsEmptyIterable(); } else {" + lhs + "." + getFieldName() + "Contains(" + rhs + "." - + fieldAccessor + ".stream().map(" + generateMatcherBuilderReferenceFor(generic) + String fieldName = getFieldName(); + return "if(" + rhs + "." + fieldAccessor + "==null) {" + lhs + "." + fieldName + "(" + MATCHERS + + ".nullValue()); } else if (" + rhs + "." + fieldAccessor + ".isEmpty()) {" + lhs + "." + fieldName + + "IsEmptyIterable(); } else {" + lhs + "." + fieldName + "Contains(" + rhs + "." + fieldAccessor + + ".stream().map(" + generateMatcherBuilderReferenceFor(generic) + ").collect(java.util.stream.Collectors.toList())); }"; } diff --git a/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/ComparableFieldDescription.java b/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/ComparableFieldDescription.java index 5626cddd4..7c9ca495f 100644 --- a/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/ComparableFieldDescription.java +++ b/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/ComparableFieldDescription.java @@ -33,25 +33,26 @@ public ComparableFieldDescription(ProvidesMatchersAnnotatedElementData containin @Override protected Collection getSpecificFieldDslMethodFor() { + String fieldtype = getFieldType(); return Arrays.asList( - getDslMethodBuilder().withDeclaration("ComparesEqualTo", this.getFieldType() + " value") + getDslMethodBuilder().withDeclaration("ComparesEqualTo", fieldtype + " value") .withJavaDoc("that this field is equals to another one, using the compareTo method", "value the value to compare with", MATCHERS + "#comparesEqualTo(java.lang.Comparable)") .havingDefault(MATCHERS + ".comparesEqualTo(value)"), - getDslMethodBuilder().withDeclaration("LessThan", this.getFieldType() + " value") + getDslMethodBuilder().withDeclaration("LessThan", fieldtype + " value") .withJavaDoc("that this field is less than another value", "value the value to compare with", MATCHERS + "#lessThan(java.lang.Comparable)") .havingDefault(MATCHERS + ".lessThan(value)"), - getDslMethodBuilder().withDeclaration("lessThanOrEqualTo", this.getFieldType() + " value") + getDslMethodBuilder().withDeclaration("lessThanOrEqualTo", fieldtype + " value") .withJavaDoc("that this field is less or equal than another value", "value the value to compare with", MATCHERS + "#lessThanOrEqualTo(java.lang.Comparable)") .havingDefault(MATCHERS + ".lessThanOrEqualTo(value)"), - getDslMethodBuilder().withDeclaration("GreaterThan", this.getFieldType() + " value") + getDslMethodBuilder().withDeclaration("GreaterThan", fieldtype + " value") .withJavaDoc("that this field is greater than another value", "value the value to compare with", MATCHERS + "#greaterThan(java.lang.Comparable)") .havingDefault(MATCHERS + ".greaterThan(value)"), - getDslMethodBuilder().withDeclaration("GreaterThanOrEqualTo", this.getFieldType() + " value") + getDslMethodBuilder().withDeclaration("GreaterThanOrEqualTo", fieldtype + " value") .withJavaDoc("that this field is greater or equal than another value", "value the value to compare with", MATCHERS + "#greaterThanOrEqualTo(java.lang.Comparable)") diff --git a/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/OptionalFieldDescription.java b/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/OptionalFieldDescription.java index 8c52b7231..f74eb2d1c 100644 --- a/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/OptionalFieldDescription.java +++ b/src/main/java/ch/powerunit/extensions/matchers/provideprocessor/fields/OptionalFieldDescription.java @@ -33,14 +33,15 @@ public OptionalFieldDescription(ProvidesMatchersAnnotatedElementData containingE @Override protected Collection getSpecificFieldDslMethodFor() { + String fieldType = getFieldType(); return Arrays.asList( getDslMethodBuilder().withDeclaration("IsPresent", "").withJavaDoc("with a present optional") - .havingDefault("new org.hamcrest.CustomTypeSafeMatcher<" + this.getFieldType() - + ">(\"optional is present\"){ public boolean matchesSafely(" + this.getFieldType() + .havingDefault("new org.hamcrest.CustomTypeSafeMatcher<" + fieldType + + ">(\"optional is present\"){ public boolean matchesSafely(" + fieldType + " o) {return o.isPresent();}}"), getDslMethodBuilder().withDeclaration("IsNotPresent", "").withJavaDoc("with a not present optional") - .havingDefault("new org.hamcrest.CustomTypeSafeMatcher<" + this.getFieldType() - + ">(\"optional is not present\"){ public boolean matchesSafely(" + this.getFieldType() + .havingDefault("new org.hamcrest.CustomTypeSafeMatcher<" + fieldType + + ">(\"optional is not present\"){ public boolean matchesSafely(" + fieldType + " o) {return !o.isPresent();}}")); }