Skip to content

Commit

Permalink
Issue #151 - Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
boretti committed May 12, 2018
1 parent 3f31c40 commit 0635f71
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 3 deletions.
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(MATCHERS + ".is(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 Down
Expand Up @@ -70,7 +70,7 @@ public String getMatcherForField() {
}

public String getFieldCopyDefault(String lhs, String rhs) {
return lhs + "." + getFieldName() + "(" + MATCHERS + ".is(" + rhs + "." + getFieldAccessor() + "))";
return lhs + "." + getFieldName() + "((org.hamcrest.Matcher)" + MATCHERS + ".is((java.lang.Object)" + rhs + "." + getFieldAccessor() + "))";
}

public String getSameValueMatcherFor(String target) {
Expand Down
Expand Up @@ -139,7 +139,7 @@ public void testGetFieldCopy() {
DefaultFieldDescription undertest = new DefaultFieldDescription(() -> provideMatchersAnnotatedElementMirror,
new FieldDescriptionMirror(() -> provideMatchersAnnotatedElementMirror, "field", "boolean",
executableElement));
assertThat(undertest.getFieldCopy("a", "b")).is("a.field(org.hamcrest.Matchers.is(b.field()))");
assertThat(undertest.getFieldCopy("a", "b")).is("a.field((org.hamcrest.Matcher)org.hamcrest.Matchers.is((java.lang.Object)b.field()))");
}

@Test
Expand Down
@@ -0,0 +1,37 @@
/**
* 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.samples;

import ch.powerunit.extensions.matchers.ProvideMatchers;

/**
* @author borettim
*
*/
@ProvideMatchers()
public class PojoClass {
public Class clazzNoGeneric;

public Class<?> clazzWildcard;

public Class<? extends Number> clazzExtends;

public Class<? super String> clazzSuper;
}
@@ -0,0 +1,36 @@
/**
* 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.samples;

import ch.powerunit.Test;
import ch.powerunit.TestSuite;

public class PojoClassMatchersTest implements TestSuite {
@Test
public void testClass() {
PojoClass ut = new PojoClass();
ut.clazzNoGeneric = Object.class;
ut.clazzWildcard = String.class;
ut.clazzExtends = Integer.class;
ut.clazzSuper = Comparable.class;
assertThat(ut).is(PojoClassMatchers.pojoClassWith().clazzNoGeneric(Object.class).clazzWildcard(String.class)
.clazzExtends(Integer.class).clazzSuper(Comparable.class));
}
}

0 comments on commit 0635f71

Please sign in to comment.