Skip to content

Commit

Permalink
Merge 54bacd4 into e9ff2dd
Browse files Browse the repository at this point in the history
  • Loading branch information
boretti committed Sep 13, 2020
2 parents e9ff2dd + 54bacd4 commit 461fce0
Show file tree
Hide file tree
Showing 31 changed files with 408 additions and 79 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -41,8 +41,8 @@ Powerunit-extensions-matchers version | With | Version | Status
0.3.0 | hamcrest | 1.3 | :heavy_check_mark:
0.3.0 | hamcrest | 2.1+ | :heavy_check_mark:
0.3.0 | JDK | 1.8 | :heavy_check_mark:
0.3.0 | JDK | 9 | Compilation with source and target = 1.8 tested. Execution of generated matcher tested. The `@Generated` annotation may not be available OOTB.
0.3.0 | JDK | 10 | Compilation with source and target = 1.8 tested. Execution of generated matcher tested. The `@Generated` annotation may not be available OOTB.
0.3.0 | JDK | 9 | Compilation with source and target = 1.9 tested. Execution of generated matcher tested. The `@Generated` annotation may not be available OOTB.
0.3.0 | JDK | 10 | Compilation with source and target = 1.9 tested. Execution of generated matcher tested. The `@Generated` annotation may not be available OOTB.
0.3.0 | powerunit-extensions-matchers | 0.2.0 | :heavy_check_mark: Matchers generated with version 0.2.0 can be used from matcher of the version 0.3.0. The ignored fields and cycle detection is not propagated to the 0.2.0 matchers.

# Migration
Expand Down
3 changes: 3 additions & 0 deletions pom.xml
Expand Up @@ -276,6 +276,9 @@
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
</manifest>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
</configuration>
</plugin>
Expand Down
4 changes: 2 additions & 2 deletions src/it/beanmatchers-it-jdk9+-existing/pom.xml
Expand Up @@ -8,8 +8,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/beanmatchers-it-jdk9+-missing/pom.xml
Expand Up @@ -8,8 +8,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
Expand Up @@ -22,6 +22,7 @@
import static ch.powerunit.matchers.MatcherTester.matcher;
import static ch.powerunit.matchers.MatcherTester.value;

