Skip to content

Commit

Permalink
Upgraded to Cute 1.0.0_RC1
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasstamann committed Jan 25, 2024
1 parent e9f2f84 commit ecd471f
Show file tree
Hide file tree
Showing 13 changed files with 340 additions and 281 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -29,7 +29,10 @@ interface ExceptionTest {
@Test
public void testWriteCompilerMessage() {

CompileTestBuilder.unitTest().<ExecutableElement>defineTestWithPassedInElement(ExceptionTest.class, (processingEnvironment, element) -> {
Cute.unitTest()
.when()
.passInElement().<ExecutableElement>fromClass(ExceptionTest.class)
.intoUnitTest((processingEnvironment, element) -> {


try {
Expand All @@ -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();

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand All @@ -44,15 +44,17 @@ private interface BackingBean {
@Test
public void validationTest_NoRoot() {

unitTestBuilder.<TypeElement>defineTestWithPassedInElement(NotAccessibleTestApi.class, new APTKUnitTestProcessor<TypeElement>() {
unitTestBuilder.when()
.passInElement().<TypeElement>fromClass(NotAccessibleTestApi.class)
.intoUnitTest(new APTKUnitTestProcessor<TypeElement>() {
@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();


Expand All @@ -72,18 +74,19 @@ static class BackingBean {
@Test
public void validationTest_PlacedOnClass() {

unitTestBuilder.<TypeElement>defineTestWithPassedInElement(PlacedOnClassTestApi.class, new APTKUnitTestProcessor<TypeElement>() {
unitTestBuilder.when()
.passInElement().<TypeElement>fromClass(PlacedOnClassTestApi.class)
.intoUnitTest(new APTKUnitTestProcessor<TypeElement>() {
@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();


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand Down Expand Up @@ -65,29 +66,31 @@ static void doSomethingBeautiful(BackingBean backingBean) {
@Test
public void validationTest_HappyPath() {

unitTestBuilder.<TypeElement>defineTestWithPassedInElement(HappyPathTestApi.class, new APTKUnitTestProcessor<TypeElement>() {
unitTestBuilder.when().passInElement().<TypeElement>fromClass(HappyPathTestApi.class)
.intoUnitTest(new APTKUnitTestProcessor<TypeElement>() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {

MatcherAssert.assertThat("should return true", CustomFluentApiCommandWrapperCode.validate(FluentApiCommandWrapper.wrap(typeElement)));
}
})
.compilationShouldSucceed()
.thenExpectThat()
.compilationSucceeds()
.executeTest();


}

@Test
public void test_getCommandMethodName_onCommandClass() {
unitTestBuilder.<TypeElement>defineTestWithPassedInElement(HappyPathTestApi.class, new APTKUnitTestProcessor<TypeElement>() {
unitTestBuilder.when().passInElement().<TypeElement>fromClass(HappyPathTestApi.class)
.intoUnitTest(new APTKUnitTestProcessor<TypeElement>() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {

MatcherAssert.assertThat(CustomFluentApiCommandWrapperCode.getCommandMethodName(FluentApiCommandWrapper.wrap(typeElement)), Matchers.is("doSomethingBeautiful"));
}
})
.compilationShouldSucceed()
.thenExpectThat().compilationSucceeds()
.executeTest();
}

Expand Down Expand Up @@ -121,14 +124,17 @@ static void doSomethingBeautiful(BackingBean backingBean) {

@Test
public void test_getCommandMethodName_onFluentInterfaceMethods() {
unitTestBuilder.<ExecutableElement>defineTestWithPassedInElement(OnFluentApiMethodTestApi.class, new APTKUnitTestProcessor<ExecutableElement>() {
unitTestBuilder.when()
.passInElement().<ExecutableElement>fromClass(OnFluentApiMethodTestApi.class)
.intoUnitTest(new APTKUnitTestProcessor<ExecutableElement>() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, ExecutableElement typeElement) {

MatcherAssert.assertThat(CustomFluentApiCommandWrapperCode.getCommandMethodName(FluentApiCommandWrapper.wrap(typeElement)), Matchers.is("doSomethingBeautiful"));
}
})
.compilationShouldSucceed()
.thenExpectThat()
.compilationSucceeds()
.executeTest();
}

Expand Down Expand Up @@ -163,7 +169,8 @@ static void doSomethingBeautiful(BackingBean backingBean) {

@Test
public void test_validate_onMethodInClass() {
unitTestBuilder.<ExecutableElement>defineTestWithPassedInElement(OnFluentApiMethodTestApi_InClass_error.class, new APTKUnitTestProcessor<ExecutableElement>() {
unitTestBuilder.when().passInElement().<ExecutableElement>fromClass(OnFluentApiMethodTestApi_InClass_error.class)
.intoUnitTest(new APTKUnitTestProcessor<ExecutableElement>() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, ExecutableElement element) {

Expand All @@ -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();
}

Expand Down Expand Up @@ -217,7 +224,8 @@ static void secondMethod(BackingBean backingBean) {

@Test
public void test_validate_twoMethodsInCommandClass() {
unitTestBuilder.<TypeElement>defineTestWithPassedInElement(MultipleMethodsInCommandClass.class, new APTKUnitTestProcessor<TypeElement>() {
unitTestBuilder.when().passInElement().<TypeElement>fromClass(MultipleMethodsInCommandClass.class)
.intoUnitTest(new APTKUnitTestProcessor<TypeElement>() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {

Expand All @@ -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();
}

Expand Down Expand Up @@ -272,7 +280,8 @@ static void secondMethod(BackingBean backingBean) {

@Test
public void test_validate_noMethodInCommandClass() {
unitTestBuilder.<TypeElement>defineTestWithPassedInElement(NoMethodInCommandClass.class, new APTKUnitTestProcessor<TypeElement>() {
unitTestBuilder.when().passInElement().<TypeElement>fromClass(NoMethodInCommandClass.class)
.intoUnitTest(new APTKUnitTestProcessor<TypeElement>() {
@Override
public void aptkUnitTest(ProcessingEnvironment processingEnvironment, TypeElement typeElement) {

Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand All @@ -49,15 +50,16 @@ private interface FluentInterface {
@Test
public void validationTest_NoRoot() {

unitTestBuilder.<TypeElement>defineTestWithPassedInElement(NotAccessibleTestApi.class, new APTKUnitTestProcessor<TypeElement>() {
unitTestBuilder.when().passInElement().<TypeElement>fromClass(NotAccessibleTestApi.class)
.intoUnitTest(new APTKUnitTestProcessor<TypeElement>() {
@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();


Expand All @@ -82,21 +84,19 @@ static class FluentInterface {
@Test
public void validationTest_PlacedOnClass() {

unitTestBuilder.<TypeElement>defineTestWithPassedInElement(PlacedOnClassTestApi.class, new APTKUnitTestProcessor<TypeElement>() {
unitTestBuilder.when().passInElement().<TypeElement>fromClass(PlacedOnClassTestApi.class)
.intoUnitTest(new APTKUnitTestProcessor<TypeElement>() {
@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();


}




}
Loading

0 comments on commit ecd471f

Please sign in to comment.