diff --git a/README.md b/README.md
index 8aae91f..f0ceaef 100644
--- a/README.md
+++ b/README.md
@@ -5,6 +5,7 @@
[![release_on_master](https://github.com/toolisticon/FluApiGen/actions/workflows/release.yml/badge.svg?branch=master)](https://github.com/toolisticon/FluApiGen/actions/workflows/release.yml)
[![codecov](https://codecov.io/gh/toolisticon/FluApiGen/branch/develop/graph/badge.svg?token=FlcugFxC64)](https://codecov.io/gh/toolisticon/FluApiGen)
+
Implementing and especially maintaining of fluent and immutable apis is one of a most annoying and difficult tasks to do in java developing.
You usually have to implement a lot of boilerplate code that is only needed to handle and clone the fluent apis internal state.
diff --git a/fluapigen-api/pom.xml b/fluapigen-api/pom.xml
index b698cf7..d6f45df 100644
--- a/fluapigen-api/pom.xml
+++ b/fluapigen-api/pom.xml
@@ -9,7 +9,7 @@
io.toolisticon.fluapigen
fluapigen
- 0.8.3
+ 0.9.0
fluapigen-api
diff --git a/fluapigen-example/pom.xml b/fluapigen-example/pom.xml
index 96aa5d4..71dbfb9 100644
--- a/fluapigen-example/pom.xml
+++ b/fluapigen-example/pom.xml
@@ -9,7 +9,7 @@
io.toolisticon.fluapigen
fluapigen
- 0.8.3
+ 0.9.0
fluapigen-example
diff --git a/fluapigen-integrationTest/pom.xml b/fluapigen-integrationTest/pom.xml
index ef28916..43a245e 100644
--- a/fluapigen-integrationTest/pom.xml
+++ b/fluapigen-integrationTest/pom.xml
@@ -9,7 +9,7 @@
io.toolisticon.fluapigen
fluapigen
- 0.8.3
+ 0.9.0
fluapigen-integrationTest
diff --git a/fluapigen-integrationTest/src/main/java/io/toolisticon/fluapigen/integrationtest/ValidatorExample.java b/fluapigen-integrationTest/src/main/java/io/toolisticon/fluapigen/integrationtest/ValidatorExample.java
index af67139..24f5e28 100644
--- a/fluapigen-integrationTest/src/main/java/io/toolisticon/fluapigen/integrationtest/ValidatorExample.java
+++ b/fluapigen-integrationTest/src/main/java/io/toolisticon/fluapigen/integrationtest/ValidatorExample.java
@@ -10,6 +10,7 @@
import io.toolisticon.fluapigen.validation.api.Matches;
import io.toolisticon.fluapigen.validation.api.MaxLength;
import io.toolisticon.fluapigen.validation.api.NotNull;
+import io.toolisticon.fluapigen.validation.api.Nullable;
@FluentApi("ValidatorExampleStarter")
public class ValidatorExample {
@@ -26,10 +27,18 @@ interface MyBackingBean {
// Fluent Api interfaces
@FluentApiInterface(MyBackingBean.class)
@FluentApiRoot
+ @Nullable
public interface MyRootInterface {
MyRootInterface setName(@NotNull @MaxLength(8) @Matches("aaa.*") @FluentApiBackingBeanMapping("name") String name);
+ @NotNull
+ MyRootInterface setNameWithNullableOnParameter(@Nullable @MaxLength(8) @Matches("aaa.*") @FluentApiBackingBeanMapping("name") String name);
+
+ @Nullable
+ MyRootInterface setNameWithNullableOnMethod(@NotNull @MaxLength(8) @Matches("aaa.*") @FluentApiBackingBeanMapping("name") String name);
+
+
@FluentApiCommand(MyCommand.class)
void myCommand();
diff --git a/fluapigen-integrationTest/src/test/java/io/toolisticon/fluapigen/integrationtest/ValidatorExampleTest.java b/fluapigen-integrationTest/src/test/java/io/toolisticon/fluapigen/integrationtest/ValidatorExampleTest.java
index 9c4dd9e..5bf81b8 100644
--- a/fluapigen-integrationTest/src/test/java/io/toolisticon/fluapigen/integrationtest/ValidatorExampleTest.java
+++ b/fluapigen-integrationTest/src/test/java/io/toolisticon/fluapigen/integrationtest/ValidatorExampleTest.java
@@ -1,5 +1,6 @@
package io.toolisticon.fluapigen.integrationtest;
+import io.toolisticon.fluapigen.validation.api.ValidatorException;
import org.junit.Test;
public class ValidatorExampleTest {
@@ -15,7 +16,14 @@ public void testValidator_failingValidation() {
public void testValidator() {
ValidatorExampleStarter.setName("aaaBDSXS").myCommand();
+ ValidatorExampleStarter.setNameWithNullableOnParameter(null).myCommand();
+ ValidatorExampleStarter.setNameWithNullableOnMethod("aaaBDSXS").myCommand();
}
+ @Test(expected = ValidatorException.class)
+ public void testOverruledNotNullAtParameter() {
+ ValidatorExampleStarter.setNameWithNullableOnMethod(null).myCommand();
+ }
+
}
diff --git a/fluapigen-processor/pom.xml b/fluapigen-processor/pom.xml
index 5b7ce06..3fe57f1 100644
--- a/fluapigen-processor/pom.xml
+++ b/fluapigen-processor/pom.xml
@@ -9,7 +9,7 @@
io.toolisticon.fluapigen
fluapigen
- 0.8.3
+ 0.9.0
fluapigen-processor
diff --git a/fluapigen-processor/src/main/java/io/toolisticon/fluapigen/processor/ModelInterfaceMethod.java b/fluapigen-processor/src/main/java/io/toolisticon/fluapigen/processor/ModelInterfaceMethod.java
index 440634e..d1b7991 100644
--- a/fluapigen-processor/src/main/java/io/toolisticon/fluapigen/processor/ModelInterfaceMethod.java
+++ b/fluapigen-processor/src/main/java/io/toolisticon/fluapigen/processor/ModelInterfaceMethod.java
@@ -6,6 +6,7 @@
import io.toolisticon.aptk.tools.wrapper.VariableElementWrapper;
import io.toolisticon.fluapigen.api.FluentApiBackingBeanMapping;
import io.toolisticon.fluapigen.api.FluentApiCommand;
+import io.toolisticon.fluapigen.api.FluentApiInlineBackingBeanMapping;
import io.toolisticon.fluapigen.api.FluentApiParentBackingBeanMapping;
import io.toolisticon.fluapigen.api.TargetBackingBean;
@@ -288,6 +289,21 @@ public boolean hasInlineBackingBeanMapping() {
public boolean validate() {
boolean outcome = true;
+
+ // check inline backing bean
+ if (this.inlineBackingBeanMapping != null) {
+
+ // validate
+ this.inlineBackingBeanMapping.validate();
+
+ if (!getInlineBackingBean().isPresent()) {
+ this.inlineBackingBeanMapping.compilerMessage().asError().write(FluentApiProcessorCompilerMessages.ERROR_INLINE_BB_MAPPING_COULDNT_BE_RESOLVED);
+ return false;
+ }
+
+
+ }
+
// check parameters
// -> names must match an existing target field
@@ -325,20 +341,6 @@ public boolean validate() {
}
- // check inline backing bean
- if (this.inlineBackingBeanMapping != null) {
-
- // validate
- this.inlineBackingBeanMapping.validate();
-
- if (!getInlineBackingBean().isPresent()) {
- this.inlineBackingBeanMapping.compilerMessage().asError().write(FluentApiProcessorCompilerMessages.ERROR_INLINE_BB_MAPPING_COULDNT_BE_RESOLVED);
- outcome = false;
- }
-
-
- }
-
// must check command case
if (isCommandMethod()) {
diff --git a/fluapigen-processor/src/main/java/io/toolisticon/fluapigen/processor/ModelInterfaceMethodParameter.java b/fluapigen-processor/src/main/java/io/toolisticon/fluapigen/processor/ModelInterfaceMethodParameter.java
index 9818b4c..97eaff4 100644
--- a/fluapigen-processor/src/main/java/io/toolisticon/fluapigen/processor/ModelInterfaceMethodParameter.java
+++ b/fluapigen-processor/src/main/java/io/toolisticon/fluapigen/processor/ModelInterfaceMethodParameter.java
@@ -3,12 +3,16 @@
import io.toolisticon.aptk.compilermessage.api.DeclareCompilerMessage;
import io.toolisticon.aptk.tools.InterfaceUtils;
import io.toolisticon.aptk.tools.TypeMirrorWrapper;
+import io.toolisticon.aptk.tools.wrapper.ElementWrapper;
import io.toolisticon.aptk.tools.wrapper.VariableElementWrapper;
import io.toolisticon.fluapigen.api.FluentApiBackingBeanMapping;
import io.toolisticon.fluapigen.api.FluentApiConverter;
+import io.toolisticon.fluapigen.api.FluentApiInlineBackingBeanMapping;
import io.toolisticon.fluapigen.api.TargetBackingBean;
import io.toolisticon.fluapigen.validation.api.FluentApiValidator;
+import javax.lang.model.element.Element;
+import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
@@ -83,7 +87,29 @@ public boolean hasValidators() {
}
public List getValidators() {
- return this.parameterElement.getAnnotations().stream().filter(e -> e.asElement().hasAnnotation(FluentApiValidator.class)).map(e -> new ModelValidator(this.parameterElement, e)).collect(Collectors.toList());
+
+ // First get all enclosing elements - order is from element to top level parent
+ List> enclosingElements = this.parameterElement.getAllEnclosingElements(true);
+
+ // now map it to ModelValidators
+ List allValidatorsWithoutOverwrites = enclosingElements.stream()
+ .flatMap(
+ e -> e.getAnnotations().stream()
+ .filter(f -> f.asElement().hasAnnotation(FluentApiValidator.class))
+ .map(f -> new ModelValidator(this.parameterElement, f))
+ ).collect(Collectors.toList());
+
+ // Must remove overwritten validators - add them one by one from lowest to highest level and check if the element to add is already overruled by thos in list.
+ List result = new ArrayList();
+
+ for (ModelValidator nextValidator : allValidatorsWithoutOverwrites) {
+ if (!nextValidator.isOverruledBy(result)) {
+ result.add(nextValidator);
+ }
+ }
+
+ return result;
+
}
public String getParameterName() {
@@ -209,6 +235,7 @@ private void validateConverter(ModelBackingBeanField backBeanField) {
@DeclareCompilerMessage(code = "001", enumValueName = "BB_MAPPING_ANNOTATION_MUST_BE_PRESENT", message = "${0} annotation must be present on parameter", processorClass = FluentApiProcessor.class)
@DeclareCompilerMessage(code = "002", enumValueName = "PARAMETER_AND_MAPPED_BB_FIELD_MUST_HAVE_SAME_TYPE", message = "Parameter type (${0}) must match backing bean field type (${1})", processorClass = FluentApiProcessor.class)
@DeclareCompilerMessage(code = "003", enumValueName = "BB_MAPPING_COULDNT_BE_RESOLVED", message = "Field ${0} doesn't exist in mapped backing bean ${1}. It must be one of: [${2}]", processorClass = FluentApiProcessor.class)
+ @DeclareCompilerMessage(code = "004", enumValueName = "INLINE_BB_MAPPING_ANNOTATION_IS_MISSING_ON_METHOD", message = "Parameter ${0} has target INLINE but no ${1} annotation is present on method", processorClass = FluentApiProcessor.class)
public boolean validate() {
// check validators
@@ -225,6 +252,12 @@ public boolean validate() {
return false;
}
+ // must check if Inline annotation is placed on method for INLINE target
+ if (fluentApiBackingBeanMapping.target() == TargetBackingBean.INLINE && !modelInterfaceMethod.getExecutableElement().hasAnnotation(FluentApiInlineBackingBeanMapping.class)) {
+ parameterElement.compilerMessage().asError().write(FluentApiProcessorCompilerMessages.INLINE_BB_MAPPING_ANNOTATION_IS_MISSING_ON_METHOD, parameterElement.getSimpleName(), FluentApiInlineBackingBeanMapping.class.getSimpleName());
+ return false;
+ }
+
if (!getBackingBeanField().isPresent()) {
Optional referencedBackingBean = fluentApiBackingBeanMapping.target() == TargetBackingBean.THIS ? Optional.of(backingBeanModel) : modelInterfaceMethod.getNextBackingBean();
diff --git a/fluapigen-processor/src/main/java/io/toolisticon/fluapigen/processor/ModelValidator.java b/fluapigen-processor/src/main/java/io/toolisticon/fluapigen/processor/ModelValidator.java
index 4145fe3..87d5ea6 100644
--- a/fluapigen-processor/src/main/java/io/toolisticon/fluapigen/processor/ModelValidator.java
+++ b/fluapigen-processor/src/main/java/io/toolisticon/fluapigen/processor/ModelValidator.java
@@ -11,6 +11,7 @@
import javax.lang.model.element.Modifier;
import java.util.Arrays;
+import java.util.List;
import java.util.stream.Collectors;
public class ModelValidator {
@@ -28,6 +29,23 @@ FluentApiValidatorWrapper getValidatorAnnotation() {
return FluentApiValidatorWrapper.wrap(this.validatorAnnotation.asElement().unwrap());
}
+ // visible for testing
+ AnnotationMirrorWrapper getAnnotationMirrorWrapper() {
+ return validatorAnnotation;
+ }
+
+ public boolean isOverruledBy (List existingLowestLevelValidators) {
+ for (ModelValidator existinModelValidator : existingLowestLevelValidators) {
+
+ for (String overruledAnnotation : existinModelValidator.getValidatorAnnotation().overwritesAsFqn()) {
+ if (overruledAnnotation.equals(validatorAnnotation.asTypeMirror().getQualifiedName())) {
+ return true;
+ }
+ }
+
+ }
+ return false;
+ }
@DeclareCompilerMessage(code = "752", enumValueName = "ERROR_BROKEN_VALIDATOR_ATTRIBUTE_NAME_MISMATCH", message = "The configured validator ${0} seems to have a broken annotation attribute to validator constructor parameter mapping. Attributes names ${1} doesn't exist. Please fix validator implementation or don't use it.", processorClass = FluentApiProcessor.class)
@DeclareCompilerMessage(code = "753", enumValueName = "ERROR_BROKEN_VALIDATOR_CONSTRUCTOR_PARAMETER_MAPPING", message = "The configured validator ${0} seems to have a broken annotation attribute to validator constructor parameter mapping. Please fix validator implementation or don't use it.", processorClass = FluentApiProcessor.class)
diff --git a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/BBNotFoundExceptionTest.java b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/BBNotFoundExceptionTest.java
index deb87a0..1eba421 100644
--- a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/BBNotFoundExceptionTest.java
+++ b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/BBNotFoundExceptionTest.java
@@ -3,7 +3,7 @@
import io.toolisticon.aptk.common.ToolingProvider;
import io.toolisticon.aptk.tools.MessagerUtils;
import io.toolisticon.aptk.tools.wrapper.ExecutableElementWrapper;
-import io.toolisticon.cute.CompileTestBuilder;
+import io.toolisticon.cute.Cute;
import io.toolisticon.cute.PassIn;
import org.junit.Before;
import org.junit.Test;
@@ -29,7 +29,10 @@ interface ExceptionTest {
@Test
public void testWriteCompilerMessage() {
- CompileTestBuilder.unitTest().defineTestWithPassedInElement(ExceptionTest.class, (processingEnvironment, element) -> {
+ Cute.unitTest()
+ .when()
+ .passInElement().fromClass(ExceptionTest.class)
+ .intoUnitTest((processingEnvironment, element) -> {
try {
@@ -43,8 +46,10 @@ public void testWriteCompilerMessage() {
ToolingProvider.clearTooling();
}
})
- .compilationShouldFail()
- .expectErrorMessageThatContains(FluentApiProcessorCompilerMessages.ERROR_CANNOT_FIND_NEXT_BACKING_BEAN.getCode(), "String method()").executeTest();
+ .thenExpectThat()
+ .compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_CANNOT_FIND_NEXT_BACKING_BEAN.getCode(), "String method()")
+ .executeTest();
}
diff --git a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiBackingBeanWrapperCodeTest.java b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiBackingBeanWrapperCodeTest.java
index 036bc7d..3acbc9f 100644
--- a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiBackingBeanWrapperCodeTest.java
+++ b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiBackingBeanWrapperCodeTest.java
@@ -3,7 +3,8 @@
import io.toolisticon.aptk.cute.APTKUnitTestProcessor;
import io.toolisticon.aptk.tools.MessagerUtils;
import io.toolisticon.aptk.tools.corematcher.CoreMatcherValidationMessages;
-import io.toolisticon.cute.CompileTestBuilder;
+import io.toolisticon.cute.Cute;
+import io.toolisticon.cute.CuteApi;
import io.toolisticon.cute.PassIn;
import io.toolisticon.fluapigen.api.FluentApi;
import io.toolisticon.fluapigen.api.FluentApiBackingBean;
@@ -19,14 +20,13 @@
*/
public class CustomFluentApiBackingBeanWrapperCodeTest {
- CompileTestBuilder.UnitTestBuilder unitTestBuilder;
+ CuteApi.UnitTestRootInterface unitTestBuilder;
@Before
public void init() {
MessagerUtils.setPrintMessageCodes(true);
- unitTestBuilder = CompileTestBuilder
- .unitTest();
+ unitTestBuilder = Cute.unitTest();
}
@FluentApi("MyTestApi")
@@ -44,15 +44,17 @@ private interface BackingBean {
@Test
public void validationTest_NoRoot() {
- unitTestBuilder.defineTestWithPassedInElement(NotAccessibleTestApi.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.when()
+ .passInElement().fromClass(NotAccessibleTestApi.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
MatcherAssert.assertThat("should return false", !CustomFluentApiBackingBeanWrapperCode.validate(FluentApiBackingBeanWrapper.wrap(typeElement)));
}
})
- .compilationShouldFail()
- .expectErrorMessage().thatContains(CoreMatcherValidationMessages.BY_MODIFIER.getCode())
+ .thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(CoreMatcherValidationMessages.BY_MODIFIER.getCode())
.executeTest();
@@ -72,18 +74,19 @@ static class BackingBean {
@Test
public void validationTest_PlacedOnClass() {
- unitTestBuilder.defineTestWithPassedInElement(PlacedOnClassTestApi.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.when()
+ .passInElement().fromClass(PlacedOnClassTestApi.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
MatcherAssert.assertThat("should return false", !CustomFluentApiBackingBeanWrapperCode.validate(FluentApiBackingBeanWrapper.wrap(typeElement)));
}
})
- .compilationShouldFail()
- .expectErrorMessage().thatContains(CoreMatcherValidationMessages.IS_INTERFACE.getCode())
+ .thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(CoreMatcherValidationMessages.IS_INTERFACE.getCode())
.executeTest();
-
}
}
\ No newline at end of file
diff --git a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiCommandWrapperCodeTest.java b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiCommandWrapperCodeTest.java
index 27b17a5..689aa3e 100644
--- a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiCommandWrapperCodeTest.java
+++ b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiCommandWrapperCodeTest.java
@@ -4,7 +4,8 @@
import io.toolisticon.aptk.cute.APTKUnitTestProcessor;
import io.toolisticon.aptk.tools.MessagerUtils;
import io.toolisticon.aptk.tools.corematcher.CoreMatcherValidationMessages;
-import io.toolisticon.cute.CompileTestBuilder;
+import io.toolisticon.cute.Cute;
+import io.toolisticon.cute.CuteApi;
import io.toolisticon.cute.PassIn;
import io.toolisticon.fluapigen.api.FluentApi;
import io.toolisticon.fluapigen.api.FluentApiBackingBean;
@@ -25,13 +26,13 @@
*/
public class CustomFluentApiCommandWrapperCodeTest {
- CompileTestBuilder.UnitTestBuilder unitTestBuilder;
+ CuteApi.UnitTestRootInterface unitTestBuilder;
@Before
public void init() {
MessagerUtils.setPrintMessageCodes(true);
- unitTestBuilder = CompileTestBuilder
+ unitTestBuilder = Cute
.unitTest();
}
@@ -65,14 +66,15 @@ static void doSomethingBeautiful(BackingBean backingBean) {
@Test
public void validationTest_HappyPath() {
- unitTestBuilder.defineTestWithPassedInElement(HappyPathTestApi.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.when().passInElement().fromClass(HappyPathTestApi.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
-
MatcherAssert.assertThat("should return true", CustomFluentApiCommandWrapperCode.validate(FluentApiCommandWrapper.wrap(typeElement)));
}
})
- .compilationShouldSucceed()
+ .thenExpectThat()
+ .compilationSucceeds()
.executeTest();
@@ -80,14 +82,15 @@ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElemen
@Test
public void test_getCommandMethodName_onCommandClass() {
- unitTestBuilder.defineTestWithPassedInElement(HappyPathTestApi.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.when().passInElement().fromClass(HappyPathTestApi.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
MatcherAssert.assertThat(CustomFluentApiCommandWrapperCode.getCommandMethodName(FluentApiCommandWrapper.wrap(typeElement)), Matchers.is("doSomethingBeautiful"));
}
})
- .compilationShouldSucceed()
+ .thenExpectThat().compilationSucceeds()
.executeTest();
}
@@ -121,14 +124,17 @@ static void doSomethingBeautiful(BackingBean backingBean) {
@Test
public void test_getCommandMethodName_onFluentInterfaceMethods() {
- unitTestBuilder.defineTestWithPassedInElement(OnFluentApiMethodTestApi.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.when()
+ .passInElement().fromClass(OnFluentApiMethodTestApi.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, ExecutableElement typeElement) {
MatcherAssert.assertThat(CustomFluentApiCommandWrapperCode.getCommandMethodName(FluentApiCommandWrapper.wrap(typeElement)), Matchers.is("doSomethingBeautiful"));
}
})
- .compilationShouldSucceed()
+ .thenExpectThat()
+ .compilationSucceeds()
.executeTest();
}
@@ -163,7 +169,8 @@ static void doSomethingBeautiful(BackingBean backingBean) {
@Test
public void test_validate_onMethodInClass() {
- unitTestBuilder.defineTestWithPassedInElement(OnFluentApiMethodTestApi_InClass_error.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.when().passInElement().fromClass(OnFluentApiMethodTestApi_InClass_error.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, ExecutableElement element) {
@@ -178,8 +185,8 @@ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, Executable
}
}
})
- .compilationShouldFail()
- .expectErrorMessageThatContains(CoreMatcherValidationMessages.IS_INTERFACE.getCode())
+ .thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(CoreMatcherValidationMessages.IS_INTERFACE.getCode())
.executeTest();
}
@@ -217,7 +224,8 @@ static void secondMethod(BackingBean backingBean) {
@Test
public void test_validate_twoMethodsInCommandClass() {
- unitTestBuilder.defineTestWithPassedInElement(MultipleMethodsInCommandClass.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.when().passInElement().fromClass(MultipleMethodsInCommandClass.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
@@ -233,8 +241,8 @@ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElemen
}
})
- .compilationShouldFail()
- .expectErrorMessageThatContains(FluentApiProcessorCompilerMessages.ERROR_COMMAND_CLASS_MUST_DECLARE_EXACTLY_ONE_STATIC_METHOD.getCode())
+ .thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_COMMAND_CLASS_MUST_DECLARE_EXACTLY_ONE_STATIC_METHOD.getCode())
.executeTest();
}
@@ -272,7 +280,8 @@ static void secondMethod(BackingBean backingBean) {
@Test
public void test_validate_noMethodInCommandClass() {
- unitTestBuilder.defineTestWithPassedInElement(NoMethodInCommandClass.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.when().passInElement().fromClass(NoMethodInCommandClass.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
@@ -288,8 +297,8 @@ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElemen
}
})
- .compilationShouldFail()
- .expectErrorMessageThatContains(FluentApiProcessorCompilerMessages.ERROR_COMMAND_CLASS_MUST_DECLARE_EXACTLY_ONE_STATIC_METHOD.getCode())
+ .thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_COMMAND_CLASS_MUST_DECLARE_EXACTLY_ONE_STATIC_METHOD.getCode())
.executeTest();
}
diff --git a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiInterfaceWrapperCodeTest.java b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiInterfaceWrapperCodeTest.java
index b94b771..2ab3423 100644
--- a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiInterfaceWrapperCodeTest.java
+++ b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiInterfaceWrapperCodeTest.java
@@ -3,7 +3,8 @@
import io.toolisticon.aptk.cute.APTKUnitTestProcessor;
import io.toolisticon.aptk.tools.MessagerUtils;
import io.toolisticon.aptk.tools.corematcher.CoreMatcherValidationMessages;
-import io.toolisticon.cute.CompileTestBuilder;
+import io.toolisticon.cute.Cute;
+import io.toolisticon.cute.CuteApi;
import io.toolisticon.cute.PassIn;
import io.toolisticon.fluapigen.api.FluentApi;
import io.toolisticon.fluapigen.api.FluentApiBackingBean;
@@ -20,13 +21,13 @@
*/
public class CustomFluentApiInterfaceWrapperCodeTest {
- CompileTestBuilder.UnitTestBuilder unitTestBuilder;
+ CuteApi.UnitTestRootInterface unitTestBuilder;
@Before
public void init() {
MessagerUtils.setPrintMessageCodes(true);
- unitTestBuilder = CompileTestBuilder
+ unitTestBuilder = Cute
.unitTest();
}
@@ -49,15 +50,16 @@ private interface FluentInterface {
@Test
public void validationTest_NoRoot() {
- unitTestBuilder.defineTestWithPassedInElement(NotAccessibleTestApi.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.when().passInElement().fromClass(NotAccessibleTestApi.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
MatcherAssert.assertThat("should return false", !CustomFluentApiInterfaceWrapperCode.validate(FluentApiInterfaceWrapper.wrap(typeElement)));
}
})
- .compilationShouldFail()
- .expectErrorMessage().thatContains(CoreMatcherValidationMessages.BY_MODIFIER.getCode())
+ .thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(CoreMatcherValidationMessages.BY_MODIFIER.getCode())
.executeTest();
@@ -82,21 +84,19 @@ static class FluentInterface {
@Test
public void validationTest_PlacedOnClass() {
- unitTestBuilder.defineTestWithPassedInElement(PlacedOnClassTestApi.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.when().passInElement().fromClass(PlacedOnClassTestApi.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
MatcherAssert.assertThat("should return false", !CustomFluentApiInterfaceWrapperCode.validate(FluentApiInterfaceWrapper.wrap(typeElement)));
}
})
- .compilationShouldFail()
- .expectErrorMessage().thatContains(CoreMatcherValidationMessages.IS_INTERFACE.getCode())
+ .thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(CoreMatcherValidationMessages.IS_INTERFACE.getCode())
.executeTest();
-
}
-
-
}
\ No newline at end of file
diff --git a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiWrapperCodeTest.java b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiWrapperCodeTest.java
index 8f40959..6539b6f 100644
--- a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiWrapperCodeTest.java
+++ b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/CustomFluentApiWrapperCodeTest.java
@@ -2,7 +2,8 @@
import io.toolisticon.aptk.cute.APTKUnitTestProcessor;
import io.toolisticon.aptk.tools.MessagerUtils;
-import io.toolisticon.cute.CompileTestBuilder;
+import io.toolisticon.cute.Cute;
+import io.toolisticon.cute.CuteApi;
import io.toolisticon.cute.PassIn;
import io.toolisticon.fluapigen.api.FluentApi;
import io.toolisticon.fluapigen.api.FluentApiBackingBean;
@@ -23,13 +24,13 @@
*/
public class CustomFluentApiWrapperCodeTest {
- CompileTestBuilder.UnitTestBuilder unitTestBuilder;
+ CuteApi.UnitTestRootInterface unitTestBuilder;
@Before
public void init() {
MessagerUtils.setPrintMessageCodes(true);
- unitTestBuilder = CompileTestBuilder
+ unitTestBuilder = Cute
.unitTest();
}
@@ -52,16 +53,17 @@ interface FluentInterface {
@Test
public void validationTest_NoRoot() {
- unitTestBuilder.defineTestWithPassedInElement(NoRootTestApi.class, new APTKUnitTestProcessor() {
- @Override
- public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
+ unitTestBuilder.when().passInElement().fromClass(NoRootTestApi.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
+ @Override
+ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
- MatcherAssert.assertThat("should return false",!CustomFluentApiWrapperCode.validate(FluentApiWrapper.wrap(typeElement)));
- }
- })
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_FLUENTAPI_NO_ROOT_INTERFACE.getCode())
- .executeTest();
+ MatcherAssert.assertThat("should return false", !CustomFluentApiWrapperCode.validate(FluentApiWrapper.wrap(typeElement)));
+ }
+ })
+ .thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_FLUENTAPI_NO_ROOT_INTERFACE.getCode())
+ .executeTest();
}
@@ -92,15 +94,16 @@ interface FluentInterface2 {
@Test
public void validationTest_MultipleRoot() {
- unitTestBuilder.defineTestWithPassedInElement(MultipleRootTestApi.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.when().passInElement().fromClass(MultipleRootTestApi.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
- MatcherAssert.assertThat("should return false",!CustomFluentApiWrapperCode.validate(FluentApiWrapper.wrap(typeElement)));
+ MatcherAssert.assertThat("should return false", !CustomFluentApiWrapperCode.validate(FluentApiWrapper.wrap(typeElement)));
}
})
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_FLUENTAPI_MULTIPLE_ROOT_INTERFACES.getCode())
+ .thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_FLUENTAPI_MULTIPLE_ROOT_INTERFACES.getCode())
.executeTest();
@@ -132,15 +135,16 @@ interface FluentInterface2 {
@Test
public void validationTest_EmptyStarterName() {
- unitTestBuilder.defineTestWithPassedInElement(EmptyStarterNameTestApi.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.when().passInElement().fromClass(EmptyStarterNameTestApi.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
- MatcherAssert.assertThat("should return false",!CustomFluentApiWrapperCode.validate(FluentApiWrapper.wrap(typeElement)));
+ MatcherAssert.assertThat("should return false", !CustomFluentApiWrapperCode.validate(FluentApiWrapper.wrap(typeElement)));
}
})
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_FLUENTAPI_CLASSNAME_MUST_NOT_BE_EMPTY.getCode())
+ .thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_FLUENTAPI_CLASSNAME_MUST_NOT_BE_EMPTY.getCode())
.executeTest();
@@ -172,15 +176,16 @@ interface FluentInterface2 {
@Test
public void validationTest_InvalidStarterName() {
- unitTestBuilder.defineTestWithPassedInElement(InvalidStarterNameTestApi.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.when().passInElement().fromClass(InvalidStarterNameTestApi.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
- MatcherAssert.assertThat("should return false",!CustomFluentApiWrapperCode.validate(FluentApiWrapper.wrap(typeElement)));
+ MatcherAssert.assertThat("should return false", !CustomFluentApiWrapperCode.validate(FluentApiWrapper.wrap(typeElement)));
}
})
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_FLUENTAPI_CLASSNAME_MUST_BE_VALID.getCode())
+ .thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_FLUENTAPI_CLASSNAME_MUST_BE_VALID.getCode())
.executeTest();
@@ -189,14 +194,15 @@ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElemen
@Test
public void validationTest_HappyPath() {
- unitTestBuilder.defineTestWithPassedInElement(ValidTestApi.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.when().passInElement().fromClass(ValidTestApi.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
- MatcherAssert.assertThat("should return true",CustomFluentApiWrapperCode.validate(FluentApiWrapper.wrap(typeElement)));
+ MatcherAssert.assertThat("should return true", CustomFluentApiWrapperCode.validate(FluentApiWrapper.wrap(typeElement)));
}
})
- .compilationShouldSucceed()
+ .thenExpectThat().compilationSucceeds()
.executeTest();
}
@@ -248,31 +254,32 @@ static void myCommand(BackingBean1 bb) {
}
@Test
- public void getStateTest () {
- unitTestBuilder.defineTestWithPassedInElement(ValidTestApi.class, new APTKUnitTestProcessor() {
+ public void getStateTest() {
+ unitTestBuilder.when().passInElement().fromClass(ValidTestApi.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
FluentApiState state = CustomFluentApiWrapperCode.getState(FluentApiWrapper.wrap(typeElement));
- MatcherAssert.assertThat(state.getFluentApiInterfaceWrappers().stream().map(e-> e._annotatedElement().asType().toString()).collect(Collectors.toList()),
+ MatcherAssert.assertThat(state.getFluentApiInterfaceWrappers().stream().map(e -> e._annotatedElement().asType().toString()).collect(Collectors.toList()),
Matchers.containsInAnyOrder(
ValidTestApi.FluentInterface1.class.getCanonicalName(),
ValidTestApi.FluentInterface2.class.getCanonicalName())
);
- MatcherAssert.assertThat(state.getFluentApiCommandWrappers().stream().map(e-> e._annotatedElement().asType().toString()).collect(Collectors.toList()),
+ MatcherAssert.assertThat(state.getFluentApiCommandWrappers().stream().map(e -> e._annotatedElement().asType().toString()).collect(Collectors.toList()),
Matchers.containsInAnyOrder(
ValidTestApi.TestCommand1.class.getCanonicalName(),
ValidTestApi.TestCommand2.class.getCanonicalName())
);
- MatcherAssert.assertThat(state.getFluentApiBackingBeanWrappers().stream().map(e-> e._annotatedElement().asType().toString()).collect(Collectors.toList()),
+ MatcherAssert.assertThat(state.getFluentApiBackingBeanWrappers().stream().map(e -> e._annotatedElement().asType().toString()).collect(Collectors.toList()),
Matchers.containsInAnyOrder(
ValidTestApi.BackingBean1.class.getCanonicalName(),
ValidTestApi.BackingBean2.class.getCanonicalName())
);
}
})
- .compilationShouldSucceed()
+ .thenExpectThat().compilationSucceeds()
.executeTest();
}
diff --git a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/FluentApiProcessorTest.java b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/FluentApiProcessorTest.java
index 7f66696..cfb12e2 100644
--- a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/FluentApiProcessorTest.java
+++ b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/FluentApiProcessorTest.java
@@ -2,7 +2,8 @@
import io.toolisticon.aptk.tools.MessagerUtils;
import io.toolisticon.aptk.tools.corematcher.CoreMatcherValidationMessages;
-import io.toolisticon.cute.CompileTestBuilder;
+import io.toolisticon.cute.Cute;
+import io.toolisticon.cute.CuteApi;
import io.toolisticon.cute.JavaFileObjectUtils;
import org.junit.Before;
import org.junit.Test;
@@ -17,15 +18,15 @@
public class FluentApiProcessorTest {
- CompileTestBuilder.CompilationTestBuilder compileTestBuilder;
+ CuteApi.BlackBoxTestSourceFilesInterface compileTestBuilder;
@Before
public void init() {
MessagerUtils.setPrintMessageCodes(true);
- compileTestBuilder = CompileTestBuilder
- .compilationTest()
- .addProcessors(FluentApiProcessor.class);
+ compileTestBuilder = Cute
+ .blackBoxTest()
+ .given().processors(FluentApiProcessor.class);
}
@@ -33,9 +34,10 @@ public void init() {
public void test_valid_usage() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/TestcaseValidUsage.java"))
- .compilationShouldSucceed()
- .expectThatGeneratedSourceFileExists("io.toolisticon.fluapigen.processor.tests.Xyz")
+ .andSourceFiles("testcases/TestcaseValidUsage.java")
+ .whenCompiled()
+ .thenExpectThat().compilationSucceeds()
+ .andThat().generatedSourceFile("io.toolisticon.fluapigen.processor.tests.Xyz").exists()
.executeTest();
}
@@ -43,9 +45,10 @@ public void test_valid_usage() {
public void test_valid_usage_with_inline_bb_mapping() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/TestcaseValidUsageWithInlineBackingBeanMapping.java"))
- .compilationShouldSucceed()
- .expectThatGeneratedSourceFileExists("io.toolisticon.fluapigen.processor.tests.Xyz")
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/TestcaseValidUsageWithInlineBackingBeanMapping.java"))
+ .whenCompiled()
+ .thenExpectThat().compilationSucceeds()
+ .andThat().generatedSourceFile("io.toolisticon.fluapigen.processor.tests.Xyz").exists()
.executeTest();
}
@@ -55,9 +58,10 @@ public void test_valid_usage_with_inline_bb_mapping() {
public void test_valid_usage2() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/ExampleFluentApi.java"))
- .compilationShouldSucceed()
- .expectThatGeneratedSourceFileExists("io.toolisticon.fluapigen.processor.tests.ExampleFluentApiStarter")
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/ExampleFluentApi.java"))
+ .whenCompiled()
+ .thenExpectThat().compilationSucceeds()
+ .andThat().generatedSourceFile("io.toolisticon.fluapigen.processor.tests.ExampleFluentApiStarter").exists()
.executeTest();
}
*/
@@ -66,9 +70,10 @@ public void test_valid_usage2() {
public void test_valid_usage3() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/CuteFluentApi.java"))
- .compilationShouldSucceed()
- //.expectThatGeneratedSourceFileExists("io.toolisticon.fluapigen.processor.tests.ExampleFluentApiStarter")
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/CuteFluentApi.java"))
+ .whenCompiled()
+ .thenExpectThat().compilationSucceeds()
+ //.andThat().generatedSourceFile("io.toolisticon.fluapigen.processor.tests.ExampleFluentApiStarter").exists()
.executeTest();
}
@@ -76,10 +81,11 @@ public void test_valid_usage3() {
public void test_valid_usage4() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest.java"))
- //.compilationShouldFail()
- .compilationShouldSucceed()
- .expectThatGeneratedSourceFileExists("io.toolisticon.fluapigen.testcases.IntegrationTestStarter")
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest.java"))
+ //.whenCompiled().thenExpectThat().compilationFails()
+ .whenCompiled()
+ .thenExpectThat().compilationSucceeds()
+ .andThat().generatedSourceFile("io.toolisticon.fluapigen.testcases.IntegrationTestStarter").exists()
.executeTest();
}
@@ -87,9 +93,10 @@ public void test_valid_usage4() {
public void test_valid_usage_withDefaultMethods() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/TestcaseValidUsageWithDefaultMethods.java"))
- .compilationShouldSucceed()
- .expectThatGeneratedSourceFileExists("io.toolisticon.fluapigen.processor.tests.Xyz")
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/TestcaseValidUsageWithDefaultMethods.java"))
+ .whenCompiled()
+ .thenExpectThat().compilationSucceeds()
+ .andThat().generatedSourceFile("io.toolisticon.fluapigen.processor.tests.Xyz").exists()
.executeTest();
}
@@ -97,9 +104,9 @@ public void test_valid_usage_withDefaultMethods() {
public void test_invalid_bbFieldNameMapping() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_InvalidBBFieldMapping.java"))
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_CANNOT_FIND_BACKING_BEAN_FIELD.getCode())
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_InvalidBBFieldMapping.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_CANNOT_FIND_BACKING_BEAN_FIELD.getCode())
.executeTest();
}
@@ -108,9 +115,9 @@ public void test_invalid_bbFieldNameMapping() {
public void test_invalid_ReturnTypeInFluentInterface() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_InvalidReturnTypeInFluentInterface.java"))
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_RETURN_TYPE_MUST_BE_FLUENT_INTERFACE.getCode())
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_InvalidReturnTypeInFluentInterface.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_RETURN_TYPE_MUST_BE_FLUENT_INTERFACE.getCode())
.executeTest();
}
@@ -119,9 +126,9 @@ public void test_invalid_ReturnTypeInFluentInterface() {
public void test_invalid_MappingAtParentTraversal() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_InvalidMappingAtParentTraversal.java"))
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_CANNOT_FIND_BACKING_BEAN_FIELD.getCode())
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_InvalidMappingAtParentTraversal.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_CANNOT_FIND_BACKING_BEAN_FIELD.getCode())
.executeTest();
}
@@ -131,9 +138,9 @@ public void test_invalid_MappingAtParentTraversal() {
public void test_invalid_MissingMappingAnnotationOnParentTraversal() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_MissingMappingAnnotationOnParentTraversal.java"))
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.BB_MAPPING_ANNOTATION_MUST_BE_PRESENT_ADD_TO_PARENT_TRAVERSALS.getCode())
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_MissingMappingAnnotationOnParentTraversal.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.BB_MAPPING_ANNOTATION_MUST_BE_PRESENT_ADD_TO_PARENT_TRAVERSALS.getCode())
.executeTest();
}
@@ -142,9 +149,9 @@ public void test_invalid_MissingMappingAnnotationOnParentTraversal() {
public void test_invalid_ParameterAtCommand() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_InvalidParameterAtCommand.java"))
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_PARAMETER_OF_COMMAND_METHOD_MUST_BE_INTERFACE_ANNOTATED_AS_BACKING_BEAN.getCode())
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_InvalidParameterAtCommand.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_PARAMETER_OF_COMMAND_METHOD_MUST_BE_INTERFACE_ANNOTATED_AS_BACKING_BEAN.getCode())
.executeTest();
}
@@ -153,9 +160,9 @@ public void test_invalid_ParameterAtCommand() {
public void test_invalid_NoParameterAtCommand() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_NoParameterAtCommand.java"))
- .compilationShouldFail()
- .expectErrorMessage().thatContains(CoreMatcherValidationMessages.BY_NUMBER_OF_PARAMETERS.getCode())
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_NoParameterAtCommand.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(CoreMatcherValidationMessages.BY_NUMBER_OF_PARAMETERS.getCode())
.executeTest();
}
@@ -164,9 +171,9 @@ public void test_invalid_NoParameterAtCommand() {
public void test_invalid_MultipleRootInterfaces() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_InvalidMultipleRootInterfaces.java"))
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_FLUENTAPI_MULTIPLE_ROOT_INTERFACES.getCode())
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_InvalidMultipleRootInterfaces.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_FLUENTAPI_MULTIPLE_ROOT_INTERFACES.getCode())
.executeTest();
}
@@ -175,9 +182,9 @@ public void test_invalid_MultipleRootInterfaces() {
public void test_invalid_ImplicitValue_Int() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_InvalidImplicitValue_Int.java"))
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CANNOT_CONVERT_VALUE_STRING_TO_TARGET_TYPE.getCode())
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_InvalidImplicitValue_Int.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CANNOT_CONVERT_VALUE_STRING_TO_TARGET_TYPE.getCode())
.executeTest();
}
@@ -186,8 +193,9 @@ public void test_invalid_ImplicitValue_Int() {
public void test_valid_MissingBBFieldAnnotation() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_MissingBBFieldAnnotation.java"))
- .compilationShouldSucceed()
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_MissingBBFieldAnnotation.java"))
+ .whenCompiled()
+ .thenExpectThat().compilationSucceeds()
.executeTest();
}
@@ -196,9 +204,9 @@ public void test_valid_MissingBBFieldAnnotation() {
public void test_invalid_NonUniqueBBFieldId() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_NonUniqueBBFieldId.java"))
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_BACKING_BEAN_FIELD_ID_MUST_NOT_UNIQUE_IN_BB.getCode())
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_NonUniqueBBFieldId.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_BACKING_BEAN_FIELD_ID_MUST_NOT_UNIQUE_IN_BB.getCode())
.executeTest();
}
@@ -207,9 +215,9 @@ public void test_invalid_NonUniqueBBFieldId() {
public void test_invalid_NonUniqueBBFieldId_ImplicitlySet() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_NonUniqueBBFieldId_ImplicitlySet.java"))
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_BACKING_BEAN_FIELD_ID_MUST_NOT_UNIQUE_IN_BB.getCode())
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_NonUniqueBBFieldId_ImplicitlySet.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_BACKING_BEAN_FIELD_ID_MUST_NOT_UNIQUE_IN_BB.getCode())
.executeTest();
}
@@ -218,9 +226,9 @@ public void test_invalid_NonUniqueBBFieldId_ImplicitlySet() {
public void test_invalid_EmptyBBFieldId() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_EmptyBBFieldId.java"))
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_BACKING_BEAN_FIELD_ID_MUST_NOT_BE_EMPTY.getCode())
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_EmptyBBFieldId.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_BACKING_BEAN_FIELD_ID_MUST_NOT_BE_EMPTY.getCode())
.executeTest();
}
@@ -229,9 +237,9 @@ public void test_invalid_EmptyBBFieldId() {
public void test_invalid_MissingMethodParameterBBMapping() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_MissingMethodParameterBBMapping.java"))
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.BB_MAPPING_ANNOTATION_MUST_BE_PRESENT.getCode())
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_MissingMethodParameterBBMapping.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.BB_MAPPING_ANNOTATION_MUST_BE_PRESENT.getCode())
.executeTest();
}
@@ -240,9 +248,9 @@ public void test_invalid_MissingMethodParameterBBMapping() {
public void test_invalid_UnsupportedImplicitValueType() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_UnsupportedImplicitValueType.java"))
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_UNSUPPORTED_TYPE.getCode())
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_UnsupportedImplicitValueType.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_UNSUPPORTED_TYPE.getCode())
.executeTest();
}
@@ -251,9 +259,9 @@ public void test_invalid_UnsupportedImplicitValueType() {
public void test_invalid_InvalidImplicitValue_Enum() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_InvalidImplicitValue_Enum.java"))
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_INVALID_ENUM_VALUE.getCode())
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_InvalidImplicitValue_Enum.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_INVALID_ENUM_VALUE.getCode())
.executeTest();
@@ -263,9 +271,9 @@ public void test_invalid_InvalidImplicitValue_Enum() {
public void test_invalid_InvalidNumberOfParentMappingsAtCommand() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/TestcaseInvalidNumberOfParentMappingsAtCommand.java"))
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_INVALID_NUMBER_OF_PARENT_MAPPINGS_TO_REACH_ROOT_BB.getCode())
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/TestcaseInvalidNumberOfParentMappingsAtCommand.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_INVALID_NUMBER_OF_PARENT_MAPPINGS_TO_REACH_ROOT_BB.getCode())
.executeTest();
@@ -275,8 +283,9 @@ public void test_invalid_InvalidNumberOfParentMappingsAtCommand() {
public void test_valid_ImplicitValueConverter() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_ImplicitValueConverterTest.java"))
- .compilationShouldSucceed()
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_ImplicitValueConverterTest.java"))
+ .whenCompiled()
+ .thenExpectThat().compilationSucceeds()
.executeTest();
@@ -286,12 +295,12 @@ public void test_valid_ImplicitValueConverter() {
public void test_invalid_ImplicitValueConverter_invalidTargetType() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidTargetType.java"))
- .expectErrorMessage().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidTargetType.java").atLineNumber(55L).thatContains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_TO_TARGET_ATTRIBUTE_TYPE.getCode())
- .expectErrorMessage().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidTargetType.java").atLineNumber(58L).thatContains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_TO_TARGET_ATTRIBUTE_TYPE.getCode())
- .expectErrorMessage().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidTargetType.java").atLineNumber(61L).thatContains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_TO_TARGET_ATTRIBUTE_TYPE.getCode())
- .expectErrorMessage().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidTargetType.java").atLineNumber(64L).thatContains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_TO_TARGET_ATTRIBUTE_TYPE.getCode())
- .compilationShouldFail()
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidTargetType.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidTargetType.java").atLine(55).contains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_TO_TARGET_ATTRIBUTE_TYPE.getCode())
+ .andThat().compilerMessage().ofKindError().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidTargetType.java").atLine(58).contains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_TO_TARGET_ATTRIBUTE_TYPE.getCode())
+ .andThat().compilerMessage().ofKindError().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidTargetType.java").atLine(61).contains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_TO_TARGET_ATTRIBUTE_TYPE.getCode())
+ .andThat().compilerMessage().ofKindError().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidTargetType.java").atLine(64).contains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_TO_TARGET_ATTRIBUTE_TYPE.getCode())
.executeTest();
@@ -301,12 +310,12 @@ public void test_invalid_ImplicitValueConverter_invalidTargetType() {
public void test_invalid_ImplicitValueConverter_invalidSourceType() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidSourceType.java"))
- .expectErrorMessage().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidSourceType.java").atLineNumber(55L).thatContains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_SOURCE_TYPE_STRING.getCode())
- .expectErrorMessage().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidSourceType.java").atLineNumber(58L).thatContains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_SOURCE_TYPE_STRING.getCode())
- .expectErrorMessage().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidSourceType.java").atLineNumber(61L).thatContains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_SOURCE_TYPE_STRING.getCode())
- .expectErrorMessage().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidSourceType.java").atLineNumber(64L).thatContains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_SOURCE_TYPE_STRING.getCode())
- .compilationShouldFail()
+ .andSourceFiles("testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidSourceType.java")
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidSourceType.java").atLine(55).contains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_SOURCE_TYPE_STRING.getCode())
+ .andThat().compilerMessage().ofKindError().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidSourceType.java").atLine(58).contains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_SOURCE_TYPE_STRING.getCode())
+ .andThat().compilerMessage().ofKindError().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidSourceType.java").atLine(61).contains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_SOURCE_TYPE_STRING.getCode())
+ .andThat().compilerMessage().ofKindError().atSource("/testcases/IntegrationTest_ImplicitValueConverterTest_withInvalidConverter_invalidSourceType.java").atLine(64).contains(FluentApiProcessorCompilerMessages.ERROR_IMPLICIT_VALUE_CONVERTER_MUST_CONVERT_SOURCE_TYPE_STRING.getCode())
.executeTest();
@@ -316,8 +325,9 @@ public void test_invalid_ImplicitValueConverter_invalidSourceType() {
public void test_valid_BackingBeanMappingConverter() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_BackingBeanMapping_Converter.java"))
- .compilationShouldSucceed()
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_BackingBeanMapping_Converter.java"))
+ .whenCompiled()
+ .thenExpectThat().compilationSucceeds()
.executeTest();
@@ -327,9 +337,9 @@ public void test_valid_BackingBeanMappingConverter() {
public void test_invalid_BackingBeanMappingConverter_wrongSingleValueSource() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_BackingBeanMapping_Converter_WrongSourceSingleValue.java"))
- .expectErrorMessage().atLineNumber(62L).thatContains(FluentApiProcessorCompilerMessages.BB_MAPPING_INVALID_CONVERTER.getCode())
- .compilationShouldFail()
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_BackingBeanMapping_Converter_WrongSourceSingleValue.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().atLine(62).contains(FluentApiProcessorCompilerMessages.BB_MAPPING_INVALID_CONVERTER.getCode())
.executeTest();
@@ -339,9 +349,9 @@ public void test_invalid_BackingBeanMappingConverter_wrongSingleValueSource() {
public void test_invalid_BackingBeanMappingConverter_wrongArrayValueSource() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_BackingBeanMapping_Converter_WrongSourceArrayValue.java"))
- .expectErrorMessage().atLineNumber(64L).thatContains(FluentApiProcessorCompilerMessages.BB_MAPPING_INVALID_CONVERTER.getCode())
- .compilationShouldFail()
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_BackingBeanMapping_Converter_WrongSourceArrayValue.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().atLine(64).contains(FluentApiProcessorCompilerMessages.BB_MAPPING_INVALID_CONVERTER.getCode())
.executeTest();
@@ -351,9 +361,9 @@ public void test_invalid_BackingBeanMappingConverter_wrongArrayValueSource() {
public void test_invalid_BackingBeanMappingConverter_wrongCollectionValueSource() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_BackingBeanMapping_Converter_WrongSourceCollectionValue.java"))
- .expectErrorMessage().atLineNumber(66L).thatContains(FluentApiProcessorCompilerMessages.BB_MAPPING_INVALID_CONVERTER.getCode())
- .compilationShouldFail()
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_BackingBeanMapping_Converter_WrongSourceCollectionValue.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().atLine(66).contains(FluentApiProcessorCompilerMessages.BB_MAPPING_INVALID_CONVERTER.getCode())
.executeTest();
@@ -363,9 +373,9 @@ public void test_invalid_BackingBeanMappingConverter_wrongCollectionValueSource(
public void test_invalid_BackingBeanMappingConverter_wrongSingleValueTarget() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_BackingBeanMapping_Converter_WrongTargetSingleValue.java"))
- .expectErrorMessage().atLineNumber(62L).thatContains(FluentApiProcessorCompilerMessages.BB_MAPPING_INVALID_CONVERTER.getCode())
- .compilationShouldFail()
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_BackingBeanMapping_Converter_WrongTargetSingleValue.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().atLine(62).contains(FluentApiProcessorCompilerMessages.BB_MAPPING_INVALID_CONVERTER.getCode())
.executeTest();
@@ -375,9 +385,9 @@ public void test_invalid_BackingBeanMappingConverter_wrongSingleValueTarget() {
public void test_invalid_BackingBeanMappingConverter_wrongArrayValueTarget() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_BackingBeanMapping_Converter_WrongTargetArrayValue.java"))
- .expectErrorMessage().atLineNumber(64L).thatContains(FluentApiProcessorCompilerMessages.BB_MAPPING_INVALID_CONVERTER.getCode())
- .compilationShouldFail()
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_BackingBeanMapping_Converter_WrongTargetArrayValue.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().atLine(64).contains(FluentApiProcessorCompilerMessages.BB_MAPPING_INVALID_CONVERTER.getCode())
.executeTest();
@@ -387,9 +397,9 @@ public void test_invalid_BackingBeanMappingConverter_wrongArrayValueTarget() {
public void test_invalid_BackingBeanMappingConverter_wrongCollectionValueTarget() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_BackingBeanMapping_Converter_WrongTargetCollectionValue.java"))
- .expectErrorMessage().atLineNumber(66L).thatContains(FluentApiProcessorCompilerMessages.BB_MAPPING_INVALID_CONVERTER.getCode())
- .compilationShouldFail()
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_BackingBeanMapping_Converter_WrongTargetCollectionValue.java"))
+ .whenCompiled().thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().atLine(66).contains(FluentApiProcessorCompilerMessages.BB_MAPPING_INVALID_CONVERTER.getCode())
.executeTest();
@@ -399,8 +409,9 @@ public void test_invalid_BackingBeanMappingConverter_wrongCollectionValueTarget(
public void test_Inheritance_reusingInterfaces() {
compileTestBuilder
- .addSources(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_Inheritance_reusingInterfaces.java"))
- .compilationShouldSucceed()
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("testcases/IntegrationTest_Inheritance_reusingInterfaces.java"))
+ .whenCompiled()
+ .thenExpectThat().compilationSucceeds()
.executeTest();
@@ -409,8 +420,9 @@ public void test_Inheritance_reusingInterfaces() {
@Test
public void test_externalOrSharedBB() {
- compileTestBuilder.addSources("/testcases/sharedBB/FirstApi.java","/testcases/sharedBB/SharedBB.java")
- .compilationShouldSucceed()
+ compileTestBuilder.andSourceFiles("/testcases/sharedBB/FirstApi.java", "/testcases/sharedBB/SharedBB.java")
+ .whenCompiled()
+ .thenExpectThat().compilationSucceeds()
.executeTest();
}
diff --git a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ImplicitValueConverterTest.java b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ImplicitValueConverterTest.java
index 9991a55..cae3b6b 100644
--- a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ImplicitValueConverterTest.java
+++ b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ImplicitValueConverterTest.java
@@ -5,19 +5,19 @@
import io.toolisticon.aptk.tools.MessagerUtils;
import io.toolisticon.aptk.tools.TypeMirrorWrapper;
import io.toolisticon.aptk.tools.wrapper.TypeElementWrapper;
-import io.toolisticon.cute.CompileTestBuilder;
-import io.toolisticon.cute.UnitTest;
+import io.toolisticon.cute.Cute;
+import io.toolisticon.cute.CuteApi;
+import io.toolisticon.cute.UnitTestWithoutPassIn;
import io.toolisticon.fluapigen.api.FluentApiConverter;
import org.junit.Before;
import org.junit.Test;
import javax.annotation.processing.ProcessingEnvironment;
-import javax.lang.model.element.Element;
import java.util.List;
public class ImplicitValueConverterTest {
- CompileTestBuilder.UnitTestBuilder unitTestBuilder;
+ CuteApi.UnitTestRootInterface unitTestBuilder;
public static class TargetType {
@@ -47,15 +47,15 @@ public TargetType convert(String o) {
public void init() {
MessagerUtils.setPrintMessageCodes(true);
- unitTestBuilder = CompileTestBuilder
+ unitTestBuilder = Cute
.unitTest();
}
@Test
public void test() {
- unitTestBuilder.defineTest(new UnitTest() {
+ unitTestBuilder.when(new UnitTestWithoutPassIn() {
@Override
- public void unitTest(ProcessingEnvironment processingEnvironment, Element element) {
+ public void unitTest(ProcessingEnvironment processingEnvironment) {
try {
ToolingProvider.setTooling(processingEnvironment);
diff --git a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/IncompatibleParameterTypeExceptionTest.java b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/IncompatibleParameterTypeExceptionTest.java
index a504189..1aea399 100644
--- a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/IncompatibleParameterTypeExceptionTest.java
+++ b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/IncompatibleParameterTypeExceptionTest.java
@@ -2,7 +2,7 @@
import io.toolisticon.aptk.common.ToolingProvider;
import io.toolisticon.aptk.tools.MessagerUtils;
-import io.toolisticon.cute.CompileTestBuilder;
+import io.toolisticon.cute.Cute;
import io.toolisticon.cute.PassIn;
import io.toolisticon.fluapigen.api.FluentApiBackingBeanMapping;
import org.junit.Before;
@@ -29,7 +29,8 @@ public void testWriteCompilerMessage() {
final String parameterType = "PT";
final String bbFieldName = "FN";
final String bbFieldType = "FT";
- CompileTestBuilder.unitTest().defineTestWithPassedInElement(ExceptionTest.class, (processingEnvironment, element) -> {
+ Cute.unitTest().when().passInElement().fromClass(ExceptionTest.class)
+ .intoUnitTest((processingEnvironment, element) -> {
try {
@@ -43,8 +44,9 @@ public void testWriteCompilerMessage() {
ToolingProvider.clearTooling();
}
})
- .compilationShouldFail()
- .expectErrorMessageThatContains(FluentApiProcessorCompilerMessages.ERROR_INCOMPATIBLE_BACKING_BEAN_MAPPING_TYPES.getCode(), parameterType, bbFieldName, bbFieldType).executeTest();
+ .thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_INCOMPATIBLE_BACKING_BEAN_MAPPING_TYPES.getCode(), parameterType, bbFieldName, bbFieldType)
+ .executeTest();
}
diff --git a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ModelBackingBeanFieldTest.java b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ModelBackingBeanFieldTest.java
index 33a30bb..cc38372 100644
--- a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ModelBackingBeanFieldTest.java
+++ b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ModelBackingBeanFieldTest.java
@@ -2,14 +2,11 @@
import io.toolisticon.aptk.cute.APTKUnitTestProcessor;
import io.toolisticon.aptk.tools.MessagerUtils;
-import io.toolisticon.aptk.tools.corematcher.CoreMatcherValidationMessages;
import io.toolisticon.aptk.tools.wrapper.ExecutableElementWrapper;
-import io.toolisticon.cute.CompileTestBuilder;
+import io.toolisticon.cute.Cute;
+import io.toolisticon.cute.CuteApi;
import io.toolisticon.cute.PassIn;
-import io.toolisticon.fluapigen.api.FluentApi;
-import io.toolisticon.fluapigen.api.FluentApiBackingBean;
import io.toolisticon.fluapigen.api.FluentApiBackingBeanField;
-import io.toolisticon.fluapigen.api.FluentApiCommand;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Before;
@@ -17,17 +14,16 @@
import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.ExecutableElement;
-import javax.lang.model.element.TypeElement;
public class ModelBackingBeanFieldTest {
- CompileTestBuilder.UnitTestBuilder unitTestBuilder;
+ CuteApi.UnitTestRootInterface unitTestBuilder;
@Before
public void init() {
MessagerUtils.setPrintMessageCodes(true);
- unitTestBuilder = CompileTestBuilder
+ unitTestBuilder = Cute
.unitTest();
}
@@ -51,7 +47,9 @@ interface BackingBeanFieldIdWithExplicitIdTest {
@Test
public void validationTest_PlacedOnClass() {
- unitTestBuilder.defineTestWithPassedInElement(BackingBeanFieldIdTest.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.
+ when().passInElement().fromClass(BackingBeanFieldIdTest.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, ExecutableElement element) {
@@ -63,7 +61,7 @@ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, Executable
}
})
- .compilationShouldSucceed()
+ .thenExpectThat().compilationSucceeds()
.executeTest();
@@ -73,7 +71,8 @@ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, Executable
@Test
public void validationTest_PlacedOnClass_withExplicitId() {
- unitTestBuilder.defineTestWithPassedInElement(BackingBeanFieldIdWithExplicitIdTest.class, new APTKUnitTestProcessor() {
+ unitTestBuilder.when().passInElement().fromClass(BackingBeanFieldIdWithExplicitIdTest.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, ExecutableElement element) {
@@ -82,7 +81,7 @@ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, Executable
}
})
- .compilationShouldSucceed()
+ .thenExpectThat().compilationSucceeds()
.executeTest();
diff --git a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ModelInterfaceMethodParameterTest.java b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ModelInterfaceMethodParameterTest.java
new file mode 100644
index 0000000..81320c0
--- /dev/null
+++ b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ModelInterfaceMethodParameterTest.java
@@ -0,0 +1,120 @@
+package io.toolisticon.fluapigen.processor;
+
+import io.toolisticon.aptk.cute.APTKUnitTestProcessor;
+import io.toolisticon.aptk.tools.wrapper.VariableElementWrapper;
+import io.toolisticon.cute.Cute;
+import io.toolisticon.cute.PassIn;
+import io.toolisticon.fluapigen.validation.api.Matches;
+import io.toolisticon.fluapigen.validation.api.NotNull;
+import io.toolisticon.fluapigen.validation.api.Nullable;
+import org.hamcrest.MatcherAssert;
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+import javax.annotation.processing.ProcessingEnvironment;
+import javax.lang.model.element.VariableElement;
+import java.util.stream.Collectors;
+
+/**
+ * Unit test for {@link ModelInterfaceMethodParameter}.
+ */
+public class ModelInterfaceMethodParameterTest {
+
+ interface TestClassWithoutValidators {
+
+ public void testMethod(@PassIn String parameter);
+
+ }
+
+
+ @Test
+ public void test_getValidators_withoutValidatorsPresent() {
+ Cute.unitTest().when().passInElement().fromClass(TestClassWithoutValidators.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
+ @Override
+ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, VariableElement variableElement) {
+
+ ModelInterfaceMethodParameter unit = new ModelInterfaceMethodParameter(VariableElementWrapper.wrap(variableElement), null, null);
+
+ MatcherAssert.assertThat("Expect to find no validators", !unit.hasValidators());
+
+ }
+ }).executeTest();
+ }
+
+ @NotNull
+ interface TestClassWithValidators {
+
+ public void testMethod(@PassIn @Matches(".*[@].*") String parameter);
+
+ }
+
+ @Test
+ public void test_getValidators_withValidatorsPresent() {
+ Cute.unitTest().when().passInElement().fromClass(TestClassWithValidators.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
+ @Override
+ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, VariableElement variableElement) {
+
+ ModelInterfaceMethodParameter unit = new ModelInterfaceMethodParameter(VariableElementWrapper.wrap(variableElement), null, null);
+
+ MatcherAssert.assertThat("Expect to find validators", unit.hasValidators());
+ MatcherAssert.assertThat("Expect to find 2 validators", unit.getValidators().size() == 2);
+ MatcherAssert.assertThat(unit.getValidators().stream().map(e -> e.getAnnotationMirrorWrapper().asTypeMirror().getQualifiedName()).collect(Collectors.toList()), Matchers.containsInAnyOrder(NotNull.class.getCanonicalName(), Matches.class.getCanonicalName()));
+
+
+ }
+ }).executeTest();
+ }
+
+ @NotNull
+ interface TestClassWithOverruledValidators {
+
+ void testMethod(@PassIn @Nullable @Matches(".*[@].*") String parameter);
+
+ }
+
+ @Test
+ public void test_getValidators_withOverruledValidatorsPresent() {
+ Cute.unitTest().when().passInElement().fromClass(TestClassWithOverruledValidators.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
+ @Override
+ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, VariableElement variableElement) {
+
+ ModelInterfaceMethodParameter unit = new ModelInterfaceMethodParameter(VariableElementWrapper.wrap(variableElement), null, null);
+
+ MatcherAssert.assertThat("Expect to find validators", unit.hasValidators());
+ MatcherAssert.assertThat("Expect to find 2 validators", unit.getValidators().size() == 2);
+ MatcherAssert.assertThat(unit.getValidators().stream().map(e -> e.getAnnotationMirrorWrapper().asTypeMirror().getQualifiedName()).collect(Collectors.toList()), Matchers.containsInAnyOrder(Nullable.class.getCanonicalName(), Matches.class.getCanonicalName()));
+
+
+ }
+ }).executeTest();
+ }
+
+ @Nullable
+ interface TestClassWithOverruledValidators2 {
+
+ void testMethod(@PassIn @NotNull @Matches(".*[@].*") String parameter);
+
+ }
+
+ @Test
+ public void test_getValidators_withOverruledValidatorsPresent2() {
+ Cute.unitTest().when().passInElement().fromClass(TestClassWithOverruledValidators2.class)
+ .intoUnitTest(new APTKUnitTestProcessor() {
+ @Override
+ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, VariableElement variableElement) {
+
+ ModelInterfaceMethodParameter unit = new ModelInterfaceMethodParameter(VariableElementWrapper.wrap(variableElement), null, null);
+
+ MatcherAssert.assertThat("Expect to find validators", unit.hasValidators());
+ MatcherAssert.assertThat("Expect to find 2 validators", unit.getValidators().size() == 2);
+ MatcherAssert.assertThat(unit.getValidators().stream().map(e -> e.getAnnotationMirrorWrapper().asTypeMirror().getQualifiedName()).collect(Collectors.toList()), Matchers.containsInAnyOrder(NotNull.class.getCanonicalName(), Matches.class.getCanonicalName()));
+
+
+ }
+ }).executeTest();
+ }
+
+}
diff --git a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ModelInterfaceTest.java b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ModelInterfaceTest.java
index d7e0bcd..8c33ad9 100644
--- a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ModelInterfaceTest.java
+++ b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ModelInterfaceTest.java
@@ -1,9 +1,10 @@
package io.toolisticon.fluapigen.processor;
-import io.toolisticon.aptk.cute.APTKUnitTestProcessor;
+import io.toolisticon.aptk.common.ToolingProvider;
import io.toolisticon.aptk.tools.MessagerUtils;
import io.toolisticon.aptk.tools.TypeUtils;
-import io.toolisticon.cute.CompileTestBuilder;
+import io.toolisticon.cute.Cute;
+import io.toolisticon.cute.UnitTestWithoutPassIn;
import io.toolisticon.fluapigen.api.FluentApiBackingBean;
import io.toolisticon.fluapigen.api.FluentApiCommand;
import io.toolisticon.fluapigen.api.FluentApiInterface;
@@ -63,23 +64,28 @@ public static List myCommand(MyBB myBB) {
@Test
public void getTypeParameterNamesString() {
- CompileTestBuilder.unitTest().defineTest(new APTKUnitTestProcessor() {
+ Cute.unitTest().when(new UnitTestWithoutPassIn() {
@Override
- public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
+ public void unitTest(ProcessingEnvironment processingEnvironment) {
- RenderStateHelper.create();
+ ToolingProvider.setTooling(processingEnvironment);
+ try {
- TypeElement backingBeanElement = TypeUtils.TypeRetrieval.getTypeElement(MyBB.class);
- TypeElement fluentApiElement = TypeUtils.TypeRetrieval.getTypeElement(MyFluentInterface.class);
+ RenderStateHelper.create();
+ TypeElement backingBeanElement = TypeUtils.TypeRetrieval.getTypeElement(MyBB.class);
+ TypeElement fluentApiElement = TypeUtils.TypeRetrieval.getTypeElement(MyFluentInterface.class);
- ModelInterface unit = new ModelInterface(FluentApiInterfaceWrapper.wrap(fluentApiElement), new ModelBackingBean(FluentApiBackingBeanWrapper.wrap(backingBeanElement)));
- MatcherAssert.assertThat(unit.getTypeParameterNamesString(), Matchers.is(""));
+ ModelInterface unit = new ModelInterface(FluentApiInterfaceWrapper.wrap(fluentApiElement), new ModelBackingBean(FluentApiBackingBeanWrapper.wrap(backingBeanElement)));
+ MatcherAssert.assertThat(unit.getTypeParameterNamesString(), Matchers.is(""));
+ } finally {
+ ToolingProvider.clearTooling();
+ }
}
})
- .compilationShouldSucceed()
+ .thenExpectThat().compilationSucceeds()
.executeTest();
@@ -88,23 +94,27 @@ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElemen
@Test
public void getTypeParametersString() {
- CompileTestBuilder.unitTest().defineTest(new APTKUnitTestProcessor() {
+ Cute.unitTest().when(new UnitTestWithoutPassIn() {
@Override
- public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
+ public void unitTest(ProcessingEnvironment processingEnvironment) {
- RenderStateHelper.create();
+ ToolingProvider.setTooling(processingEnvironment);
+ try {
+ RenderStateHelper.create();
- TypeElement backingBeanElement = TypeUtils.TypeRetrieval.getTypeElement(MyBB.class);
- TypeElement fluentApiElement = TypeUtils.TypeRetrieval.getTypeElement(MyFluentInterface.class);
+ TypeElement backingBeanElement = TypeUtils.TypeRetrieval.getTypeElement(MyBB.class);
+ TypeElement fluentApiElement = TypeUtils.TypeRetrieval.getTypeElement(MyFluentInterface.class);
- ModelInterface unit = new ModelInterface(FluentApiInterfaceWrapper.wrap(fluentApiElement), new ModelBackingBean(FluentApiBackingBeanWrapper.wrap(backingBeanElement)));
- MatcherAssert.assertThat(unit.getTypeParametersString(), Matchers.is(">"));
-
+ ModelInterface unit = new ModelInterface(FluentApiInterfaceWrapper.wrap(fluentApiElement), new ModelBackingBean(FluentApiBackingBeanWrapper.wrap(backingBeanElement)));
+ MatcherAssert.assertThat(unit.getTypeParametersString(), Matchers.is(">"));
+ } finally {
+ ToolingProvider.clearTooling();
+ }
}
})
- .compilationShouldSucceed()
+ .thenExpectThat().compilationSucceeds()
.executeTest();
@@ -112,22 +122,25 @@ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElemen
@Test
public void getTypeParametersString_WithMultipleExtendsBounds() {
-
- CompileTestBuilder.unitTest().defineTest(new APTKUnitTestProcessor() {
+ Cute.unitTest().when(new UnitTestWithoutPassIn() {
@Override
- public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
-
- RenderStateHelper.create();
+ public void unitTest(ProcessingEnvironment processingEnvironment) {
- TypeElement backingBeanElement = TypeUtils.TypeRetrieval.getTypeElement(MyBB.class);
- TypeElement fluentApiElement = TypeUtils.TypeRetrieval.getTypeElement(MyFluentInterfaceWithMultipleExtendsBounds.class);
+ ToolingProvider.setTooling(processingEnvironment);
+ try {
+ RenderStateHelper.create();
- ModelInterface unit = new ModelInterface(FluentApiInterfaceWrapper.wrap(fluentApiElement), new ModelBackingBean(FluentApiBackingBeanWrapper.wrap(backingBeanElement)));
- MatcherAssert.assertThat(unit.getTypeParametersString(), Matchers.is(" & Serializable>"));
+ TypeElement backingBeanElement = TypeUtils.TypeRetrieval.getTypeElement(MyBB.class);
+ TypeElement fluentApiElement = TypeUtils.TypeRetrieval.getTypeElement(MyFluentInterfaceWithMultipleExtendsBounds.class);
+ ModelInterface unit = new ModelInterface(FluentApiInterfaceWrapper.wrap(fluentApiElement), new ModelBackingBean(FluentApiBackingBeanWrapper.wrap(backingBeanElement)));
+ MatcherAssert.assertThat(unit.getTypeParametersString(), Matchers.is(" & Serializable>"));
+ } finally {
+ ToolingProvider.clearTooling();
+ }
}
})
- .compilationShouldSucceed()
+ .thenExpectThat().compilationSucceeds()
.executeTest();
}
@@ -135,29 +148,25 @@ public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElemen
@Test
public void getImports() {
- CompileTestBuilder.unitTest().defineTest(new APTKUnitTestProcessor() {
+ Cute.unitTest().when(new UnitTestWithoutPassIn() {
@Override
- public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {
+ public void unitTest(ProcessingEnvironment processingEnvironment) {
- RenderStateHelper.create();
+ ToolingProvider.setTooling(processingEnvironment);
+ try {
+ RenderStateHelper.create();
- TypeElement backingBeanElement = TypeUtils.TypeRetrieval.getTypeElement(MyBB.class);
- TypeElement fluentApiElement = TypeUtils.TypeRetrieval.getTypeElement(MyFluentInterfaceWithMultipleExtendsBounds.class);
-
- ModelInterface unit = new ModelInterface(FluentApiInterfaceWrapper.wrap(fluentApiElement), new ModelBackingBean(FluentApiBackingBeanWrapper.wrap(backingBeanElement)));
- MatcherAssert.assertThat(unit.fetchImports(), Matchers.containsInAnyOrder(
- List.class.getCanonicalName(),
- MyFluentInterfaceWithMultipleExtendsBounds.class.getCanonicalName(),
- MyCommand.class.getCanonicalName(),
- InputStream.class.getCanonicalName(),
- Collection.class.getCanonicalName(),
- Serializable.class.getCanonicalName()));
+ TypeElement backingBeanElement = TypeUtils.TypeRetrieval.getTypeElement(MyBB.class);
+ TypeElement fluentApiElement = TypeUtils.TypeRetrieval.getTypeElement(MyFluentInterfaceWithMultipleExtendsBounds.class);
+ ModelInterface unit = new ModelInterface(FluentApiInterfaceWrapper.wrap(fluentApiElement), new ModelBackingBean(FluentApiBackingBeanWrapper.wrap(backingBeanElement)));
+ MatcherAssert.assertThat(unit.fetchImports(), Matchers.containsInAnyOrder(List.class.getCanonicalName(), MyFluentInterfaceWithMultipleExtendsBounds.class.getCanonicalName(), MyCommand.class.getCanonicalName(), InputStream.class.getCanonicalName(), Collection.class.getCanonicalName(), Serializable.class.getCanonicalName()));
+ } finally {
+ ToolingProvider.clearTooling();
+ }
}
- })
- .compilationShouldSucceed()
+ }).thenExpectThat().compilationSucceeds()
.executeTest();
-
}
}
diff --git a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ValidatorTest.java b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ValidatorTest.java
index 2533e07..1129f2d 100644
--- a/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ValidatorTest.java
+++ b/fluapigen-processor/src/test/java/io/toolisticon/fluapigen/processor/ValidatorTest.java
@@ -4,7 +4,8 @@
import io.toolisticon.aptk.tools.MessagerUtils;
import io.toolisticon.aptk.tools.wrapper.AnnotationMirrorWrapper;
import io.toolisticon.aptk.tools.wrapper.VariableElementWrapper;
-import io.toolisticon.cute.CompileTestBuilder;
+import io.toolisticon.cute.Cute;
+import io.toolisticon.cute.CuteApi;
import io.toolisticon.cute.PassIn;
import io.toolisticon.cute.UnitTest;
import io.toolisticon.fluapigen.validation.api.FluentApiValidator;
@@ -23,17 +24,17 @@
public class ValidatorTest {
- CompileTestBuilder.UnitTestBuilder unitTestBuilder;
- CompileTestBuilder.CompilationTestBuilder compilationTestBuilder;
+ CuteApi.UnitTestRootInterface unitTestBuilder;
+ CuteApi.BlackBoxTestSourceFilesInterface compilationTestBuilder;
@Before
public void init() {
MessagerUtils.setPrintMessageCodes(true);
- unitTestBuilder = CompileTestBuilder
+ unitTestBuilder = Cute
.unitTest();
- compilationTestBuilder = CompileTestBuilder.compilationTest().addProcessors(FluentApiProcessor.class);
+ compilationTestBuilder = Cute.blackBoxTest().given().processors(FluentApiProcessor.class);
}
@@ -43,7 +44,8 @@ interface TestInterfaceWithMatchesValidator {
@Test
public void testMatchesValidator() {
- unitTestBuilder.defineTestWithPassedInElement(TestInterfaceWithMatchesValidator.class, (UnitTest) (processingEnvironment, element) -> {
+ unitTestBuilder.when().passInElement().fromClass(TestInterfaceWithMatchesValidator.class)
+ .intoUnitTest((UnitTest) (processingEnvironment, element) -> {
try {
ToolingProvider.setTooling(processingEnvironment);
@@ -55,14 +57,16 @@ public void testMatchesValidator() {
ToolingProvider.clearTooling();
}
- }).compilationShouldSucceed()
+ })
+ .thenExpectThat().compilationSucceeds()
.executeTest();
}
@Test
public void compilationTestValidator() {
- compilationTestBuilder.addSources("/testcases/TestcaseValidator.java")
- .compilationShouldSucceed()
+ compilationTestBuilder.andSourceFiles("/testcases/TestcaseValidator.java")
+ .whenCompiled().thenExpectThat()
+ .compilationSucceeds()
.executeTest();
}
@@ -141,7 +145,8 @@ void testCase(@PassIn @AttributeValueStringRepresentationTest(longValue = 1L, in
@Test
public void test_getValidatorExpressionAttributeValueStringRepresentation() {
- unitTestBuilder.defineTestWithPassedInElement(TestCase.class, (UnitTest) (processingEnvironment, element) -> {
+ unitTestBuilder.when().passInElement().fromClass(TestCase.class)
+ .intoUnitTest((UnitTest) (processingEnvironment, element) -> {
try {
ToolingProvider.setTooling(processingEnvironment);
@@ -165,13 +170,14 @@ public void test_getValidatorExpressionAttributeValueStringRepresentation() {
ToolingProvider.clearTooling();
}
- }).compilationShouldSucceed()
+ }).thenExpectThat().compilationSucceeds()
.executeTest();
}
@Test
public void test_validate() {
- unitTestBuilder.defineTestWithPassedInElement(TestCase.class, (UnitTest) (processingEnvironment, element) -> {
+ unitTestBuilder.when().passInElement().fromClass(TestCase.class)
+ .intoUnitTest((UnitTest) (processingEnvironment, element) -> {
try {
ToolingProvider.setTooling(processingEnvironment);
@@ -186,7 +192,8 @@ public void test_validate() {
ToolingProvider.clearTooling();
}
- }).compilationShouldSucceed()
+ })
+ .thenExpectThat().compilationSucceeds()
.executeTest();
}
@@ -201,9 +208,10 @@ public class MyValidator implements Validator {
final String attr;
- public MyValidator (String attr){
+ public MyValidator(String attr) {
this.attr = attr;
}
+
@Override
public boolean validate(String obj) {
@@ -222,7 +230,9 @@ interface WrongAttributeNameToConstructorParameterMappingTest {
@Test
public void test_validate_invalidValidatorWrong() {
- unitTestBuilder.defineTestWithPassedInElement(WrongAttributeNameToConstructorParameterMappingTest.class, (UnitTest) (processingEnvironment, element) -> {
+ unitTestBuilder.
+ when().passInElement().fromClass(WrongAttributeNameToConstructorParameterMappingTest.class)
+ .intoUnitTest((UnitTest) (processingEnvironment, element) -> {
try {
ToolingProvider.setTooling(processingEnvironment);
@@ -238,8 +248,8 @@ public void test_validate_invalidValidatorWrong() {
}
})
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_BROKEN_VALIDATOR_ATTRIBUTE_NAME_MISMATCH.getCode())
+ .thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_BROKEN_VALIDATOR_ATTRIBUTE_NAME_MISMATCH.getCode())
.executeTest();
}
@@ -272,7 +282,8 @@ interface MissingNoargConstructorTest {
@Test
public void test_validate_missingNoargConstructor() {
- unitTestBuilder.defineTestWithPassedInElement(MissingNoargConstructorTest.class, (UnitTest) (processingEnvironment, element) -> {
+ unitTestBuilder.when().passInElement().fromClass(MissingNoargConstructorTest.class)
+ .intoUnitTest((UnitTest) (processingEnvironment, element) -> {
try {
ToolingProvider.setTooling(processingEnvironment);
@@ -288,8 +299,8 @@ public void test_validate_missingNoargConstructor() {
}
})
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_BROKEN_VALIDATOR_MISSING_NOARG_CONSTRUCTOR.getCode())
+ .thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_BROKEN_VALIDATOR_MISSING_NOARG_CONSTRUCTOR.getCode())
.executeTest();
}
@@ -325,7 +336,8 @@ interface NonMatchingConstructorTest {
@Test
public void test_validate_noMatchingConstructor() {
- unitTestBuilder.defineTestWithPassedInElement(NonMatchingConstructorTest.class, (UnitTest) (processingEnvironment, element) -> {
+ unitTestBuilder.when().passInElement().fromClass(NonMatchingConstructorTest.class)
+ .intoUnitTest((UnitTest) (processingEnvironment, element) -> {
try {
ToolingProvider.setTooling(processingEnvironment);
@@ -341,8 +353,8 @@ public void test_validate_noMatchingConstructor() {
}
})
- .compilationShouldFail()
- .expectErrorMessage().thatContains(FluentApiProcessorCompilerMessages.ERROR_BROKEN_VALIDATOR_CONSTRUCTOR_PARAMETER_MAPPING.getCode())
+ .thenExpectThat().compilationFails()
+ .andThat().compilerMessage().ofKindError().contains(FluentApiProcessorCompilerMessages.ERROR_BROKEN_VALIDATOR_CONSTRUCTOR_PARAMETER_MAPPING.getCode())
.executeTest();
}
diff --git a/fluapigen-validation-api/pom.xml b/fluapigen-validation-api/pom.xml
index a3788b6..37e5e98 100644
--- a/fluapigen-validation-api/pom.xml
+++ b/fluapigen-validation-api/pom.xml
@@ -9,7 +9,7 @@
io.toolisticon.fluapigen
fluapigen
- 0.8.3
+ 0.9.0
fluapigen-validation-api
diff --git a/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/FluentApiValidator.java b/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/FluentApiValidator.java
index 7a2dbaf..62e4709 100644
--- a/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/FluentApiValidator.java
+++ b/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/FluentApiValidator.java
@@ -20,8 +20,16 @@
/**
* Used to map parameters to validator constructor.
+ * Defaults to empty array for no-arg constructor.
* @return the parameter names
*/
String[] attributeNamesToConstructorParameterMapping() default {};
+ /**
+ * Must reference annotation types annotated with this meta annotation.
+ * Defaults to empty array.
+ * @return the annotations overwritten with this annotation
+ */
+ Class>[] overwrites() default {};
+
}
diff --git a/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/HasNoArgConstructor.java b/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/HasNoArgConstructor.java
index 1720771..ba4a66e 100644
--- a/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/HasNoArgConstructor.java
+++ b/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/HasNoArgConstructor.java
@@ -1,12 +1,18 @@
package io.toolisticon.fluapigen.validation.api;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
/**
* Meta annotation to declare validators via annotation.
*/
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.PARAMETER)
@FluentApiValidator(value = HasNoArgConstructor.ValidatorImpl.class, attributeNamesToConstructorParameterMapping = {"modifier"})
public @interface HasNoArgConstructor {
@@ -27,7 +33,7 @@ public boolean validate(Class obj) {
try {
// need to get constructor method
- Constructor> constructor = obj.getConstructor();
+ Constructor> constructor = obj.getDeclaredConstructor();
for (int modifier : modifiers) {
if ((modifier & obj.getModifiers()) == 0) {
@@ -36,12 +42,24 @@ public boolean validate(Class obj) {
}
} catch (NoSuchMethodException e) {
- return false;
+
+ // must check if there are any explicit constructors, if not then there is just the default public one.
+ return obj.getDeclaredConstructors().length == 0 && hasPublicModifier();
+
}
}
return true;
}
+
+ boolean hasPublicModifier () {
+ for (int modifier : modifiers){
+ if (modifier == Modifier.PUBLIC) {
+ return true;
+ }
+ }
+ return false;
+ }
}
diff --git a/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/Matches.java b/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/Matches.java
index da4b8b6..6b6ea82 100644
--- a/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/Matches.java
+++ b/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/Matches.java
@@ -1,8 +1,14 @@
package io.toolisticon.fluapigen.validation.api;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
import java.util.regex.Pattern;
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.PARAMETER)
@FluentApiValidator(value = Matches.ValidatorImpl.class, attributeNamesToConstructorParameterMapping = {"value"})
public @interface Matches {
@@ -18,7 +24,7 @@ public ValidatorImpl(String regularExpression) {
@Override
public boolean validate(String obj) {
- return Pattern.compile(regularExpression).matcher(obj).matches();
+ return obj == null || Pattern.compile(regularExpression).matcher(obj).matches();
}
}
diff --git a/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/MaxLength.java b/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/MaxLength.java
index c9e240c..c3b0d9a 100644
--- a/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/MaxLength.java
+++ b/fluapigen-validation-api/src/main/java/io/toolisticon/fluapigen/validation/api/MaxLength.java
@@ -1,34 +1,36 @@
package io.toolisticon.fluapigen.validation.api;
-import java.lang.reflect.Array;
-import java.util.Collection;
-
-
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Checks if string has maximal length.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.PARAMETER)
@FluentApiValidator(value = MaxLength.ValidatorImpl.class, attributeNamesToConstructorParameterMapping = {"value"})
public @interface MaxLength {
int value();
- class ValidatorImpl implements Validator