diff --git a/coverage/pom.xml b/coverage/pom.xml index 823545e..19c0bf3 100644 --- a/coverage/pom.xml +++ b/coverage/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute cute-parent - 1.3.1 + 1.4.0 coverage diff --git a/cute/pom.xml b/cute/pom.xml index 85197d2..63f689d 100644 --- a/cute/pom.xml +++ b/cute/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.3.1 + 1.4.0 cute diff --git a/cute/src/main/java/io/toolisticon/cute/AbstractUnitTestAnnotationProcessorClass.java b/cute/src/main/java/io/toolisticon/cute/AbstractUnitTestAnnotationProcessorClass.java index 5c6d7e8..38f499a 100644 --- a/cute/src/main/java/io/toolisticon/cute/AbstractUnitTestAnnotationProcessorClass.java +++ b/cute/src/main/java/io/toolisticon/cute/AbstractUnitTestAnnotationProcessorClass.java @@ -43,8 +43,7 @@ protected Element getElement(Set elements) { if (elements.size() == 1) { return elements.iterator().next(); - } - if (elements.size() == 0) { + } else if (elements.isEmpty()) { throw new FailingAssertionException(Constants.Messages.UNIT_TEST_PRECONDITION_MUST_FIND_ONE_ELEMENT.produceMessage()); } else { @@ -57,7 +56,7 @@ protected Element getElement(Set elements) { } - if (filteredList.size() == 0) { + if (filteredList.isEmpty()) { throw new FailingAssertionException(Constants.Messages.UNIT_TEST_PRECONDITION_MUST_FIND_EXACTLY_ONE_ELEMENT.produceMessage(annotationTypeToUse.getCanonicalName())); } else if (filteredList.size() > 1) { throw new FailingAssertionException(Constants.Messages.UNIT_TEST_PRECONDITION_MUST_FIND_EXACTLY_ONE_ELEMENT_WITH_PASSIN_ANNOTATION.produceMessage()); @@ -69,10 +68,4 @@ protected Element getElement(Set elements) { } - protected void triggerError(String message) { - - this.processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, message); - - } - } diff --git a/cute/src/main/java/io/toolisticon/cute/AbstractUnitTestAnnotationProcessorWithPassIn.java b/cute/src/main/java/io/toolisticon/cute/AbstractUnitTestAnnotationProcessorWithPassIn.java index f7262f8..920ee3d 100644 --- a/cute/src/main/java/io/toolisticon/cute/AbstractUnitTestAnnotationProcessorWithPassIn.java +++ b/cute/src/main/java/io/toolisticon/cute/AbstractUnitTestAnnotationProcessorWithPassIn.java @@ -44,9 +44,7 @@ protected Element getPassedInElement() { List filteredElements = filterByAnnotation(allEnclosedElements); if (filteredElements.size() != 1) { - throw new FailingAssertionException(Constants.Messages.UNIT_TEST_PASS_IN_PRECONDITION_MUST_FIND_EXACTLY_ONE_ELEMENT.produceMessage(annotationTypeUsedForScan.getCanonicalName(), classToScan.getCanonicalName())); - } return filteredElements.get(0); diff --git a/cute/src/main/java/io/toolisticon/cute/AnnotationProcessorWrapper.java b/cute/src/main/java/io/toolisticon/cute/AnnotationProcessorWrapper.java index c526e85..54d6d5c 100644 --- a/cute/src/main/java/io/toolisticon/cute/AnnotationProcessorWrapper.java +++ b/cute/src/main/java/io/toolisticon/cute/AnnotationProcessorWrapper.java @@ -9,6 +9,7 @@ import javax.lang.model.element.AnnotationMirror; import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; +import javax.lang.model.element.PackageElement; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic; import java.util.HashSet; @@ -93,6 +94,9 @@ public boolean process(Set annotations, RoundEnvironment , e); } + // Exception has been found + expectedExceptionWasThrown = true; + } else { // Got unexpected exception @@ -107,13 +111,14 @@ public boolean process(Set annotations, RoundEnvironment } - // check in last round if expected exception has been thrown - if (roundEnv.processingOver() && expectedExceptionWasThrown && this.expectedThrownException != null) { + // check in last round if expected exception has been thrown - in this case trigger assertion error + if (roundEnv.processingOver() && !expectedExceptionWasThrown && this.expectedThrownException != null) { throw new FailingAssertionException( Constants.Messages.ASSERTION_EXPECTED_EXCEPTION_NOT_THROWN.produceMessage(this.expectedThrownException.getCanonicalName()) ); } + return returnValue; } @@ -177,23 +182,8 @@ public static AnnotationProcessorWrapper wrapProcessor(Cla static Set getWrappedProcessors(CuteApi.CompilerTestBB compilerTestBB) { - // return cached wrapped processors if available - - Set wrappedProcessors = new HashSet<>(); - - // need to add unit test processor - - - // TODO: THIS CASE HANDLES PROCESSOR INSTANCES - NORMALLY ONLY USED IN UNIT TESTS ?!? - /*- - for (Processor processor : compilerTestBB.processors()) { - - wrappedProcessors.add(AnnotationProcessorWrapper.wrapProcessor(processor, expectedThrownException)); - - } - */ if (compilerTestBB.testType() == CuteApi.TestType.UNIT && compilerTestBB.unitTest() != null) { Processor processor = null; @@ -210,13 +200,13 @@ static Set getWrappedProcessors(CuteApi.CompilerTest processor = new UnitTestAnnotationProcessorClassWithPassIn<>( compilerTestBB.passInConfiguration().getPassedInClass(), compilerTestBB.passInConfiguration().getAnnotationToScanFor() != null ? compilerTestBB.passInConfiguration().getAnnotationToScanFor() : PassIn.class, - (UnitTest) compilerTestBB.unitTest()); + (UnitTest) compilerTestBB.unitTest()); } else { // This is the legacy case processor = new UnitTestAnnotationProcessorClass<>( compilerTestBB.passInConfiguration() != null && compilerTestBB.passInConfiguration().getAnnotationToScanFor() != null ? compilerTestBB.passInConfiguration().getAnnotationToScanFor() : (compilerTestBB.passInConfiguration() != null && compilerTestBB.passInConfiguration().getPassInElement() ? PassIn.class : Constants.DEFAULT_ANNOTATION ), - (UnitTest) compilerTestBB.unitTest()); + (UnitTest) compilerTestBB.unitTest()); } } else if (compilerTestBB.unitTest() instanceof UnitTestWithoutPassIn) { @@ -227,7 +217,7 @@ static Set getWrappedProcessors(CuteApi.CompilerTest } else if (compilerTestBB.unitTest() instanceof UnitTestForTestingAnnotationProcessors) { - Processor processorUnderTest = null; + Processor processorUnderTest; try { processorUnderTest = compilerTestBB.passInConfiguration().getPassedInProcessor().getDeclaredConstructor().newInstance(); } catch (Exception e) { @@ -240,14 +230,14 @@ static Set getWrappedProcessors(CuteApi.CompilerTest Constants.DEFAULT_ANNOTATION, compilerTestBB.passInConfiguration().getPassedInClass(), compilerTestBB.passInConfiguration().getAnnotationToScanFor() != null ? compilerTestBB.passInConfiguration().getAnnotationToScanFor() : PassIn.class, - (UnitTestForTestingAnnotationProcessors) compilerTestBB.unitTest() + (UnitTestForTestingAnnotationProcessors) compilerTestBB.unitTest() ); } else { processor = new UnitTestAnnotationProcessorClassForTestingAnnotationProcessors<>( processorUnderTest, compilerTestBB.passInConfiguration().getAnnotationToScanFor() != null ? compilerTestBB.passInConfiguration().getAnnotationToScanFor() : (compilerTestBB.passInConfiguration().getPassInElement() ? PassIn.class : Constants.DEFAULT_ANNOTATION ), - (UnitTestForTestingAnnotationProcessors) compilerTestBB.unitTest()); + (UnitTestForTestingAnnotationProcessors) compilerTestBB.unitTest()); } @@ -263,7 +253,7 @@ static Set getWrappedProcessors(CuteApi.CompilerTest processor = new UnitTestAnnotationProcessorClassForTestingAnnotationProcessorsWithoutPassIn<>( processorUnderTest, Constants.DEFAULT_ANNOTATION, - (UnitTestForTestingAnnotationProcessorsWithoutPassIn) compilerTestBB.unitTest()); + (UnitTestForTestingAnnotationProcessorsWithoutPassIn) compilerTestBB.unitTest()); } @@ -276,24 +266,16 @@ static Set getWrappedProcessors(CuteApi.CompilerTest for (Class processorType : compilerTestBB.processors()) { try { - Processor processor = processorType.getDeclaredConstructor().newInstance(); + Processor processor = processorType.getDeclaredConstructor().newInstance(); wrappedProcessors.add(AnnotationProcessorWrapper.wrapProcessor(processor, compilerTestBB.getExceptionIsThrown())); } catch (Exception e) { - throw new IllegalArgumentException("Passed processor " + processorType.getCanonicalName() + " cannot be instantiated.", e); + throw new IllegalArgumentException(Constants.Messages.IAE_CANNOT_INSTANTIATE_PROCESSOR.produceMessage(processorType.getCanonicalName())); } } - // TODO: CURRENTLY NOT IMPLEMENTED WITH NEW FLUENT API - /*- - for (CompileTestConfiguration.ProcessorWithExpectedException processor : this.processorsWithExpectedExceptions) { - - wrappedProcessors.add(AnnotationProcessorWrapper.wrapProcessor(processor.processorType, processor.throwable != null ? processor.throwable : expectedThrownException)); - - } - */ return wrappedProcessors; diff --git a/cute/src/main/java/io/toolisticon/cute/CompilationResult.java b/cute/src/main/java/io/toolisticon/cute/CompilationResult.java index 7f6226a..a13dfd1 100644 --- a/cute/src/main/java/io/toolisticon/cute/CompilationResult.java +++ b/cute/src/main/java/io/toolisticon/cute/CompilationResult.java @@ -5,6 +5,7 @@ /** * Compilation result. + * For internal usage. *

* Allows access to DiagnosticCollector and FileManager used during compilation test. */ diff --git a/cute/src/main/java/io/toolisticon/cute/CompileTest.java b/cute/src/main/java/io/toolisticon/cute/CompileTest.java index e3f6854..88eca36 100644 --- a/cute/src/main/java/io/toolisticon/cute/CompileTest.java +++ b/cute/src/main/java/io/toolisticon/cute/CompileTest.java @@ -88,6 +88,7 @@ CompilationResult executeTest() { try { generatedClassesTest.doTests(cuteClassLoader); } catch (AssertionError e) { + // make sure AssertionErrors will pass throw e; } catch (Exception e) { throw new FailingAssertionException(Constants.Messages.MESSAGE_GOT_UNEXPECTED_EXCEPTION_DURING_CLASS_TEST_ERROR.produceMessage(generatedClassesTest, e.getMessage())); @@ -305,12 +306,12 @@ void checkMessages(DiagnosticCollector diagnostics) { for (Map.Entry> entry : compileMessageChecks.entrySet()) { - Set filteredDiagnostics = CompileTestUtilities.getDiagnosticByKind(diagnostics, entry.getKey()); + Set> filteredDiagnostics = CompileTestUtilities.getDiagnosticByKind(diagnostics, entry.getKey()); outer: for (CuteApi.CompilerMessageCheckBB messageToCheck : entry.getValue()) { - for (Diagnostic element : filteredDiagnostics) { + for (Diagnostic element : filteredDiagnostics) { String localizedMessage = element.getMessage(messageToCheck.withLocale()); @@ -326,7 +327,7 @@ void checkMessages(DiagnosticCollector diagnostics) { } case CONTAINS: default: { - if (!messageToCheck.getSearchString().stream().allMatch(e -> localizedMessage.contains(e))) { + if (!messageToCheck.getSearchString().stream().allMatch(localizedMessage::contains)) { continue; } } @@ -353,7 +354,7 @@ void checkMessages(DiagnosticCollector diagnostics) { } // Not found ==> assertion fails - throw new FailingAssertionException(Constants.Messages.MESSAGE_HAVENT_FOUND_MESSSAGE.produceMessage(messageToCheck.getSearchString(), messageToCheck.getKind().name())); + throw new FailingAssertionException(Constants.Messages.MESSAGE_HAVENT_FOUND_MESSSAGE.produceMessage(messageToCheck.getSearchString(), messageToCheck.getKind().name(), messageToCheck.toString())); } @@ -366,18 +367,12 @@ public Map> getCompilerMes Map> map = new HashMap<>(); for (CuteApi.CompilerMessageCheckBB compilerMessageCheck : compilerTestBB.compilerMessageChecks()) { - - List checkByKindList = map.get(compilerMessageCheck.getKind()); - if (checkByKindList == null) { - checkByKindList = new ArrayList<>(); - map.put(Diagnostic.Kind.valueOf(compilerMessageCheck.getKind().name()), checkByKindList); - - } - - checkByKindList.add(compilerMessageCheck); + map.computeIfAbsent(compilerMessageCheck.getKind().toDiagnosticsKind(),(k) -> new ArrayList<>()).add(compilerMessageCheck); } return map; } + + } diff --git a/cute/src/main/java/io/toolisticon/cute/CompileTestUtilities.java b/cute/src/main/java/io/toolisticon/cute/CompileTestUtilities.java index f7de0d6..67cc335 100644 --- a/cute/src/main/java/io/toolisticon/cute/CompileTestUtilities.java +++ b/cute/src/main/java/io/toolisticon/cute/CompileTestUtilities.java @@ -7,6 +7,7 @@ import javax.tools.JavaFileObject; import java.util.HashSet; import java.util.Set; +import java.util.stream.Collectors; /** * Some static utility functions. @@ -52,14 +53,7 @@ static String getAnnotationProcessorWasAppliedMessage(Processor processor) { */ static Set getMessages(DiagnosticCollector diagnostics, Diagnostic.Kind kind) { - Set messages = new HashSet<>(); - Set filteredDiagnostic = getDiagnosticByKind(diagnostics, kind); - - for (Diagnostic diagnostic : filteredDiagnostic) { - messages.add(diagnostic.getMessage(null)); - } - - return messages; + return getDiagnosticByKind(diagnostics,kind).stream().map(e -> e.getMessage(null)).collect(Collectors.toSet()); } @@ -70,17 +64,9 @@ static Set getMessages(DiagnosticCollector diagnostics, * @param kind the kind of the messages to return * @return a Set containing all Diagnostic element of passed kind, or an empty Set. */ - static Set getDiagnosticByKind(DiagnosticCollector diagnostics, Diagnostic.Kind kind) { - - Set filteredDiagnostics = new HashSet<>(); - - for (Diagnostic diagnostic : diagnostics.getDiagnostics()) { - if (kind == diagnostic.getKind()) { - filteredDiagnostics.add(diagnostic); - } - } + static Set> getDiagnosticByKind(DiagnosticCollector diagnostics, Diagnostic.Kind kind) { - return filteredDiagnostics; + return diagnostics.getDiagnostics().stream().filter(e -> e.getKind().equals(kind)).collect(Collectors.toSet()); } diff --git a/cute/src/main/java/io/toolisticon/cute/Constants.java b/cute/src/main/java/io/toolisticon/cute/Constants.java index 92630ce..03fc42a 100644 --- a/cute/src/main/java/io/toolisticon/cute/Constants.java +++ b/cute/src/main/java/io/toolisticon/cute/Constants.java @@ -65,7 +65,7 @@ public String getMessagePattern(){ public final static Message MESSAGE_FO_EXISTS_BUT_DOESNT_MATCH_MATCHER = new Message("Expected generated FileObject (%s) exists but doesn't match passed GeneratedFileObjectMatcher: %s"); public final static Message MESSAGE_PROCESSOR_HASNT_BEEN_APPLIED = new Message("Annotation processor %s hasn't been called! Please check that there's at least one source file using an annotation supported by the processor: %s"); - public final static Message MESSAGE_HAVENT_FOUND_MESSSAGE = new Message("Haven't found expected message string '%s' of kind %s!"); + public final static Message MESSAGE_HAVENT_FOUND_MESSSAGE = new Message("Haven't found expected compiler message string '%s' of kind '%s'! (Check configuration : %s)"); public final static Message MESSAGE_TECHNICAL_ERROR = new Message("TECHNICAL ERROR : %s"); diff --git a/cute/src/main/java/io/toolisticon/cute/CuteApi.java b/cute/src/main/java/io/toolisticon/cute/CuteApi.java index 969e2f4..95605fb 100644 --- a/cute/src/main/java/io/toolisticon/cute/CuteApi.java +++ b/cute/src/main/java/io/toolisticon/cute/CuteApi.java @@ -103,7 +103,7 @@ default List getNormalizedCompilerOptions() { for (String compilerOption : compilerOptions()) { if (compilerOption != null) { - for (String tokenizedCompilerOption : compilerOption.split("[ ]+")) { + for (String tokenizedCompilerOption : compilerOption.split(" +")) { if (!tokenizedCompilerOption.isEmpty()) { normalizedCompilerOptions.add(tokenizedCompilerOption); } @@ -153,15 +153,15 @@ public interface CompilerMessageCheckBB { @FluentApiBackingBeanField("searchString") List getSearchString(); + @FluentApiBackingBeanField("atSource") + String atSource(); + @FluentApiBackingBeanField("atLine") Integer atLine(); @FluentApiBackingBeanField("atColumn") Integer atColumn(); - @FluentApiBackingBeanField("atSource") - String atSource(); - @FluentApiBackingBeanField("withLocale") Locale withLocale(); @@ -177,11 +177,15 @@ public enum UnitTestType { } public enum CompilerMessageComparisonType { - CONTAINS, EQUALS; + CONTAINS, EQUALS } public enum CompilerMessageKind { NOTE, WARNING, MANDATORY_WARNING, ERROR; + + Diagnostic.Kind toDiagnosticsKind() { + return Diagnostic.Kind.valueOf(this.name()); + } } @@ -455,7 +459,7 @@ public interface UnitTestRootInterface { * Traverses to given section of unit test. * Allows to add source files, to define compiler options and java modules. * - * @return + * @return the next fluent api instance */ UnitTestGivenInterface given(); @@ -669,7 +673,7 @@ public interface PassInProcessorInterface { * Define unit test. * * @param unitTest the Unit test - * @return the next fluent inteface + * @return the next fluent interface */ @FluentApiImplicitValue(id = "getPassInType", value = "PROCESSOR", target = TargetBackingBean.NEXT) @FluentApiParentBackingBeanMapping(value = "passInConfiguration") @@ -803,7 +807,7 @@ public interface UnitTestInterface { /** * Executes the test. - * All AssertionError triggered inside the unit test will bepassed through to your unit test framework. + * All AssertionError triggered inside the unit test will be passed through to your unit test framework. */ @FluentApiCommand(ExecuteTestCommand.class) DoCustomAssertions executeTest(); @@ -823,7 +827,7 @@ public interface BlackBoxTestInterface { /** * Executes the test. - * All AssertionError triggered inside the unit test will bepassed through to your unit test framework. + * All AssertionError triggered inside the unit test will be passed through to your unit test framework. */ @FluentApiCommand(ExecuteTestCommand.class) DoCustomAssertions executeTest(); @@ -856,7 +860,7 @@ public interface BlackBoxTestOutcomeInterface { /** * Expect an Exception to be thrown. * This usually makes sense for unit tests rather than black box tests. - * + *

* Please keep in mind that it's discouraged for processors to throw exceptions. * Please catch them in your processor and convert them to compiler messages and maybe trigger a compiler error if needed. * @@ -910,7 +914,7 @@ public interface CompilerTestExpectThatInterface { /** - * Adds check that generated class exists or doesn't exist. + * Adds check that generated or just compiled class exists or doesn't exist. * * @param className the fully qualified class name * @return the next fluent interface @@ -1120,7 +1124,7 @@ default CompilerTestExpectAndThatInterface matches(ExpectedFileObjectMatcherKind /** * Sometimes it can become handy to even test the generated code. - * This method can used to do those tests. Compiled classes are provided via the {@link GeneratedClassesTest} interface. + * This method can be used to do those tests. Compiled classes are provided via the {@link GeneratedClassesTest} interface. * Be aware that the binary class names must be used to get classes ( '$' delimiter for inner types,...) * Test rely heavily on reflection api. * So please consider integration test projects for testing generated code if your code doesn't implement a precompiled interface. diff --git a/cute/src/main/java/io/toolisticon/cute/CuteClassLoaderImpl.java b/cute/src/main/java/io/toolisticon/cute/CuteClassLoaderImpl.java index f8e8142..8d73c28 100644 --- a/cute/src/main/java/io/toolisticon/cute/CuteClassLoaderImpl.java +++ b/cute/src/main/java/io/toolisticon/cute/CuteClassLoaderImpl.java @@ -1,9 +1,6 @@ package io.toolisticon.cute; import javax.tools.JavaFileObject; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -36,10 +33,10 @@ public CuteClassLoaderImpl(CompileTestFileManager compileTestFileManager) { static String convertJavaFileObjectNameToBinaryClassName(JavaFileObject javaFileObject) { - Pattern pattern = Pattern.compile("^[/](.*)[.]class$"); + Pattern pattern = Pattern.compile("^/(.*)[.]class$"); Matcher matcher = pattern.matcher(javaFileObject.getName()); if (matcher.matches()) { - return matcher.group(1).replaceAll("[/]", "."); + return matcher.group(1).replaceAll("/", "."); } throw new IllegalStateException("Got invalid name : " + javaFileObject.getName()); } @@ -48,7 +45,7 @@ static String convertJavaFileObjectNameToBinaryClassName(JavaFileObject javaFile protected Class findClass(String name) throws ClassNotFoundException { if (!classMap.containsKey(name)) { - throw new ClassNotFoundException("Couldnt't find class : " + name); + throw new ClassNotFoundException("Couldn't find class : " + name); } CompileTestFileManager.InMemoryOutputJavaFileObject javaFileObject = classMap.get(name); diff --git a/cute/src/main/java/io/toolisticon/cute/DebugOutputGenerator.java b/cute/src/main/java/io/toolisticon/cute/DebugOutputGenerator.java index c025ee8..5b13c09 100644 --- a/cute/src/main/java/io/toolisticon/cute/DebugOutputGenerator.java +++ b/cute/src/main/java/io/toolisticon/cute/DebugOutputGenerator.java @@ -5,6 +5,7 @@ import javax.tools.Diagnostic; import javax.tools.FileObject; +import javax.tools.JavaFileObject; import java.io.File; import java.io.FileFilter; import java.io.FileOutputStream; @@ -116,12 +117,12 @@ public boolean accept(File pathname) { private static String getDebugMessages(CompilationResult compilationResult, Diagnostic.Kind kind) { StringBuilder stringBuilder = new StringBuilder(); - Set filteredDiagnostics = CompileTestUtilities.getDiagnosticByKind(compilationResult.getDiagnostics(), kind); + Set> filteredDiagnostics = CompileTestUtilities.getDiagnosticByKind(compilationResult.getDiagnostics(), kind); if (!filteredDiagnostics.isEmpty()) { stringBuilder.append(getDebugOutputHeader(kind.toString() + " MESSAGES")); int i = 1; - for (Diagnostic diagnostics : filteredDiagnostics) { + for (Diagnostic diagnostics : filteredDiagnostics) { stringBuilder.append("[").append(i) @@ -212,7 +213,7 @@ private static String writeFile(String pathPrefix, FileObject fileObject) { try { fos.close(); } catch (IOException e) { - + // ignore it } } @@ -220,7 +221,7 @@ private static String writeFile(String pathPrefix, FileObject fileObject) { try { is.close(); } catch (IOException e) { - + // ignore it } } } diff --git a/cute/src/main/java/io/toolisticon/cute/FileObjectUtils.java b/cute/src/main/java/io/toolisticon/cute/FileObjectUtils.java index b885b27..747c658 100644 --- a/cute/src/main/java/io/toolisticon/cute/FileObjectUtils.java +++ b/cute/src/main/java/io/toolisticon/cute/FileObjectUtils.java @@ -30,7 +30,7 @@ public String getName() { } @Override - public OutputStream openOutputStream() throws IOException { + public OutputStream openOutputStream() { throw new UnsupportedOperationException(); } @@ -96,12 +96,6 @@ public InputStream openInputStream() throws IOException { return FileObjectUtils.class.getResourceAsStream(resource); } - @Override - public OutputStream openOutputStream() throws IOException { - throw new UnsupportedOperationException(); - } - - @Override public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { @@ -117,8 +111,7 @@ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOExcept } buffer.flush(); - byte[] byteArray = buffer.toByteArray(); - return new String(byteArray); + return buffer.toString(); } diff --git a/cute/src/main/java/io/toolisticon/cute/UnitTestWithoutPassIn.java b/cute/src/main/java/io/toolisticon/cute/UnitTestWithoutPassIn.java index bb98c3b..9614a59 100644 --- a/cute/src/main/java/io/toolisticon/cute/UnitTestWithoutPassIn.java +++ b/cute/src/main/java/io/toolisticon/cute/UnitTestWithoutPassIn.java @@ -4,7 +4,7 @@ /** * Interface that is used during unit test creation. It allows setting up a unit test without the need to create a valid annotation processor. - *

*

+ * * Please use {@link UnitTestForTestingAnnotationProcessors} if you want to unit test annotation processor methods. */ public interface UnitTestWithoutPassIn extends UnitTestBase{ diff --git a/cute/src/test/java/io/toolisticon/cute/AnnotationProcessorWrapperTest.java b/cute/src/test/java/io/toolisticon/cute/AnnotationProcessorWrapperTest.java index 1e7d4b8..b8a27d6 100644 --- a/cute/src/test/java/io/toolisticon/cute/AnnotationProcessorWrapperTest.java +++ b/cute/src/test/java/io/toolisticon/cute/AnnotationProcessorWrapperTest.java @@ -1,10 +1,6 @@ package io.toolisticon.cute; -import io.toolisticon.cute.AnnotationProcessorWrapper; -import io.toolisticon.cute.Cute; -import io.toolisticon.cute.TestAnnotation; -import io.toolisticon.cute.UnitTestWithoutPassIn; import io.toolisticon.cute.testcases.TestAnnotationProcessor; import io.toolisticon.cute.testcases.TestAnnotationProcessorWithMissingNoArgConstructor; import org.hamcrest.MatcherAssert; @@ -35,15 +31,14 @@ public void createWrapperWithInstance() { Processor unit = AnnotationProcessorWrapper.wrapProcessor(TestAnnotationProcessor.class); - MatcherAssert.assertThat("Must return non null valued Processor", unit != null); + MatcherAssert.assertThat("Must return non null valued Processor", unit, Matchers.notNullValue()); } @Test(expected = IllegalArgumentException.class) public void createWrapperWithNullValuedInstance() { - Processor unit = AnnotationProcessorWrapper.wrapProcessor((AbstractProcessor) null); - + AnnotationProcessorWrapper.wrapProcessor((AbstractProcessor) null); } @@ -51,8 +46,7 @@ public void createWrapperWithNullValuedInstance() { public void createWrapperWithType() { Processor unit = AnnotationProcessorWrapper.wrapProcessor(TestAnnotationProcessor.class); - - MatcherAssert.assertThat("Must return non null valued Processor", unit != null); + MatcherAssert.assertThat("Must return non null valued Processor", unit, Matchers.notNullValue()); } @@ -60,8 +54,7 @@ public void createWrapperWithType() { public void createWrapperWithTypeAndException() { Processor unit = AnnotationProcessorWrapper.wrapProcessor(TestAnnotationProcessor.class, IllegalStateException.class); - - MatcherAssert.assertThat("Must return non null valued Processor", unit != null); + MatcherAssert.assertThat("Must return non null valued Processor", unit, Matchers.notNullValue()); } @@ -185,7 +178,7 @@ public void testWrappedProcessCall() { unit.init(processingEnvironment); - Set set = new HashSet(); + Set set = new HashSet<>(); RoundEnvironment roundEnvironment = Mockito.mock(RoundEnvironment.class); @@ -251,8 +244,8 @@ public void process_testExpectedExceptionIsThrown_assertionShouldSucceed() { Cute.unitTest().when(processingEnvironment -> { - throw new IllegalArgumentException(); - }) + throw new IllegalArgumentException(); + }) .thenExpectThat().exceptionIsThrown(IllegalArgumentException.class) .executeTest(); @@ -263,30 +256,27 @@ public void process_testExpectedExceptionIsThrown_assertionShouldSucceed() { public void process_testExpectedExceptionNotThrown_assertionShouldFail() { try { - Cute.unitTest().when(new UnitTestWithoutPassIn() { - @Override - public void unitTest(ProcessingEnvironment processingEnvironment) { + Cute.unitTest().when(processingEnvironment -> { - } - }) + }) .thenExpectThat().exceptionIsThrown(IllegalArgumentException.class) .executeTest(); - } catch (Exception e) { + } catch (AssertionError e) { MatcherAssert.assertThat(e.getMessage(), Matchers.containsString("Expected exception of type 'java.lang.IllegalArgumentException'")); + return; } + MatcherAssert.assertThat("Expected assertion error wasn't triggered", false); + } @Test public void process_testUnexpectedExceptionWasThrown_assertionShouldFail() { try { - Cute.unitTest().when(new UnitTestWithoutPassIn() { - @Override - public void unitTest(ProcessingEnvironment processingEnvironment) { - throw new IllegalStateException(); - } - }) + Cute.unitTest().when(processingEnvironment -> { + throw new IllegalStateException(); + }) .thenExpectThat().exceptionIsThrown(IllegalArgumentException.class) .executeTest(); } catch (Throwable e) { diff --git a/cute/src/test/java/io/toolisticon/cute/CompileTestFileManagerTest.java b/cute/src/test/java/io/toolisticon/cute/CompileTestFileManagerTest.java index a8b8f0e..4db36de 100644 --- a/cute/src/test/java/io/toolisticon/cute/CompileTestFileManagerTest.java +++ b/cute/src/test/java/io/toolisticon/cute/CompileTestFileManagerTest.java @@ -58,21 +58,19 @@ public void test_InMemoryOutputStream_callBackCalledCorrectly() throws IOExcepti private StandardJavaFileManager standardJavaFileManager = Mockito.mock(StandardJavaFileManager.class); @Test - public void test_InMemoryOutputJavaFileObject_setContent_nullValued() throws IOException, URISyntaxException { + public void test_InMemoryOutputJavaFileObject_setContent_nullValued() { - CompileTestFileManager compileTestFileManager = new CompileTestFileManager(standardJavaFileManager); CompileTestFileManager.AbstractInMemoryOutputFileObject unit = new CompileTestFileManager.InMemoryOutputFileObject(StandardLocation.CLASS_OUTPUT,"io.toolisticon.cute","abc"); unit.setContent(null); - MatcherAssert.assertThat((String) unit.getCharContent(false), Matchers.isEmptyString()); + MatcherAssert.assertThat((String) unit.getCharContent(false), Matchers.is(Matchers.emptyString())); } @Test - public void test_InMemoryOutputJavaFileObject_setContent() throws IOException, URISyntaxException { + public void test_InMemoryOutputJavaFileObject_setContent() { - CompileTestFileManager compileTestFileManager = new CompileTestFileManager(standardJavaFileManager); CompileTestFileManager.AbstractInMemoryOutputFileObject unit = new CompileTestFileManager.InMemoryOutputFileObject(StandardLocation.CLASS_OUTPUT,"io.toolisticon.cute","abc"); unit.setContent("ABC".getBytes()); @@ -82,9 +80,8 @@ public void test_InMemoryOutputJavaFileObject_setContent() throws IOException, U } @Test - public void test_InMemoryOutputJavaFileObject_openReader() throws IOException, URISyntaxException { + public void test_InMemoryOutputJavaFileObject_openReader() throws IOException { - CompileTestFileManager compileTestFileManager = new CompileTestFileManager(standardJavaFileManager); CompileTestFileManager.AbstractInMemoryOutputFileObject unit = new CompileTestFileManager.InMemoryOutputFileObject(StandardLocation.CLASS_OUTPUT,"io.toolisticon.cute","abc"); unit.setContent("ABC".getBytes()); @@ -104,7 +101,7 @@ public void test_InMemoryOutputJavaFileObject_openReader() throws IOException, U @Test public void test_FileObjectCache() throws URISyntaxException { - CompileTestFileManager.FileObjectCache unit = new CompileTestFileManager.FileObjectCache(); + CompileTestFileManager.FileObjectCache unit = new CompileTestFileManager.FileObjectCache<>(); JavaFileObject javaFileObject = Mockito.mock(JavaFileObject.class); diff --git a/cute/src/test/java/io/toolisticon/cute/CompileTestUtilitiesTest.java b/cute/src/test/java/io/toolisticon/cute/CompileTestUtilitiesTest.java index 4740a37..8319c78 100644 --- a/cute/src/test/java/io/toolisticon/cute/CompileTestUtilitiesTest.java +++ b/cute/src/test/java/io/toolisticon/cute/CompileTestUtilitiesTest.java @@ -1,6 +1,5 @@ package io.toolisticon.cute; -import io.toolisticon.cute.CompileTestUtilities; import io.toolisticon.cute.common.SimpleTestProcessor1; import org.hamcrest.MatcherAssert; import org.hamcrest.Matchers; @@ -36,7 +35,7 @@ public void getAnnotationProcessorWasAppliedMessage_concreteProcessor() { } @Test - public void getAnnotationProcessorWasAppliedMessage_anynomousProcessor_class() { + public void getAnnotationProcessorWasAppliedMessage_anonymousProcessor_class() { Processor processor = new AbstractProcessor() { @Override @@ -49,16 +48,16 @@ public boolean process(Set annotations, RoundEnvironment CompileTestUtilities.getAnnotationProcessorWasAppliedMessage(processor), Matchers.equalTo( CompileTestUtilities.TEMPLATE_ANNOTATION_PROCESSOR_WAS_APPLIED.replaceFirst( - "[%]s", - CompileTestUtilities.ANONYMOUS_CLASS.replaceFirst("[%]s", AbstractProcessor.class.getCanonicalName()) - ) + "[%]s", + CompileTestUtilities.ANONYMOUS_CLASS.replaceFirst("[%]s", AbstractProcessor.class.getCanonicalName()) + ) .replaceFirst("[%]s", "" + System.identityHashCode(processor)) ) ); } @Test - public void getAnnotationProcessorWasAppliedMessage_anynomousProcessor_interface() { + public void getAnnotationProcessorWasAppliedMessage_anonymousProcessor_interface() { Processor processor = new Processor() { @Override @@ -97,12 +96,12 @@ public Iterable getCompletions(Element element, Annotation Matchers.equalTo( CompileTestUtilities.TEMPLATE_ANNOTATION_PROCESSOR_WAS_APPLIED.replaceFirst( - "[%]s", - CompileTestUtilities.ANONYMOUS_CLASS - .replaceFirst("[%]s", Processor.class.getCanonicalName() - ) + "[%]s", + CompileTestUtilities.ANONYMOUS_CLASS + .replaceFirst("[%]s", Processor.class.getCanonicalName() + ) - ) + ) .replaceFirst("[%]s", "" + System.identityHashCode(processor) ) ) diff --git a/cute/src/test/java/io/toolisticon/cute/CompilerMessageCheckTest.java b/cute/src/test/java/io/toolisticon/cute/CompilerMessageCheckTest.java index d60e13c..3c5060d 100644 --- a/cute/src/test/java/io/toolisticon/cute/CompilerMessageCheckTest.java +++ b/cute/src/test/java/io/toolisticon/cute/CompilerMessageCheckTest.java @@ -1,13 +1,8 @@ package io.toolisticon.cute; -import io.toolisticon.cute.CuteApi; -import io.toolisticon.cute.Cute; -import io.toolisticon.cute.UnitTest; -import io.toolisticon.cute.UnitTestForTestingAnnotationProcessors; import io.toolisticon.cute.common.SimpleTestProcessor1; import org.junit.Test; -import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic; @@ -23,12 +18,7 @@ public void testComplexCompilerMessageCheck_findMessage_withAll() { builder.when() .passInElement().fromSourceFile("/AnnotationProcessorUnitTestTestClass.java") - .intoUnitTest(new UnitTest() { - @Override - public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement element) { - processingEnvironment.getMessager().printMessage(Diagnostic.Kind.WARNING, "ABC", element); - } - }) + .intoUnitTest((processingEnvironment, element) -> processingEnvironment.getMessager().printMessage(Diagnostic.Kind.WARNING, "ABC", element)) .thenExpectThat().compilationSucceeds() .andThat().compilerMessage().ofKindWarning().atSource("/AnnotationProcessorUnitTestTestClass.java").atLine(13).atColumn(8).equals("ABC") .executeTest(); @@ -38,12 +28,7 @@ public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement el public void testComplexCompilerMessageCheck_dontFindMessage_withAll_wrongSource() { builder.when().passInElement().fromSourceFile("/AnnotationProcessorUnitTestTestClass.java") - .intoUnitTest(new UnitTest() { - @Override - public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement element) { - processingEnvironment.getMessager().printMessage(Diagnostic.Kind.WARNING, "ABC", element); - } - }) + .intoUnitTest((processingEnvironment, element) -> processingEnvironment.getMessager().printMessage(Diagnostic.Kind.WARNING, "ABC", element)) .thenExpectThat().compilationSucceeds() .andThat().compilerMessage().ofKindWarning().atSource("/XYZ.java").atLine(15).atColumn(8).equals("ABC") .executeTest(); @@ -54,12 +39,7 @@ public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement el public void testComplexCompilerMessageCheck_dontFindMessage_withAll_wrongLine() { builder.when().passInElement().fromSourceFile("/AnnotationProcessorUnitTestClass.java") - .intoUnitTest(new UnitTest() { - @Override - public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement element) { - processingEnvironment.getMessager().printMessage(Diagnostic.Kind.WARNING, "ABC", element); - } - }).thenExpectThat().compilationSucceeds() + .intoUnitTest((processingEnvironment, element) -> processingEnvironment.getMessager().printMessage(Diagnostic.Kind.WARNING, "ABC", element)).thenExpectThat().compilationSucceeds() .andThat().compilerMessage().ofKindWarning().atSource("/AnnotationProcessorUnitTestClass.java").atLine(3).atColumn(8).equals("ABC") .executeTest(); @@ -69,12 +49,7 @@ public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement el public void testComplexCompilerMessageCheck_dontFindMessage_withAll_wrongColumn() { builder.when().passInElement().fromSourceFile("/AnnotationProcessorUnitTestClass.java") - .intoUnitTest(new UnitTest() { - @Override - public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement element) { - processingEnvironment.getMessager().printMessage(Diagnostic.Kind.WARNING, "ABC", element); - } - }).thenExpectThat().compilationSucceeds() + .intoUnitTest((processingEnvironment, element) -> processingEnvironment.getMessager().printMessage(Diagnostic.Kind.WARNING, "ABC", element)).thenExpectThat().compilationSucceeds() .andThat().compilerMessage().ofKindWarning().atSource("/AnnotationProcessorUnitTestClass.java").atLine(13).atColumn(7).equals("ABC") .executeTest(); @@ -85,12 +60,7 @@ public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement el public void testComplexCompilerMessageCheck_dontFindMessage_withAll_wrongMessage() { builder.when().passInElement().fromSourceFile("/AnnotationProcessorUnitTestClass.java") - .intoUnitTest(new UnitTest() { - @Override - public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement element) { - processingEnvironment.getMessager().printMessage(Diagnostic.Kind.WARNING, "ABC", element); - } - }).thenExpectThat().compilationSucceeds() + .intoUnitTest((processingEnvironment, element) -> processingEnvironment.getMessager().printMessage(Diagnostic.Kind.WARNING, "ABC", element)).thenExpectThat().compilationSucceeds() .andThat().compilerMessage().ofKindWarning().atSource("/AnnotationProcessorUnitTestClass.java").atLine(13).atColumn(8).equals("BC") .executeTest(); @@ -101,31 +71,11 @@ public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement el public void testComplexCompilerMessageCheck_findMessageSubstring_withAll() { builder.when().passInElement().fromSourceFile("/AnnotationProcessorUnitTestTestClass.java") - .intoUnitTest(new UnitTest() { - @Override - public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement element) { - processingEnvironment.getMessager().printMessage(Diagnostic.Kind.WARNING, "ABC", element); - } - }).thenExpectThat().compilationSucceeds() + .intoUnitTest((processingEnvironment, element) -> processingEnvironment.getMessager().printMessage(Diagnostic.Kind.WARNING, "ABC", element)).thenExpectThat().compilationSucceeds() .andThat().compilerMessage().ofKindWarning().atSource("/AnnotationProcessorUnitTestTestClass.java").atLine(13).atColumn(8).contains("BC") .executeTest(); } - public void xyx(){ - builder.when() - .passInProcessor(SimpleTestProcessor1.class) - .andPassInElement().fromSourceFile("/AnnotationProcessorUnitTestClass.java") - .intoUnitTest(new UnitTestForTestingAnnotationProcessors() { - @Override - public void unitTest(SimpleTestProcessor1 unit, ProcessingEnvironment processingEnvironment, TypeElement element) { - - } - }) - .thenExpectThat() - .compilationSucceeds() - .andThat().compilerMessage().ofKindWarning().atSource("/AnnotationProcessorUnitTestClass.java").atLine(13).atColumn(8).contains("BC") - .executeTest(); - } } diff --git a/cute/src/test/java/io/toolisticon/cute/CuteTest.java b/cute/src/test/java/io/toolisticon/cute/CuteTest.java index d32d395..b799629 100644 --- a/cute/src/test/java/io/toolisticon/cute/CuteTest.java +++ b/cute/src/test/java/io/toolisticon/cute/CuteTest.java @@ -12,7 +12,6 @@ import javax.annotation.processing.ProcessingEnvironment; import javax.annotation.processing.Processor; -import javax.lang.model.element.Element; import javax.lang.model.element.ExecutableElement; import javax.lang.model.element.TypeElement; import javax.tools.Diagnostic; @@ -24,7 +23,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Optional; /** * Unit tests for {@link Cute}. @@ -33,34 +31,29 @@ public class CuteTest { @Test - public void test_UnitTest_successfulCompilation_build() throws IOException { + public void test_UnitTest_successfulCompilation_build() { - JavaFileObject testSource = Mockito.mock(JavaFileObject.class); - JavaFileObject expectedGeneratedSource = JavaFileObjectUtils.readFromString("Jupp.txt", "TATA!"); Cute .unitTest() .when( - new UnitTestWithoutPassIn() { - @Override - public void unitTest(ProcessingEnvironment processingEnvironment) { - - processingEnvironment.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, "MANDATORY_WARNING"); - processingEnvironment.getMessager().printMessage(Diagnostic.Kind.WARNING, "WARNING"); - processingEnvironment.getMessager().printMessage(Diagnostic.Kind.NOTE, "NOTE"); - + processingEnvironment -> { - try { - FileObject fileObject = processingEnvironment.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "root", "Jupp.txt"); - Writer writer = fileObject.openWriter(); - writer.write("TATA!"); - writer.close(); + processingEnvironment.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING, "MANDATORY_WARNING"); + processingEnvironment.getMessager().printMessage(Diagnostic.Kind.WARNING, "WARNING"); + processingEnvironment.getMessager().printMessage(Diagnostic.Kind.NOTE, "NOTE"); - } catch (IOException e) { + try { + FileObject fileObject = processingEnvironment.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "root", "Jupp.txt"); + Writer writer = fileObject.openWriter(); + writer.write("TATA!"); + writer.close(); - } + } catch (IOException e) { + // ignore } + }) .thenExpectThat().compilationSucceeds() .andThat().compilerMessage().ofKindWarning().contains("WARNING") @@ -68,10 +61,10 @@ public void unitTest(ProcessingEnvironment processingEnvironment) { .andThat().compilerMessage().ofKindNote().contains("NOTE") .executeTest().executeCustomAssertions(e -> { MatcherAssert.assertThat("Compilation should be successful", e.compilationWasSuccessful()); - MatcherAssert.assertThat("Expected to find warning message that contains WARNING", !(e.getCompilerMessages().stream().filter(f -> f.getKind() == Diagnostic.Kind.WARNING).filter(f -> f.getMessage().contains("WARNING")).count() == 0)); - MatcherAssert.assertThat("Should not find generated SOURCE FILES", e.getFileManager().getJavaFileObjects().stream().filter(f -> f.getKind() == JavaFileObject.Kind.SOURCE).count() == 0); + MatcherAssert.assertThat("Expected to find warning message that contains WARNING", e.getCompilerMessages().stream().filter(f -> f.getKind() == Diagnostic.Kind.WARNING).anyMatch(f -> f.getMessage().contains("WARNING"))); + MatcherAssert.assertThat("Should not find generated SOURCE FILES", e.getFileManager().getJavaFileObjects().stream().noneMatch(f -> f.getKind() == JavaFileObject.Kind.SOURCE)); MatcherAssert.assertThat("Should find generated RESOURCE file that contains TATA", e.getFileManager().getFileObjects().stream().filter(f -> f.getName().equals("/root/Jupp.txt")).filter(f -> - f.getContent().toString().contains("TATA") + f.getContent().contains("TATA") ).count() == 1); MatcherAssert.assertThat("Should be true", true); @@ -83,6 +76,54 @@ public void unitTest(ProcessingEnvironment processingEnvironment) { } + @Test + public void test_compilationWithCompilerOptions_happyPath() { + Cute.blackBoxTest().given().noProcessors() + .andSourceFiles("/compiletests/compileroptionstest/Java8Code.java") + .andUseCompilerOptions("-source 1.8", "-target 1.8") + .whenCompiled().thenExpectThat().compilationSucceeds() + .andThat().generatedClass("io.toolisticon.cute.testcases.Java8Code").exists() + .executeTest(); + } + + @Test + public void test_compilationWithCompilerOptions_invalidUsageOfJava8Code() { + if (getJavaVersion() <= 17) { + Cute.blackBoxTest().given().noProcessors() + .andSourceFiles("/compiletests/compileroptionstest/Java8Code.java") + .andUseCompilerOptions("-source 1.7", "-target 1.7") + .whenCompiled().thenExpectThat().compilationFails() + .andThat().compilerMessage().ofKindError().atSource("/compiletests/compileroptionstest/Java8Code.java").atLine(10).atColumn(56).contains("lambda expressions are not supported") + .andThat().generatedClass("io.toolisticon.cute.testcases.Java8Code").doesntExist() + .executeTest(); + } + } + + + private static int getJavaVersion() { + String version = System.getProperty("java.version"); + if (version.startsWith("1.")) { + version = version.substring(2, 3); + } else { + int dot = version.indexOf("."); + if (dot != -1) { + version = version.substring(0, dot); + } + } + return Integer.parseInt(version); + } + + @Test + public void test_addSourceFromString() { + Cute.blackBoxTest().given() + .noProcessors() + .andSourceFile("io.toolisticon.cute.Testclass", "package io.toolisticon.cute; public class Testclass{}") + .whenCompiled().thenExpectThat().compilationSucceeds() + .andThat().generatedClass("io.toolisticon.cute.Testclass").exists() + .executeTest(); + } + + @Test public void test_testGenerationOfClassAndCustomAssertions() { @@ -117,14 +158,7 @@ public void test_UnitTest_successfulCompilation_withInitializedProcessorUnderTes Cute.unitTest() .when().passInProcessor(SimpleTestProcessor1.class) - .intoUnitTest(new UnitTestForTestingAnnotationProcessorsWithoutPassIn() { - @Override - public void unitTest(SimpleTestProcessor1 unit, ProcessingEnvironment processingEnvironment) { - - MatcherAssert.assertThat(unit.getProcessingEnvironment(), Matchers.equalTo(processingEnvironment)); - - } - }) + .intoUnitTest((unit, processingEnvironment) -> MatcherAssert.assertThat(unit.getProcessingEnvironment(), Matchers.equalTo(processingEnvironment))) .thenExpectThat().compilationSucceeds() .executeTest(); } @@ -143,14 +177,11 @@ public void test_UnitTest_successfulCompilation_withInitializedProcessorUnderTes .when() .passInProcessor(SimpleTestProcessor1.class) .andPassInElement().fromClass(PassInProcessorAndElement.class) - .intoUnitTest(new UnitTestForTestingAnnotationProcessors() { - @Override - public void unitTest(SimpleTestProcessor1 unit, ProcessingEnvironment processingEnvironment, TypeElement typeElement) { + .intoUnitTest((unit, processingEnvironment, typeElement) -> { - MatcherAssert.assertThat(typeElement, Matchers.notNullValue()); - MatcherAssert.assertThat(typeElement.getQualifiedName().toString(), Matchers.is(PassInProcessorAndElement.class.getCanonicalName())); + MatcherAssert.assertThat(typeElement, Matchers.notNullValue()); + MatcherAssert.assertThat(typeElement.getQualifiedName().toString(), Matchers.is(PassInProcessorAndElement.class.getCanonicalName())); - } }) .thenExpectThat() .compilationSucceeds() @@ -159,34 +190,6 @@ public void unitTest(SimpleTestProcessor1 unit, ProcessingEnvironment processing } - /** - * @Retention(RetentionPolicy.RUNTIME) private static @interface CustomPassInAnnotation { - *

- * } - * @CustomPassInAnnotation private static class PassInProcessorAndElementWithCustomAnnotation { - *

- * } - * @Test public void test_UnitTest_successfulCompilation_withInitializedProcessorUnderTestAndPassInWithCustomAnnotation_build() { - *

- * CuteFluentApiStarter - * .unitTest() - * .when() - * .passInProcessor(SimpleTestProcessor1.class) - * .andPassInElement().fromClass(PassInProcessorAndElementWithCustomAnnotation.class) - * .defineTestWithPassedInElement(SimpleTestProcessor1.class, PassInProcessorAndElementWithCustomAnnotation.class, CustomPassInAnnotation.class, new UnitTestForTestingAnnotationProcessors() { - * @Override public void unitTest(SimpleTestProcessor1 unit, ProcessingEnvironment processingEnvironment, TypeElement typeElement) { - *

- * MatcherAssert.assertThat(typeElement, Matchers.notNullValue()); - * MatcherAssert.assertThat(typeElement.getQualifiedName().toString(), Matchers.is(PassInProcessorAndElementWithCustomAnnotation.class.getCanonicalName())); - *

- * } - * }) - * .compilationShouldSucceed() - * .executeTest(); - *

- *

- * } - */ @Test public void test_UnitTest_failingCompilation_build() { @@ -212,6 +215,8 @@ public void unitTest(ProcessingEnvironment processingEnvironment) { } /*- + // Unfortunately these tests can not be done at the moment because the is no access to the compiletest configuration ! + private void assertCompilerMessages(Set compilerMessageChecks, Diagnostic.Kind kind, CompileTestConfiguration.ComparisonKind comparisonKind, String... expectedMessages) { List configuredExpectedMessages = new ArrayList<>(); @@ -756,12 +761,9 @@ public void test_passInViaSourceCode_multipleAnnotated_withOnePassIn() { .unitTest() .when() .passInElement().fromSourceFile("/compiletests/passintest/PassInTestClass.java") - .intoUnitTest(new UnitTest() { - @Override - public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement element) { - MatcherAssert.assertThat(element, Matchers.notNullValue()); - MatcherAssert.assertThat(element.getSimpleName().toString(), Matchers.is("InnerTestClass")); - } + .intoUnitTest((processingEnvironment, element) -> { + MatcherAssert.assertThat(element, Matchers.notNullValue()); + MatcherAssert.assertThat(element.getSimpleName().toString(), Matchers.is("InnerTestClass")); }) .executeTest(); @@ -775,11 +777,8 @@ public void test_passInViaSourceCode_multipleAnnotated_withoutPassIn() { .unitTest() .when() .passInElement().fromSourceFile("/compiletests/passintest/PassInTestClassMultipleAnnotatedWithoutPassIn.java") - .intoUnitTest(new UnitTest() { - @Override - public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement element) { - throw new AssertionError("should have thrown assertion error!"); - } + .intoUnitTest((processingEnvironment, element) -> { + throw new AssertionError("should have thrown assertion error!"); }) .executeTest(); @@ -800,11 +799,8 @@ public void test_passInViaSourceCode_multipleAnnotated_withMultiplePassIn() { .unitTest() .when() .passInElement().fromSourceFile("/compiletests/passintest/PassInTestClassMultipleAnnotatedWithMultiplePassIn.java") - .intoUnitTest(new UnitTest() { - @Override - public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement element) { - throw new AssertionError("should have thrown assertion error!"); - } + .intoUnitTest((processingEnvironment, element) -> { + throw new AssertionError("should have thrown assertion error!"); }) .executeTest(); @@ -827,11 +823,8 @@ public void test_passInViaSourceCode_withNonMatchingElementType() { .useSourceFile("/compiletests/passintest/PassInTestClass.java") .when() .passInElement().fromGivenSourceFiles() - .intoUnitTest(new UnitTest() { - @Override - public void unitTest(ProcessingEnvironment processingEnvironment, ExecutableElement element) { - throw new AssertionError("should have thrown assertion error!"); - } + .intoUnitTest((processingEnvironment, element) -> { + throw new AssertionError("should have thrown assertion error!"); }) .executeTest(); @@ -854,11 +847,8 @@ public void test_passInViaSourceCode_withProcessorPassIn_withMatchingElementButC .when() .passInElement().fromGivenSourceFiles() .andPassInProcessor(SimpleTestProcessor1.class) - .intoUnitTest(new UnitTestForTestingAnnotationProcessors() { - @Override - public void unitTest(SimpleTestProcessor1 unit, ProcessingEnvironment processingEnvironment, TypeElement element) { - throw new ClassCastException("Test Class Cast Exception"); - } + .intoUnitTest((unit, processingEnvironment, element) -> { + throw new ClassCastException("Test Class Cast Exception"); }) .thenExpectThat() .exceptionIsThrown(ClassCastException.class) @@ -880,11 +870,8 @@ public void test_passIn_withNonMatchingElementType() { .unitTest() .when() .passInElement().fromClass(PassInClass.class) - .intoUnitTest(new UnitTest() { - @Override - public void unitTest(ProcessingEnvironment processingEnvironment, ExecutableElement element) { - throw new AssertionError("should have thrown assertion error!"); - } + .intoUnitTest((processingEnvironment, element) -> { + throw new AssertionError("should have thrown assertion error!"); }) .executeTest(); @@ -904,11 +891,8 @@ public void test_passIn_withMatchingElementButClassCastException() { .unitTest() .when() .passInElement().fromClass(PassInClass.class) - .intoUnitTest(new UnitTest() { - @Override - public void unitTest(ProcessingEnvironment processingEnvironment, TypeElement element) { - throw new ClassCastException("Test Class Cast Exception"); - } + .intoUnitTest((processingEnvironment, element) -> { + throw new ClassCastException("Test Class Cast Exception"); }) .thenExpectThat() .exceptionIsThrown(ClassCastException.class) @@ -925,11 +909,8 @@ public void test_passIn_withProcessorPassIn_withNonMatchingElementType() { .when() .passInProcessor(SimpleTestProcessor1.class) .andPassInElement().fromClass(PassInClass.class) - .intoUnitTest(new UnitTestForTestingAnnotationProcessors() { - @Override - public void unitTest(SimpleTestProcessor1 unit, ProcessingEnvironment processingEnvironment, ExecutableElement element) { - throw new AssertionError("should have thrown assertion error!"); - } + .intoUnitTest((unit, processingEnvironment, element) -> { + throw new AssertionError("should have thrown assertion error!"); }) .executeTest(); @@ -950,11 +931,8 @@ public void test_passIn_withProcessorPassIn_withMatchingElementButClassCastExcep .when() .passInProcessor(SimpleTestProcessor1.class) .andPassInElement().fromClass(PassInClass.class) - .intoUnitTest(new UnitTestForTestingAnnotationProcessors() { - @Override - public void unitTest(SimpleTestProcessor1 unit, ProcessingEnvironment processingEnvironment, Element element) { - throw new ClassCastException("Test Class Cast Exception"); - } + .intoUnitTest((unit, processingEnvironment, element) -> { + throw new ClassCastException("Test Class Cast Exception"); }) .thenExpectThat() .exceptionIsThrown(ClassCastException.class) @@ -965,17 +943,17 @@ public void unitTest(SimpleTestProcessor1 unit, ProcessingEnvironment processing @Test(expected = ValidatorException.class) public void blackBoxTest_nullValuedProcessor() { - Cute.blackBoxTest().given().processor((Class) null); + Cute.blackBoxTest().given().processor(null); } @Test(expected = ValidatorException.class) public void blackBoxTest_nullValuedProcessors() { - Cute.blackBoxTest().given().processor((Class) null); + Cute.blackBoxTest().given().processor(null); } @Test(expected = ValidatorException.class) public void blackBoxTest_nullValuedProcessorInArray() { - Cute.blackBoxTest().given().processors((Class) null, (Class) null); + Cute.blackBoxTest().given().processors(null, null); } @Test(expected = ValidatorException.class) @@ -1046,14 +1024,12 @@ public void blackBoxTest_justCompileCodeAndDoClassTests() { .whenCompiled() .thenExpectThat() .compilationSucceeds() - .andThat().generatedClass("io.toolisticon.cute.TestClass").testedSuccessfullyBy(new GeneratedClassesTestForSpecificClass() { - @Override - public void doTests(Class clazz, CuteClassLoader cuteClassLoader) throws Exception { - MatcherAssert.assertThat(clazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClass")); + .andThat().generatedClass("io.toolisticon.cute.TestClass") + .testedSuccessfullyBy((clazz, cuteClassLoader) -> { + MatcherAssert.assertThat(clazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClass")); - Object instance = clazz.getConstructor().newInstance(); - MatcherAssert.assertThat(instance, Matchers.notNullValue()); - } + Object instance = clazz.getConstructor().newInstance(); + MatcherAssert.assertThat(instance, Matchers.notNullValue()); }) .executeTest(); } @@ -1065,24 +1041,22 @@ public void blackBoxTest_justCompileCodeAndDoClassTests2() { .whenCompiled() .thenExpectThat() .compilationSucceeds() - .andThat().generatedClass("io.toolisticon.cute.TestClassWithInnerClasses").testedSuccessfullyBy(new GeneratedClassesTestForSpecificClass() { - @Override - public void doTests(Class clazz, CuteClassLoader cuteClassLoader) throws Exception { - MatcherAssert.assertThat(clazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses")); + .andThat().generatedClass("io.toolisticon.cute.TestClassWithInnerClasses") + .testedSuccessfullyBy((clazz, cuteClassLoader) -> { + MatcherAssert.assertThat(clazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses")); - Class innerClazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$InnerClass"); - MatcherAssert.assertThat(innerClazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.InnerClass")); + Class innerClazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$InnerClass"); + MatcherAssert.assertThat(innerClazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.InnerClass")); - Class staticInnerClazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$StaticInnerClass"); - MatcherAssert.assertThat(staticInnerClazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.StaticInnerClass")); + Class staticInnerClazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$StaticInnerClass"); + MatcherAssert.assertThat(staticInnerClazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.StaticInnerClass")); - Class innerInterface = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$InnerInterface"); - MatcherAssert.assertThat(innerInterface.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.InnerInterface")); + Class innerInterface = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$InnerInterface"); + MatcherAssert.assertThat(innerInterface.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.InnerInterface")); - Object instance = clazz.getConstructor().newInstance(); - MatcherAssert.assertThat(instance, Matchers.notNullValue()); + Object instance = clazz.getConstructor().newInstance(); + MatcherAssert.assertThat(instance, Matchers.notNullValue()); - } }) .executeTest(); } @@ -1094,25 +1068,22 @@ public void blackBoxTest_justCompileCodeAndDoClassTest3() { .whenCompiled() .thenExpectThat() .compilationSucceeds() - .andThat().generatedClassesTestedSuccessfullyBy(new GeneratedClassesTest() { - @Override - public void doTests(CuteClassLoader cuteClassLoader) throws Exception { - Class clazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses"); - MatcherAssert.assertThat(clazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses")); + .andThat().generatedClassesTestedSuccessfullyBy(cuteClassLoader -> { + Class clazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses"); + MatcherAssert.assertThat(clazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses")); - Class innerClazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$InnerClass"); - MatcherAssert.assertThat(innerClazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.InnerClass")); + Class innerClazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$InnerClass"); + MatcherAssert.assertThat(innerClazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.InnerClass")); - Class staticInnerClazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$StaticInnerClass"); - MatcherAssert.assertThat(staticInnerClazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.StaticInnerClass")); + Class staticInnerClazz = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$StaticInnerClass"); + MatcherAssert.assertThat(staticInnerClazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.StaticInnerClass")); - Class innerInterface = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$InnerInterface"); - MatcherAssert.assertThat(innerInterface.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.InnerInterface")); + Class innerInterface = cuteClassLoader.getClass("io.toolisticon.cute.TestClassWithInnerClasses$InnerInterface"); + MatcherAssert.assertThat(innerInterface.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.InnerInterface")); - Object instance = clazz.getConstructor().newInstance(); - MatcherAssert.assertThat(instance, Matchers.notNullValue()); + Object instance = clazz.getConstructor().newInstance(); + MatcherAssert.assertThat(instance, Matchers.notNullValue()); - } }) .executeTest(); } @@ -1124,15 +1095,10 @@ public void blackBoxTest_justCompileCodeAndDoClassTest4() { .whenCompiled() .thenExpectThat() .compilationSucceeds() - .andThat().generatedClass("io.toolisticon.cute.TestClassWithInnerClasses$InnerClass").testedSuccessfullyBy(new GeneratedClassesTestForSpecificClass() { - @Override - public void doTests(Class innerClazz, CuteClassLoader cuteClassLoader) throws Exception { - - MatcherAssert.assertThat(innerClazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.InnerClass")); - - - } - }) + .andThat().generatedClass("io.toolisticon.cute.TestClassWithInnerClasses$InnerClass") + .testedSuccessfullyBy( + (innerClazz, cuteClassLoader) -> + MatcherAssert.assertThat(innerClazz.getCanonicalName(), Matchers.is("io.toolisticon.cute.TestClassWithInnerClasses.InnerClass"))) .executeTest(); } @@ -1143,14 +1109,12 @@ public void blackBoxTest_justCompileCodeAndDoClassTestWithImplementedInterface() .whenCompiled() .thenExpectThat() .compilationSucceeds() - .andThat().generatedClass("io.toolisticon.cute.TestClassWithImplementedInterface").testedSuccessfullyBy(new GeneratedClassesTestForSpecificClass() { - @Override - public void doTests(Class clazz, CuteClassLoader cuteClassLoader) throws Exception { + .andThat().generatedClass("io.toolisticon.cute.TestClassWithImplementedInterface") + .testedSuccessfullyBy((clazz, cuteClassLoader) -> { - SimpleTestInterface unit = (SimpleTestInterface) clazz.getConstructor().newInstance(); - MatcherAssert.assertThat(unit.saySomething(), Matchers.is("WHATS UP?")); + SimpleTestInterface unit = (SimpleTestInterface) clazz.getConstructor().newInstance(); + MatcherAssert.assertThat(unit.saySomething(), Matchers.is("WHATS UP?")); - } }) .executeTest(); } @@ -1163,20 +1127,19 @@ public void blackBoxTest_justCompileCodeAndDoClassTestWithImplementedInterfaceAn .whenCompiled() .thenExpectThat() .compilationSucceeds() - .andThat().generatedClass("io.toolisticon.cute.TestClassWithImplementedInterface").testedSuccessfullyBy(new GeneratedClassesTestForSpecificClass() { - @Override - public void doTests(Class clazz, CuteClassLoader cuteClassLoader) throws Exception { + .andThat().generatedClass("io.toolisticon.cute.TestClassWithImplementedInterface") + .testedSuccessfullyBy( + (clazz, cuteClassLoader) -> { - SimpleTestInterface unit = (SimpleTestInterface) clazz.getConstructor().newInstance(); - MatcherAssert.assertThat(unit.saySomething(), Matchers.is("WHATS UP???")); + SimpleTestInterface unit = (SimpleTestInterface) clazz.getConstructor().newInstance(); + MatcherAssert.assertThat(unit.saySomething(), Matchers.is("WHATS UP???")); - } - }) + }) .executeTest(); } @Test - public void blackBoxTest_checkForExpectedException(){ + public void blackBoxTest_checkForExpectedException_happyPath() { Cute.blackBoxTest().given().processor(ExceptionThrowerProcessor.class) .andSourceFiles("/compiletests/exceptionthrown/ExceptionThrownUsecase.java") .whenCompiled() @@ -1186,7 +1149,7 @@ public void blackBoxTest_checkForExpectedException(){ } @Test - public void blackBoxTest_checkForExpectedException_failure(){ + public void blackBoxTest_checkForExpectedException_failure_otherException() { try { Cute.blackBoxTest().given().processor(ExceptionThrowerProcessor.class) .andSourceFiles("/compiletests/exceptionthrown/ExceptionThrownUsecase.java") @@ -1194,9 +1157,28 @@ public void blackBoxTest_checkForExpectedException_failure(){ .thenExpectThat() .exceptionIsThrown(IllegalArgumentException.class) .executeTest(); - throw new AssertionError("FAIL"); + } catch (AssertionError e) { MatcherAssert.assertThat(e.getMessage(), Matchers.containsString("WHOOP")); + return; + } + throw new AssertionError("Expected an Assertion Error to be thrown"); + } + + @Test + public void blackBoxTest_checkForExpectedException_failure_noException() { + try { + Cute.blackBoxTest().given().processor(SimpleTestProcessor1.class) + .andSourceFiles("/compiletests/exceptionthrown/ExceptionThrownUsecase.java") + .whenCompiled() + .thenExpectThat() + .exceptionIsThrown(IllegalArgumentException.class) + .executeTest(); + + } catch (AssertionError e) { + MatcherAssert.assertThat(e.getMessage(), Matchers.containsString("Expected exception of type 'java.lang.IllegalArgumentException' to be thrown")); + return; } + throw new AssertionError("Expected exceptions wasn't triggered!!!"); } } diff --git a/cute/src/test/java/io/toolisticon/cute/integrationtest/CompiledClassesAndGeneratedFilesTest.java b/cute/src/test/java/io/toolisticon/cute/integrationtest/CompiledClassesAndGeneratedFilesTest.java index 3b1a752..aa1415f 100644 --- a/cute/src/test/java/io/toolisticon/cute/integrationtest/CompiledClassesAndGeneratedFilesTest.java +++ b/cute/src/test/java/io/toolisticon/cute/integrationtest/CompiledClassesAndGeneratedFilesTest.java @@ -2,7 +2,6 @@ import io.toolisticon.cute.Constants; import io.toolisticon.cute.Cute; -import io.toolisticon.cute.GeneratedFileObjectMatcher; import io.toolisticon.cute.JavaFileObjectUtils; import io.toolisticon.cute.TestUtilities; import io.toolisticon.cute.common.SimpleTestProcessor1; @@ -16,7 +15,6 @@ import javax.tools.StandardLocation; import java.io.BufferedWriter; import java.io.IOException; -import java.util.Collections; import java.util.Set; /** @@ -29,7 +27,7 @@ public class CompiledClassesAndGeneratedFilesTest { public void testCompiledClassesExist() { Cute.blackBoxTest() - .given().processors(SimpleTestProcessor1.class) + .given().processor(SimpleTestProcessor1.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java")) .whenCompiled() .thenExpectThat().compilationSucceeds() @@ -43,7 +41,7 @@ public void testCompiledClassesExist() { public void testCompiledClassesExist_withProcessorCollection() { Cute.blackBoxTest() - .given().processors(Collections.singletonList(SimpleTestProcessor1.class)) + .given().processor(SimpleTestProcessor1.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java")) .whenCompiled() .thenExpectThat().compilationSucceeds() @@ -107,7 +105,7 @@ public void testCompiledResourceExistButShouldnt() { try { Cute.blackBoxTest() - .given().processors(FileGeneratorProcessor.class) + .given().processor(FileGeneratorProcessor.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java")) .whenCompiled() .thenExpectThat().compilationSucceeds() @@ -129,11 +127,11 @@ public void testCompiledResourceExistButShouldnt() { public void testCompiledResourceExist_byFileObject() { Cute.blackBoxTest() - .given().processors(FileGeneratorProcessor.class) + .given().processor(FileGeneratorProcessor.class) .andSourceFiles("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java") .whenCompiled() .thenExpectThat().compilationSucceeds() - .andThat().fileObject(StandardLocation.SOURCE_OUTPUT, "/META-INF", "jupp.txt").equals( JavaFileObjectUtils.readFromString("XXX")) + .andThat().fileObject(StandardLocation.SOURCE_OUTPUT, "/META-INF", "jupp.txt").equals(JavaFileObjectUtils.readFromString("XXX")) .executeTest(); @@ -143,16 +141,11 @@ public void testCompiledResourceExist_byFileObject() { public void testCompiledResourceExist_ByMatcher() { Cute.blackBoxTest() - .given().processors(FileGeneratorProcessor.class) + .given().processor(FileGeneratorProcessor.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java")) .whenCompiled() .thenExpectThat().compilationSucceeds() - .andThat().fileObject(StandardLocation.SOURCE_OUTPUT, "/META-INF", "jupp.txt").matches( new GeneratedFileObjectMatcher() { - @Override - public boolean check(FileObject fileObject) throws IOException { - return true; - } - }) + .andThat().fileObject(StandardLocation.SOURCE_OUTPUT, "/META-INF", "jupp.txt").matches(fileObject -> true) .executeTest(); @@ -165,7 +158,7 @@ public void testCompiledResourceNotExistButShould_byFileObject() { try { Cute.blackBoxTest() - .given().processors(FileGeneratorProcessor.class) + .given().processor(FileGeneratorProcessor.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java")) .whenCompiled() .thenExpectThat().compilationSucceeds() @@ -189,15 +182,10 @@ public void testCompiledResourceNotExistButShould_byMatcher() { try { Cute.blackBoxTest() - .given().processors(FileGeneratorProcessor.class) + .given().processor(FileGeneratorProcessor.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java")) .whenCompiled().thenExpectThat().compilationSucceeds() - .andThat().fileObject(StandardLocation.SOURCE_OUTPUT, "/META-INF", "jupp.txt").matches( new GeneratedFileObjectMatcher() { - @Override - public boolean check(FileObject fileObject) throws IOException { - return false; - } - }) + .andThat().fileObject(StandardLocation.SOURCE_OUTPUT, "/META-INF", "jupp.txt").matches(fileObject -> false) .executeTest(); } catch (AssertionError e) { @@ -250,7 +238,7 @@ public boolean process(Set annotations, RoundEnvironment public void testCompiledJavaFileObjectExist() { Cute.blackBoxTest() - .given().processors(JavaFileGeneratorProcessor.class) + .given().processor(JavaFileGeneratorProcessor.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java")) .whenCompiled().thenExpectThat().compilationSucceeds() .andThat().javaFileObject(StandardLocation.SOURCE_OUTPUT, JavaFileGeneratorProcessor.PACKAGE_NAME + "." + JavaFileGeneratorProcessor.CLASS_NAME, JavaFileObject.Kind.SOURCE).exists() @@ -268,7 +256,7 @@ public void testCompiledJavaFileObjectNotExistButShould_byJavaFileObject() { try { Cute.blackBoxTest() - .given().processors(JavaFileGeneratorProcessor.class) + .given().processor(JavaFileGeneratorProcessor.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java")) .whenCompiled().thenExpectThat().compilationSucceeds() .andThat().javaFileObject(StandardLocation.SOURCE_OUTPUT, JavaFileGeneratorProcessor.PACKAGE_NAME + ".Murks", JavaFileObject.Kind.SOURCE).exists() @@ -292,7 +280,7 @@ public void testCompiledJavaFileObjectNotExistButShould_bySource() { try { Cute.blackBoxTest() - .given().processors(JavaFileGeneratorProcessor.class) + .given().processor(JavaFileGeneratorProcessor.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java")) .whenCompiled() .thenExpectThat().compilationSucceeds() @@ -317,7 +305,7 @@ public void testCompiledJavaFileObjectExistButShouldnt_byJavaFileObject() { try { Cute.blackBoxTest() - .given().processors(JavaFileGeneratorProcessor.class) + .given().processor(JavaFileGeneratorProcessor.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java")) .whenCompiled() .thenExpectThat().compilationSucceeds() @@ -342,7 +330,7 @@ public void testCompiledJavaFileObjectExistButShouldnt_bySource() { try { Cute.blackBoxTest() - .given().processors(JavaFileGeneratorProcessor.class) + .given().processor(JavaFileGeneratorProcessor.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java")) .whenCompiled() .thenExpectThat().compilationSucceeds() @@ -367,7 +355,7 @@ public void testCompiledJavaFileObjectNotExist_byJavaFileObjectComparision() { try { Cute.blackBoxTest() - .given().processors(JavaFileGeneratorProcessor.class) + .given().processor(JavaFileGeneratorProcessor.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java")) .whenCompiled() .thenExpectThat().compilationSucceeds() @@ -392,15 +380,10 @@ public void testCompiledJavaFileObjectNotExist_byMatcher() { try { Cute.blackBoxTest() - .given().processors(JavaFileGeneratorProcessor.class) + .given().processor(JavaFileGeneratorProcessor.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java")) .whenCompiled().thenExpectThat().compilationSucceeds() - .andThat().javaFileObject(StandardLocation.SOURCE_OUTPUT, JavaFileGeneratorProcessor.PACKAGE_NAME + "." + JavaFileGeneratorProcessor.CLASS_NAME, JavaFileObject.Kind.SOURCE).matches( new GeneratedFileObjectMatcher() { - @Override - public boolean check(FileObject fileObject) throws IOException { - return false; - } - }) + .andThat().javaFileObject(StandardLocation.SOURCE_OUTPUT, JavaFileGeneratorProcessor.PACKAGE_NAME + "." + JavaFileGeneratorProcessor.CLASS_NAME, JavaFileObject.Kind.SOURCE).matches(fileObject -> false) .executeTest(); } catch (AssertionError e) { diff --git a/cute/src/test/java/io/toolisticon/cute/integrationtest/ProcessorWasAppliedTest.java b/cute/src/test/java/io/toolisticon/cute/integrationtest/ProcessorWasAppliedTest.java index fce8c7b..24720a8 100644 --- a/cute/src/test/java/io/toolisticon/cute/integrationtest/ProcessorWasAppliedTest.java +++ b/cute/src/test/java/io/toolisticon/cute/integrationtest/ProcessorWasAppliedTest.java @@ -17,13 +17,12 @@ public class ProcessorWasAppliedTest { public void concreteProcessorClassInstance_wasApplied() { Cute.blackBoxTest() - .given().processors( SimpleTestProcessor1.class) + .given().processor(SimpleTestProcessor1.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/AnnotationProcessorAppliedTestClass.java")) .whenCompiled() .thenExpectThat().compilationSucceeds() .executeTest(); - } @Test @@ -31,7 +30,7 @@ public void concreteProcessorClassInstance_wasNotApplied() { boolean assertionErrorWasTriggered = false; try { Cute.blackBoxTest() - .given().processors( SimpleTestProcessor2.class) + .given().processor(SimpleTestProcessor2.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/AnnotationProcessorAppliedTestClass.java")) .executeTest(); @@ -46,47 +45,11 @@ public void concreteProcessorClassInstance_wasNotApplied() { } - /*- - @Test - public void anonymousProcessorClassInstanceOfProcessor_wasApplied() { - CuteFluentApiStarter.unitTest() - .unitTest() - .useProcessor(new SimpleTestProcessor1() { - }) - .useSource(JavaFileObjectUtils.readFromResource("/integrationtest/AnnotationProcessorAppliedTestClass.java")) - .executeTest(); - - } - - @Test - public void anonymousProcessorClassInstanceOfProcessor_wasNotApplied() { - boolean assertionErrorWasTriggered = false; - try { - CompileTestBuilder - .unitTest() - .useProcessor(new SimpleTestProcessor2() { - }) - .useSource(JavaFileObjectUtils.readFromResource("/integrationtest/AnnotationProcessorAppliedTestClass.java")) - .executeTest(); - - } catch (AssertionError e) { - assertionErrorWasTriggered = true; - - MatcherAssert.assertThat(e.getMessage(), Matchers.containsString("Annotation processor null hasn't been called")); - - } - - MatcherAssert.assertThat("AssertionError should have been triggered", assertionErrorWasTriggered); - - } - - */ - @Test public void anonymousProcessorClassInstanceOfClass_wasApplied() { Cute.blackBoxTest() - .given().processors(SimpleTestProcessor1.class) + .given().processor(SimpleTestProcessor1.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/AnnotationProcessorAppliedTestClass.java")) .executeTest(); @@ -99,13 +62,12 @@ public void anonymousProcessorClassInstanceOfClass_wasNotApplied() { try { Cute.blackBoxTest() - .given().processors(SimpleTestProcessor2.class) + .given().processor(SimpleTestProcessor2.class) .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/AnnotationProcessorAppliedTestClass.java")) .executeTest(); } catch (AssertionError e) { assertionErrorWasTriggered = true; - MatcherAssert.assertThat(e.getMessage(), Matchers.containsString("Annotation processor " + SimpleTestProcessor2.class.getCanonicalName() + " hasn't been called")); } diff --git a/cute/src/test/java/io/toolisticon/cute/matchers/CoreGeneratedFileObjectMatchersTest.java b/cute/src/test/java/io/toolisticon/cute/matchers/CoreGeneratedFileObjectMatchersTest.java index 0c7a169..3698f93 100644 --- a/cute/src/test/java/io/toolisticon/cute/matchers/CoreGeneratedFileObjectMatchersTest.java +++ b/cute/src/test/java/io/toolisticon/cute/matchers/CoreGeneratedFileObjectMatchersTest.java @@ -57,7 +57,7 @@ public void createIgnoreLineEndingsMatcher() { @Test(expected = IllegalArgumentException.class) public void createIgnoreLineEndingsMatcher_nullValued() { - GeneratedFileObjectMatcher unit = CoreGeneratedFileObjectMatchers.createIgnoreLineEndingsMatcher(null); + CoreGeneratedFileObjectMatchers.createIgnoreLineEndingsMatcher(null); } @@ -74,7 +74,7 @@ public void createBinaryMatcher() { @Test(expected = IllegalArgumentException.class) public void createBinaryMatcher_nullValued() { - GeneratedFileObjectMatcher unit = CoreGeneratedFileObjectMatchers.createBinaryMatcher(null); + CoreGeneratedFileObjectMatchers.createBinaryMatcher(null); } } \ No newline at end of file diff --git a/cute/src/test/resources/compiletests/compileroptionstest/Java8Code.java b/cute/src/test/resources/compiletests/compileroptionstest/Java8Code.java new file mode 100644 index 0000000..0f91b89 --- /dev/null +++ b/cute/src/test/resources/compiletests/compileroptionstest/Java8Code.java @@ -0,0 +1,12 @@ +package io.toolisticon.cute.testcases; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +public class Java8Code { + public static void main(String[] args) { + Arrays.asList("A", "B", "C").stream().filter(e -> e.equals("B")).collect(Collectors.toSet()); + } +} \ No newline at end of file diff --git a/cute/src/test/resources/compiletests/exceptionthrown/ExceptionThrownUsecase.java b/cute/src/test/resources/compiletests/exceptionthrown/ExceptionThrownUsecase.java index 9165381..6cdbec9 100644 --- a/cute/src/test/resources/compiletests/exceptionthrown/ExceptionThrownUsecase.java +++ b/cute/src/test/resources/compiletests/exceptionthrown/ExceptionThrownUsecase.java @@ -1,8 +1,10 @@ package io.toolisticon.cute.testhelper.compiletest; import io.toolisticon.cute.common.ExceptionThrowerAnnotation; +import io.toolisticon.cute.common.SimpleTestAnnotation1; @ExceptionThrowerAnnotation +@SimpleTestAnnotation1 public class ExceptionThrownUsecase { } \ No newline at end of file diff --git a/extension/api/pom.xml b/extension/api/pom.xml index 3561804..5883e0a 100644 --- a/extension/api/pom.xml +++ b/extension/api/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute extension-parent - 1.3.1 + 1.4.0 extension-api diff --git a/extension/junit4/pom.xml b/extension/junit4/pom.xml index 05b6ade..f625fa4 100644 --- a/extension/junit4/pom.xml +++ b/extension/junit4/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute extension-parent - 1.3.1 + 1.4.0 extension-junit4 diff --git a/extension/junit5/pom.xml b/extension/junit5/pom.xml index 981f9d8..124b18d 100644 --- a/extension/junit5/pom.xml +++ b/extension/junit5/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute extension-parent - 1.3.1 + 1.4.0 extension-junit5 diff --git a/extension/modulesupport/pom.xml b/extension/modulesupport/pom.xml index 5e8138b..5f89a69 100644 --- a/extension/modulesupport/pom.xml +++ b/extension/modulesupport/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute extension-parent - 1.3.1 + 1.4.0 extension-modulesupport @@ -40,6 +40,8 @@ maven-compiler-plugin + 9 + 9 io.toolisticon.spiap @@ -84,26 +86,17 @@ - - maven-compiler-plugin - - 9 - 9 - - - org.codehaus.mojo animal-sniffer-maven-plugin + ${animal-sniffer-maven-plugin.version} true - - diff --git a/extension/plainjava/pom.xml b/extension/plainjava/pom.xml index d988026..aedce4a 100644 --- a/extension/plainjava/pom.xml +++ b/extension/plainjava/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute extension-parent - 1.3.1 + 1.4.0 extension-plainjava diff --git a/extension/pom.xml b/extension/pom.xml index 1c614f0..959c5ac 100644 --- a/extension/pom.xml +++ b/extension/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.3.1 + 1.4.0 extension-parent diff --git a/extension/testng/pom.xml b/extension/testng/pom.xml index 6092338..0b4afa0 100644 --- a/extension/testng/pom.xml +++ b/extension/testng/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute extension-parent - 1.3.1 + 1.4.0 extension-testng diff --git a/integration-test/java9/namedAutomaticModule/pom.xml b/integration-test/java9/namedAutomaticModule/pom.xml index df8710e..a1ce594 100644 --- a/integration-test/java9/namedAutomaticModule/pom.xml +++ b/integration-test/java9/namedAutomaticModule/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-java9-parent - 1.3.1 + 1.4.0 integration-test-java9-namedAutomaticModule diff --git a/integration-test/java9/pom.xml b/integration-test/java9/pom.xml index 434e4c7..5dde17e 100644 --- a/integration-test/java9/pom.xml +++ b/integration-test/java9/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-parent - 1.3.1 + 1.4.0 integration-test-java9-parent diff --git a/integration-test/java9/regularTestModule/pom.xml b/integration-test/java9/regularTestModule/pom.xml index c0e8200..eb503f5 100644 --- a/integration-test/java9/regularTestModule/pom.xml +++ b/integration-test/java9/regularTestModule/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-java9-parent - 1.3.1 + 1.4.0 integration-test-java9-regularModule diff --git a/integration-test/java9/test/pom.xml b/integration-test/java9/test/pom.xml index 833ce6d..0420fb9 100644 --- a/integration-test/java9/test/pom.xml +++ b/integration-test/java9/test/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-java9-parent - 1.3.1 + 1.4.0 integration-test-java9-test diff --git a/integration-test/java9/unnamedAutomaticModule/pom.xml b/integration-test/java9/unnamedAutomaticModule/pom.xml index f9f6ab8..6783b5b 100644 --- a/integration-test/java9/unnamedAutomaticModule/pom.xml +++ b/integration-test/java9/unnamedAutomaticModule/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-java9-parent - 1.3.1 + 1.4.0 integration-test-java9-unnamedAutomaticModule diff --git a/integration-test/junit4/pom.xml b/integration-test/junit4/pom.xml index 3275cb7..a936ed2 100644 --- a/integration-test/junit4/pom.xml +++ b/integration-test/junit4/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-parent - 1.3.1 + 1.4.0 integration-test-junit4 diff --git a/integration-test/junit5/pom.xml b/integration-test/junit5/pom.xml index b16d709..07af98f 100644 --- a/integration-test/junit5/pom.xml +++ b/integration-test/junit5/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute integration-test-parent - 1.3.1 + 1.4.0 integration-test-junit5 diff --git a/integration-test/pom.xml b/integration-test/pom.xml index 35ab65d..828144c 100644 --- a/integration-test/pom.xml +++ b/integration-test/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute cute-parent - 1.3.1 + 1.4.0 integration-test-parent diff --git a/integration-test/testng/pom.xml b/integration-test/testng/pom.xml index 159803e..fddb777 100644 --- a/integration-test/testng/pom.xml +++ b/integration-test/testng/pom.xml @@ -7,7 +7,7 @@ io.toolisticon.cute integration-test-parent - 1.3.1 + 1.4.0 integration-test-testng diff --git a/legacy/pom.xml b/legacy/pom.xml index 7951e85..00d3115 100644 --- a/legacy/pom.xml +++ b/legacy/pom.xml @@ -8,7 +8,7 @@ io.toolisticon.cute cute-parent - 1.3.1 + 1.4.0 cute-legacy diff --git a/pom.xml b/pom.xml index aeec794..4966173 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.toolisticon.cute cute-parent - 1.3.1 + 1.4.0 pom cute-parent @@ -93,7 +93,7 @@ 1.18 4.3.0 - 0.8.8 + 0.8.11 2.4 2.5.3 2.22.2