import ch.powerunit.Test;
import ch.powerunit.TestDelegate;
import ch.powerunit.TestSuite;
import ch.powerunit.matchers.MatcherTester;
Expand All @@ -44,8 +45,8 @@ public class Pojo1MatcherTest implements TestSuite {

//@formatter:off
@TestDelegate
public final MatcherTester<?> tester = testerOfMatcher(Pojo1Matchers.Pojo1MatcherImpl.class).with(
matcher((Pojo1Matchers.Pojo1MatcherImpl) Pojo1Matchers.pojo1WithSameValue(p1))
public final MatcherTester<?> tester = testerOfMatcher(Pojo1Matchers.<Void>pojo1MatcherClass()).with(
matcher(Pojo1Matchers.pojo1WithSameValue(p1))
.describedAs("an instance of ch.powerunit.extensions.matchers.samples.Pojo1 with\n[msg1 is \"x\"]\n[pojo2 null]\n")
.nullRejected("was null").
accepting(
Expand All @@ -55,7 +56,7 @@ public class Pojo1MatcherTest implements TestSuite {
value(new Pojo1(null,null)).withMessage("[msg1 was null]\n"),
value(new Pojo1("x",p2)).withMessage("[pojo2 was <Pojo2 [msg2=y, pojo1=null]>]\n"),
value(new Pojo1("y",null)).withMessage("[msg1 was \"y\"]\n")),
matcher((Pojo1Matchers.Pojo1MatcherImpl) Pojo1Matchers.pojo1WithSameValue(p12))
matcher(Pojo1Matchers.pojo1WithSameValue(p12))
.describedAs("an instance of ch.powerunit.extensions.matchers.samples.Pojo1 with\n[msg1 is \"1\"]\n[pojo2 an instance of ch.powerunit.extensions.matchers.samples.Pojo2 with\n[msg2 is \"2\"]\n[pojo1 an instance of ch.powerunit.extensions.matchers.samples.Pojo1 with\n[msg1 ANYTHING]\n[pojo2 ANYTHING]\n[object itself Same instance control only. A cycle has been detected.]\n]\n]\n")
.nullRejected("was null").
accepting(
Expand All @@ -66,5 +67,11 @@ public class Pojo1MatcherTest implements TestSuite {
value(new Pojo1("x",p2)).withMessage("[msg1 was \"x\"]\n[pojo2 [msg2 was \"y\"]\n[pojo1 was null]\n]\n"),
value(new Pojo1("y",null)).withMessage("[msg1 was \"y\"]\n[pojo2 was null]\n")));
//@formatter:off


@Test
public void testPostProcessor() {
assertThat(p12).is(Pojo1Matchers.pojo1WithSameValue(p1,Pojo1Matchers.PostProcessor.of(Pojo1Matchers.pojo1MatcherClass()).when((m,o)->true).then((m,o)->m.msg1("1").pojo2(anything()))));

}

}
4 changes: 2 additions & 2 deletions src/it/cycle-it-jdk9+/pom.xml
Expand Up @@ -9,8 +9,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/full-it-jdk9+/pom.xml
Expand Up @@ -9,8 +9,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/hamcrestdate-it-jdk9+-existing/pom.xml
Expand Up @@ -8,8 +8,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/hamcrestdate-it-jdk9+-missing/pom.xml
Expand Up @@ -8,8 +8,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/hamcrestutility-it-jdk9+-existing/pom.xml
Expand Up @@ -8,8 +8,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/hamcrestutility-it-jdk9+-missing/pom.xml
Expand Up @@ -8,8 +8,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/jackson-it-jdk9+-existing/pom.xml
Expand Up @@ -9,8 +9,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/multimodule-nogeneric-it-jdk9+/pom.xml
Expand Up @@ -8,8 +8,8 @@
<packaging>pom</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/provider-factory-disabled-it-jdk9+/pom.xml
Expand Up @@ -9,8 +9,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/provider-factory-enabled-it-jdk9+/pom.xml
Expand Up @@ -9,8 +9,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/simple-it-jdk9+-hamcrest21/pom.xml
Expand Up @@ -9,8 +9,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<surefire.version>2.22.2</surefire.version>
<powerunit.version>0.5.0</powerunit.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/simple-it-jdk9+-hamcrest22/pom.xml
Expand Up @@ -9,8 +9,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<surefire.version>2.22.2</surefire.version>
<powerunit.version>0.5.0</powerunit.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/simple-it-jdk9+-missinghamcrest/pom.xml
Expand Up @@ -9,8 +9,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/simple-it-jdk9+/pom.xml
Expand Up @@ -9,8 +9,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/spotify-it-jdk9+-existing/pom.xml
Expand Up @@ -8,8 +8,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/spotify-it-jdk9+-missing/pom.xml
Expand Up @@ -8,8 +8,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
4 changes: 2 additions & 2 deletions src/it/wrongannotation-it-jdk9+/pom.xml
Expand Up @@ -9,8 +9,8 @@
<packaging>jar</packaging>

<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<java.source.version>9</java.source.version>
<java.target.version>9</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hamcrest.version>1.3</hamcrest.version>
<surefire.version>2.22.2</surefire.version>
Expand Down
Expand Up @@ -31,7 +31,8 @@ public interface Matchable {
default long getCompatibility() {
// 0x01 : withSameValue also provides a version to ignore fields
// 0x02 : withSameValue also use a list of parent to detect cycle
return 0x03;
// 0x04 : withSameValue also support a post processor
return 0x07;
}

default String getMethodNameDSLWithSameValue() {
Expand All @@ -53,6 +54,10 @@ default boolean supportIgnore() {
default boolean supportCycleDetectionV1() {
return (getCompatibility() & 0x02) == 0x02;
}

default boolean supportSameValueWithParentPostPrecessor() {
return (getCompatibility() & 0x04) == 0x04;
}

static Matchable of(String fullName, String methodName, String interfaceName, boolean hasWithSameValue,
long compatibility) {
Expand Down
Expand Up @@ -56,6 +56,9 @@ public class ProvidesMatchersAnnotatedElementMirror extends ProvidesMatchersAnno
private static final String MATCHER_FORMAT = RessourceLoaderHelper
.loadRessource(ProvidesMatchersAnnotatedElementMirror.class, "Matchers.txt");

private static final String POSTPROCESSOR_FORMAT = addPrefix(" ",
RessourceLoaderHelper.loadRessource(ProvidesMatchersAnnotatedElementMirror.class, "PostProcessor.txt"));

private static final ListJoining<DSLMethod> JOIN_DSL_METHOD = ListJoining
.joinWithMapperAndDelimiter(m -> addPrefix(" ", m.asStaticImplementation()), "\n");

Expand All @@ -65,9 +68,9 @@ private static Supplier<Collection<DSLMethod>> asCollection(Supplier<DSLMethod>

public ProvidesMatchersAnnotatedElementMirror(TypeElement typeElement, RoundMirror roundMirror) {
super(typeElement, roundMirror);
List<Supplier<Collection<DSLMethod>>> tmp = new ArrayList<>(
Arrays.asList(asCollection(this::generateDefaultDSLStarter),
asCollection(this::generateDefaultForChainingDSLStarter)));
List<Supplier<Collection<DSLMethod>>> tmp = new ArrayList<>(Arrays.asList(
asCollection(this::generateDefaultDSLStarter), asCollection(this::generateDefaultForChainingDSLStarter),
asCollection(this::generateMatcherClassMethod)));
if (hasSuperClass()) {
tmp.add(asCollection(this::generateParentDSLStarter));
tmp.add(() -> ProvidesMatchersWithSameValueHelper.generateParentValueDSLStarter(this));
Expand Down Expand Up @@ -96,7 +99,8 @@ public Collection<DSLMethod> process() {
getFullyQualifiedNameOfClassAnnotated(),
generateGeneratedAnnotation(ProvidesMatchersAnnotationsProcessor.class, comments()),
getSimpleNameOfGeneratedClass(), generateMatchers(), generatePublicInterface(),
generatePrivateImplementation(), JOIN_DSL_METHOD.asString(tmp), generateMetadata());
generatePrivateImplementation(), JOIN_DSL_METHOD.asString(tmp), POSTPROCESSOR_FORMAT,
generateMetadata());
output.flush();
return tmp;
}, e -> traceErrorAndDump(this, e, te));
Expand Down Expand Up @@ -177,4 +181,13 @@ public DSLMethod generateParentInSameRoundWithChaningDSLStarter() {
}).orElse(null);
}

public DSLMethod generateMatcherClassMethod() {
return of(getFullGenericParent()+" Class<" + getFullyQualifiedNameOfGeneratedClass() + "."
+ getSimpleNameOfGeneratedInterfaceMatcherWithGenericParent() + "> "
+ getMethodShortClassName() + "MatcherClass").withoutArgument()
.withImplementation("return (Class)" + getSimpleNameOfGeneratedInterfaceMatcher() + ".class;")
.withJavadoc(
"/**\n * Helper method to retrieve the Class of the matcher interface.\n * @return the class.\n */\n");
}

}
Expand Up @@ -19,6 +19,9 @@
*/
package ch.powerunit.extensions.matchers.provideprocessor;

import static ch.powerunit.extensions.matchers.common.CommonUtils.addPrefix;
import static java.util.Arrays.asList;
import static java.util.Collections.unmodifiableList;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;
Expand All @@ -29,6 +32,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Stream;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.ProcessingEnvironment;
Expand All @@ -44,6 +48,7 @@
import ch.powerunit.extensions.matchers.common.CommonUtils;
import ch.powerunit.extensions.matchers.common.FactoryHelper;
import ch.powerunit.extensions.matchers.common.FileObjectHelper;
import ch.powerunit.extensions.matchers.common.RessourceLoaderHelper;

/**
* @author borettim
Expand All @@ -62,6 +67,10 @@ public class ProvidesMatchersAnnotationsProcessor extends AbstractProcessor {

private List<Element> allSourceElements = new ArrayList<>();

private static final List<String> POSTPROCESSOR_FORMAT = unmodifiableList(asList(addPrefix(" ",
RessourceLoaderHelper.loadRessource(ProvidesMatchersAnnotatedElementMirror.class, "PostProcessor.txt"))
.split("\n")));

@Override
public synchronized void init(ProcessingEnvironment processingEnv) {
super.init(processingEnv);
Expand Down Expand Up @@ -106,7 +115,7 @@ private void processFactory(String factory) {
jfo -> new PrintWriter(jfo.openWriter()),
wjfo -> FactoryHelper.generateFactoryClass(wjfo, ProvidesMatchersAnnotationsProcessor.class,
factory.replaceAll("\\.[^.]+$", ""), factory.replaceAll("^([^.]+\\.)*", ""),
() -> factories.stream()),
() -> Stream.concat(factories.stream(), POSTPROCESSOR_FORMAT.stream())),
e -> processingEnv.getMessager().printMessage(Kind.ERROR,
"Unable to create the file containing the target class `" + factory + "`, because of "
+ e.getMessage()));
Expand Down

0 comments on commit 461fce0

Please sign in to comment.