Skip to content

Commit

Permalink
Issue #142, #143, #144 (#155)
Browse files Browse the repository at this point in the history
Close #142 
Close #143 
Close #144
  • Loading branch information
boretti committed May 13, 2018
1 parent c824304 commit 38601f7
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 25 deletions.
Expand Up @@ -39,9 +39,9 @@ public DefaultBeanMatchersAutomatedExtension(RoundMirror roundMirror) {

@Override
protected Collection<FieldDSLMethod> acceptBeanMatchers(AbstractFieldDescription field) {
return Collections.singletonList(builderFor(field).withDeclaration("IsAValidBean", "")
.withJavaDoc("Check that this field (clazz) is a correct bean, based on Bean Matchers").havingDefault(
"org.hamcrest.CoreMatchers.allOf(com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor(),com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters(),com.google.code.beanmatchers.BeanMatchers.hasValidBeanHashCode(),com.google.code.beanmatchers.BeanMatchers.hasValidBeanEquals(),com.google.code.beanmatchers.BeanMatchers.hasValidBeanToString())"));
return Collections.singletonList(builderFor(field).withSuffixDeclarationJavadocAndDefault("IsAValidBean",
"Check that this field (clazz) is a correct bean, based on Bean Matchers",
"org.hamcrest.CoreMatchers.allOf(com.google.code.beanmatchers.BeanMatchers.hasValidBeanConstructor(),com.google.code.beanmatchers.BeanMatchers.hasValidGettersAndSetters(),com.google.code.beanmatchers.BeanMatchers.hasValidBeanHashCode(),com.google.code.beanmatchers.BeanMatchers.hasValidBeanEquals(),com.google.code.beanmatchers.BeanMatchers.hasValidBeanToString())"));
}

}
Expand Up @@ -43,9 +43,10 @@ protected Collection<FieldDSLMethod> acceptHamcrestUtility(AbstractFieldDescript
String expectedElement = getExpectedElement();
String genericMatcher = "org.hamcrest.Matcher<" + field.getGeneric() + ">";
return Arrays.asList(
builderFor(field, "hasNoDuplicates", "").withJavaDoc("That this collection contains no duplication")
.havingDefault("(org.hamcrest.Matcher)" + expectedElement
+ ".hasNoDuplicates(java.lang.Object.class)"),
builderFor(field, "hasNoDuplicates", "")
.withJavaDocAndDefault("That this collection contains no duplication",
"(org.hamcrest.Matcher)" + expectedElement
+ ".hasNoDuplicates(java.lang.Object.class)"),
builderFor(field, "hasFirstItem", genericMatcher + " matcher")
.withJavaDoc(Optional.of("having first item with a specific value"),
Optional.of("matcher matcher on the item"), Optional.empty())
Expand Down
Expand Up @@ -33,9 +33,8 @@ public ArrayFieldDescription(ProvidesMatchersAnnotatedElementData containingElem

@Override
protected Collection<FieldDSLMethod> getSpecificFieldDslMethodFor() {
return Collections
.singleton(getDslMethodBuilder().withDeclaration("IsEmpty", "").withJavaDoc("that the array is empty")
.havingDefault("(org.hamcrest.Matcher)" + MATCHERS + ".emptyArray()"));
return Collections.singleton(getDslMethodBuilder().withSuffixDeclarationJavadocAndDefault("IsEmpty",
"that the array is empty", "(org.hamcrest.Matcher)" + MATCHERS + ".emptyArray()"));
}

}
Expand Up @@ -52,10 +52,10 @@ protected Collection<FieldDSLMethod> getSpecificFieldDslMethodFor() {

public List<FieldDSLMethod> getFieldDslMethodForIterableAndComparable() {
return Arrays.asList(
getDslMethodBuilder().withDeclaration("IsEmptyIterable", "").withJavaDoc("that the iterable is empty")
.havingDefault("(org.hamcrest.Matcher)" + MATCHERS + ".emptyIterable()"),
getDslMethodBuilder().withDeclaration("IsEmpty", "").withJavaDoc("that the collection is empty")
.havingDefault("(org.hamcrest.Matcher)" + MATCHERS + ".empty()"));
getDslMethodBuilder().withSuffixDeclarationJavadocAndDefault("IsEmptyIterable",
"that the iterable is empty", "(org.hamcrest.Matcher)" + MATCHERS + ".emptyIterable()"),
getDslMethodBuilder().withSuffixDeclarationJavadocAndDefault("IsEmpty", "that the collection is empty",
"(org.hamcrest.Matcher)" + MATCHERS + ".empty()"));
}

public List<FieldDSLMethod> getDslForIterableWithGeneric() {
Expand Down
Expand Up @@ -55,7 +55,7 @@ protected final Collection<FieldDSLMethod> getFieldDslMethodFor() {
tmp.add(FieldDSLMethodBuilder.of(this).withDeclaration(ft + " value")
.withJavaDoc("", "value an expected value for the field, which will be compared using the is matcher",
SEE_TEXT_FOR_IS_MATCHER)
.havingDefault("(org.hamcrest.Matcher)"+MATCHERS + ".is((java.lang.Object)value)"));
.havingDefault("(org.hamcrest.Matcher)" + MATCHERS + ".is((java.lang.Object)value)"));
tmp.add(FieldDSLMethodBuilder.of(this)
.withGenericDeclaration("<_TARGETFIELD>", "As",
"java.util.function.Function<" + ft
Expand All @@ -67,11 +67,11 @@ protected final Collection<FieldDSLMethod> getFieldDslMethodFor() {
if (fullyQualifiedNameMatcherInSameRound != null && te.getTypeParameters().isEmpty()) {
String name = te.getSimpleName().toString();
String lname = name.substring(0, 1).toLowerCase() + name.substring(1);
tmp.add(FieldDSLMethodBuilder.of(this)
.withExplicitDeclaration(fullyQualifiedNameMatcherInSameRound + "." + name + "Matcher" + "<"
+ defaultReturnMethod + "> " + fn + "With()")
.withJavaDoc("by starting a matcher for this field")
.havingImplementation(fullyQualifiedNameMatcherInSameRound + "." + name + "Matcher tmp = "
tmp.add(FieldDSLMethodBuilder.of(this).withExplicitDeclarationJavadocAndImplementation(
fullyQualifiedNameMatcherInSameRound + "." + name + "Matcher" + "<" + defaultReturnMethod + "> "
+ fn + "With()",
"by starting a matcher for this field",
fullyQualifiedNameMatcherInSameRound + "." + name + "Matcher tmp = "
+ fullyQualifiedNameMatcherInSameRound + "." + lname + "WithParent(this);\n" + fn
+ "(tmp);\nreturn tmp;"));
}
Expand Down
Expand Up @@ -73,6 +73,23 @@ public BuilderJavadoc withGenericDeclaration(String generic, String postFix, Str
return this;
}

@Override
public FieldDSLMethod withExplicitDeclarationJavadocAndImplementation(String declaration,
String addToDescription, String body) {
return withExplicitDeclaration(declaration).withJavaDoc(addToDescription).havingImplementation(body);
}

@Override
public FieldDSLMethod withJavaDocAndDefault(String addToDescription, String innerMatcher) {
return withJavaDoc(addToDescription).havingDefault(innerMatcher);
}

@Override
public FieldDSLMethod withSuffixDeclarationJavadocAndDefault(String declaration, String addToDescription,
String innerMatcher) {
return withSuffixDeclaration(declaration).withJavaDocAndDefault(addToDescription, innerMatcher);
}

}

public static String getJavaDocFor(AbstractFieldDescription fieldDescription, Optional<String> addToDescription,
Expand Down
Expand Up @@ -35,12 +35,13 @@ public OptionalFieldDescription(ProvidesMatchersAnnotatedElementData containingE
protected Collection<FieldDSLMethod> getSpecificFieldDslMethodFor() {
String fieldType = getFieldType();
return Arrays.asList(
getDslMethodBuilder().withDeclaration("IsPresent", "").withJavaDoc("with a present optional")
.havingDefault("new org.hamcrest.CustomTypeSafeMatcher<" + fieldType
getDslMethodBuilder().withSuffixDeclarationJavadocAndDefault("IsPresent", "with a present optional",
"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<" + fieldType
getDslMethodBuilder().withSuffixDeclarationJavadocAndDefault("IsNotPresent",
"with a not present optional",
"new org.hamcrest.CustomTypeSafeMatcher<" + fieldType
+ ">(\"optional is not present\"){ public boolean matchesSafely(" + fieldType
+ " o) {return !o.isPresent();}}"));
}
Expand Down
Expand Up @@ -19,10 +19,14 @@
*/
package ch.powerunit.extensions.matchers.provideprocessor.fields.lang;

public interface BuilderDeclaration {
public interface BuilderDeclaration extends BuilderShortCutDeclaration{
BuilderJavadoc withExplicitDeclaration(String declaration);

BuilderJavadoc withGenericDeclaration(String generic, String postFix, String arguments);

default BuilderJavadoc withSuffixDeclaration(String postfix) {
return withDeclaration(postfix,"");
}

default BuilderJavadoc withDeclaration(String postFix, String arguments) {
return withGenericDeclaration("", postFix, arguments);
Expand Down
Expand Up @@ -21,7 +21,7 @@

import java.util.Optional;

public interface BuilderJavadoc {
public interface BuilderJavadoc extends BuilderShortCutJavadoc{
BuilderImplementation withJavaDoc(Optional<String> addToDescription, Optional<String> param, Optional<String> see);

default BuilderImplementation withJavaDoc(String addToDescription, String param, String see) {
Expand Down
@@ -0,0 +1,34 @@
/**
* Powerunit - A JDK1.8 test framework
* Copyright (C) 2014 Mathieu Boretti.
*
* This file is part of Powerunit
*
* Powerunit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Powerunit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Powerunit. If not, see <http://www.gnu.org/licenses/>.
*/
package ch.powerunit.extensions.matchers.provideprocessor.fields.lang;

import ch.powerunit.extensions.matchers.provideprocessor.fields.FieldDSLMethod;

/**
* @author borettim
*
*/
public interface BuilderShortCutDeclaration {
FieldDSLMethod withExplicitDeclarationJavadocAndImplementation(String declaration, String addToDescription,
String body);

FieldDSLMethod withSuffixDeclarationJavadocAndDefault(String declaration, String addToDescription,
String innerMatcher);
}
@@ -0,0 +1,30 @@
/**
* Powerunit - A JDK1.8 test framework
* Copyright (C) 2014 Mathieu Boretti.
*
* This file is part of Powerunit
*
* Powerunit is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Powerunit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Powerunit. If not, see <http://www.gnu.org/licenses/>.
*/
package ch.powerunit.extensions.matchers.provideprocessor.fields.lang;

import ch.powerunit.extensions.matchers.provideprocessor.fields.FieldDSLMethod;

/**
* @author borettim
*
*/
public interface BuilderShortCutJavadoc {
FieldDSLMethod withJavaDocAndDefault(String addToDescription, String innerMatcher);
}

0 comments on commit 38601f7

Please sign in to comment.