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.cutecute-parent
- 1.3.1
+ 1.4.0coverage
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.cutecute-parent
- 1.3.1
+ 1.4.0cute
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 extends TypeElement> annotations, RoundEnvironment
, e);
}
+ // Exception has been found
+ expectedExceptionWasThrown = true;
+
} else {
// Got unexpected exception
@@ -107,13 +111,14 @@ public boolean process(Set extends TypeElement> 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 extends Processor> 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 extends JavaFileObject> 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 extends TypeElement> set = new HashSet();
+ Set extends TypeElement> 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 extends TypeElement> 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 extends Completion> 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 {
- *