GeneratedFileObjectMatcher createMatcher(T expecte
}
},
/**
- * Textual comparison line by line by ignoring the OS depending line-endings.
+ * Textual comparison line by line ignoring the OS dependent line-endings.
*/
TEXT_IGNORE_LINE_ENDINGS {
@Override
diff --git a/cute/src/main/java/io/toolisticon/cute/FileObjectUtils.java b/cute/src/main/java/io/toolisticon/cute/FileObjectUtils.java
index f3271d9..b885b27 100644
--- a/cute/src/main/java/io/toolisticon/cute/FileObjectUtils.java
+++ b/cute/src/main/java/io/toolisticon/cute/FileObjectUtils.java
@@ -1,281 +1,137 @@
package io.toolisticon.cute;
-import javax.tools.SimpleJavaFileObject;
+
+import javax.tools.FileObject;
import javax.tools.StandardLocation;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
import java.io.Reader;
+import java.io.Writer;
import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
/**
- * Utility class to create JavaFileObjects and therefore also FileObjects.
- * These files can be used for comparison or as source files during compilation.
+ * Utility class to provide FileObjects that can be used for comparison in checks.
*/
-public class FileObjectUtils {
-
-
- /**
- * A file object used to represent source coming from a string.
- */
- public static class JavaSourceFromString extends SimpleJavaFileObject {
- /**
- * The source content of this "file".
- */
- private final String content;
+public abstract class FileObjectUtils {
- /**
- * Constructs a new JavaSourceFromString.
- *
- * @param name the name of the compilation unit represented by this file object
- * @param content the source content for the compilation unit represented by this file object
- */
- private JavaSourceFromString(String name, String content) {
- super(URI.create("string://" + StandardLocation.SOURCE_PATH + "/" + name.replace('.', '/') + Kind.SOURCE.extension),
- Kind.SOURCE);
- this.content = content;
+ static abstract class AbstractFileObject implements FileObject {
+ @Override
+ public URI toUri() {
+ return URI.create("string://" + StandardLocation.SOURCE_OUTPUT + "/Dummy");
}
-
@Override
- public InputStream openInputStream() {
- return new ByteArrayInputStream(this.content.getBytes());
+ public String getName() {
+ return "Dummy";
}
@Override
- public Reader openReader(boolean ignoreEncodingErrors) {
- return new InputStreamReader(openInputStream());
+ public OutputStream openOutputStream() throws IOException {
+ throw new UnsupportedOperationException();
}
@Override
- public CharSequence getCharContent(boolean ignoreEncodingErrors) {
- return content;
+ public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
+ return new InputStreamReader(openInputStream());
}
- }
-
- /**
- * Resource based java source.
- */
- public static class JavaSourceFromResource extends SimpleJavaFileObject {
-
- private final static String JAVA_COMPATIBILITY_FILE_ENDING_SUFFIX = ".ct";
-
- private final Class> relativeLocationRoot;
- private final String location;
-
- private JavaSourceFromResource(String location, Class> relativeLocationRoot) {
-
- super(URI.create("resource://" + (location.endsWith(".java" + JAVA_COMPATIBILITY_FILE_ENDING_SUFFIX) ? location.substring(0, location.length() - JAVA_COMPATIBILITY_FILE_ENDING_SUFFIX.length()) : location)), Kind.SOURCE);
- this.relativeLocationRoot = relativeLocationRoot;
- this.location = location;
-
- }
-
@Override
- public InputStream openInputStream() {
-
- Class> relativeRoot = relativeLocationRoot != null ? relativeLocationRoot : FileObjectUtils.class;
- InputStream inputStream = relativeRoot.getResourceAsStream(location);
-
- if (inputStream == null) {
- throw new IllegalStateException(Constants.Messages.ISE_CANNOT_OPEN_INPUTSTREAM_WITH_URI.produceMessage(uri.toString()));
- }
-
- return inputStream;
+ public Writer openWriter() throws IOException {
+ throw new UnsupportedOperationException();
}
@Override
- public Reader openReader(boolean ignoreEncodingErrors) {
- return new InputStreamReader(openInputStream());
+ public long getLastModified() {
+ return 0;
}
@Override
- public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
- return readFromInputStream(openInputStream());
+ public boolean delete() {
+ return false;
}
+
}
- /**
- * Url based java source.
- */
- public static class JavaSourceFromUrl extends SimpleJavaFileObject {
+ static class FileObjectFromString extends AbstractFileObject {
- private final URL url;
- private JavaSourceFromUrl(URL url) throws URISyntaxException {
- super(url.toURI(), Kind.SOURCE);
- this.url = url;
- }
+ private final String content;
+ public FileObjectFromString(String content) {
- @Override
- public InputStream openInputStream() throws IOException {
- return url.openStream();
+ this.content = content;
}
@Override
- public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
- return new InputStreamReader(openInputStream());
+ public InputStream openInputStream() throws IOException {
+ return new ByteArrayInputStream(this.content.getBytes());
}
+
@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
- return readFromInputStream(openInputStream());
+ return content;
}
+
}
+ static class FileObjectFromResource extends AbstractFileObject {
- /**
- * Read a java source file from resources.
- *
- * Some IDEs like Eclipse don't like resource files ending with *.java.
- * In this case extend the file name by ".ct" suffix (f.e. "JavaClass.java.ct").
- * The suffix will be ignored for looking up files via the compile-test file manager.
- * *
- *
- * @param location the location
- * @param relativeLocationRoot relative location root class
- * @return The SimpleJavaFileObject for resource
- */
- public static SimpleJavaFileObject readFromResource(String location, Class> relativeLocationRoot) {
-
- if (location == null) {
- throw new IllegalArgumentException(Constants.Messages.IAE_PASSED_PARAMETER_MUST_NOT_BE_NULL.produceMessage("location"));
- }
+ private final String resource;
- return new JavaSourceFromResource(location, relativeLocationRoot);
- }
+ public FileObjectFromResource(String resource) {
- /**
- * Read a java source file from resources.
- * Passed location will be handled as absolute path and will be used to both read resource and as location in compile test file manager.
- *
- * Some IDEs like Eclipse don't like resource files ending with *.java.
- * In this case extend the file name by ".ct" suffix (f.e. "JavaClass.java.ct").
- * The suffix will be ignored for looking up files via the compile-test file manager.
- *
- * @param location the location
- * @return The SimpleJavaFileObject for resource
- */
- public static SimpleJavaFileObject readFromResource(String location) {
-
- if (location == null) {
- throw new IllegalArgumentException(Constants.Messages.IAE_PASSED_PARAMETER_MUST_NOT_BE_NULL.produceMessage("location"));
+ this.resource = resource;
}
- return new JavaSourceFromResource((!location.startsWith("/") ? "/" : "") + location, null);
- }
- /**
- * Reads multiple java source files from resources.
- * Passed locations will be handled as absolute path and will be used to both read resource and as location in compile test file manager.
- *
- * Some IDEs like Eclipse don't like resource files ending with *.java.
- * In this case extend the file name by ".ct" suffix (f.e. "JavaClass.java.ct").
- * The suffix will be ignored for looking up files via the compile-test file manager.
- *
- * @param locations the location
- * @return The SimpleJavaFileObject for resource
- */
- public static SimpleJavaFileObject[] readFromResources(String... locations) {
-
- List resourceFiles = new ArrayList<>();
-
- for (String location : locations) {
- resourceFiles.add(readFromResource(location));
+ @Override
+ public InputStream openInputStream() throws IOException {
+ return FileObjectUtils.class.getResourceAsStream(resource);
}
- return resourceFiles.toArray(new SimpleJavaFileObject[0]);
- }
-
- /**
- * Read a java source file from string.
- *
- * @param location the location
- * @param content content of the file
- * @return The SimpleJavaFileObject for passed content string
- */
- public static SimpleJavaFileObject readFromString(String location, String content) {
-
- if (location == null) {
- throw new IllegalArgumentException(Constants.Messages.IAE_PASSED_PARAMETER_MUST_NOT_BE_NULL.produceMessage("location"));
+ @Override
+ public OutputStream openOutputStream() throws IOException {
+ throw new UnsupportedOperationException();
}
- if (content == null) {
- throw new IllegalArgumentException(Constants.Messages.IAE_PASSED_PARAMETER_MUST_NOT_BE_NULL.produceMessage("content"));
- }
- return new JavaSourceFromString(location, content);
- }
+ @Override
+ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
- /**
- * Read a java source file from resources.
- * This one works great if you don't rely on the location, f.e. in case of comparison.
- *
- * @param content content of the file
- * @return he SimpleJavaFileObject for passed content string
- */
- public static SimpleJavaFileObject readFromString(String content) {
+ ByteArrayOutputStream buffer;
+ try (InputStream inputStream = openInputStream()) {
- // create a random location
- String location = "string_" + CommonUtilities.getRandomString(6);
+ buffer = new ByteArrayOutputStream();
+ int nRead;
+ byte[] data = new byte[1024];
- return readFromString(location, content);
- }
+ while ((nRead = inputStream.read(data, 0, data.length)) != -1) {
+ buffer.write(data, 0, nRead);
+ }
+ buffer.flush();
+ byte[] byteArray = buffer.toByteArray();
+ return new String(byteArray);
- /**
- * Read a java source file from resources.
- *
- * @param url the location
- * @return The SimpleJavaFileObject for passed URL
- * @throws URISyntaxException if passed url cannot be converted into URI
- * @throws IllegalArgumentException if passed url is null
- */
- public static SimpleJavaFileObject readFromUrl(URL url) throws URISyntaxException {
+ }
- if (url == null) {
- throw new IllegalArgumentException(Constants.Messages.IAE_PASSED_PARAMETER_MUST_NOT_BE_NULL.produceMessage("url"));
}
- return new JavaSourceFromUrl(url);
}
-
- /**
- * Reads a String from an InputStream.
- * CLoses the stream
- *
- * @param stream the inputStream to use
- * @return The String read from the inputStreams
- * @throws IOException if an error occurs
- */
- private static String readFromInputStream(InputStream stream) throws IOException {
-
- byte[] buffer = new byte[10000];
- ByteArrayOutputStream os = new ByteArrayOutputStream();
-
- int line;
- // read bytes from stream, and store them in buffer
- while ((line = stream.read(buffer)) != -1) {
- // Writes bytes from byte array (buffer) into output stream.
- os.write(buffer, 0, line);
- }
- stream.close();
- os.flush();
- os.close();
-
- return os.toString();
+ public static FileObject fromString(String content) {
+ return new FileObjectFromString(content);
}
+ public static FileObject fromResource(String resource) {
+ return new FileObjectFromResource(resource);
+ }
}
diff --git a/cute/src/test/java/io/toolisticon/cute/CompileTestTest.java b/cute/src/test/java/io/toolisticon/cute/CompileTestTest.java
deleted file mode 100644
index fa87a78..0000000
--- a/cute/src/test/java/io/toolisticon/cute/CompileTestTest.java
+++ /dev/null
@@ -1,375 +0,0 @@
-package io.toolisticon.cute;
-
-import io.toolisticon.cute.Cute;
-import io.toolisticon.cute.GeneratedFileObjectMatcher;
-import io.toolisticon.cute.JavaFileObjectUtils;
-import io.toolisticon.cute.UnitTest;
-import org.junit.Test;
-
-import javax.annotation.processing.ProcessingEnvironment;
-import javax.lang.model.element.Element;
-import javax.lang.model.element.TypeElement;
-import javax.tools.FileObject;
-import javax.tools.StandardLocation;
-import java.io.IOException;
-import java.io.Writer;
-
-public class CompileTestTest {
-
- @Test
- public void test_UnitTest_checkMatchingFileObject() {
-
- Cute.unitTest()
- .given().useCompilerOptions("-verbose ", " -source 1.7 ", "-target 1.7")
- .when().passInElement().fromSourceFile("/AnnotationProcessorUnitTestTestClass.java")
- .intoUnitTest(new UnitTest() {
- @Override
- public void unitTest(ProcessingEnvironment processingEnvironment, Element typeElement) {
-
- try {
-
- FileObject fileObject = processingEnvironment.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "root", "Jupp.txt");
- Writer writer = fileObject.openWriter();
- writer.write("TATA!");
- writer.close();
-
-
- } catch (IOException ignored) {
-
- }
-
- }
- })
- .thenExpectThat().compilationSucceeds()
- .andThat().fileObject(StandardLocation.SOURCE_OUTPUT, "root", "Jupp.txt").exists()
-
- .andThat().fileObject(StandardLocation.SOURCE_OUTPUT, "root", "Jupp.txt").equals( JavaFileObjectUtils.readFromString("TATA!"))
-
- .andThat().fileObject(StandardLocation.SOURCE_OUTPUT, "root", "Jupp.txt").matches( new GeneratedFileObjectMatcher() {
- @Override
- public boolean check(FileObject fileObject) throws IOException {
- return fileObject.getCharContent(false).toString().contains("TAT");
- }
- })
-
-
- .executeTest();
-
- }
-
- /*-
- @Test
- public void test_UnitTest_checkNonMatchingFileObject() {
-
-
- try {
- CompileTestBuilder
- .unitTest()
- .defineTest(new UnitTest() {
- @Override
- public void unitTest(ProcessingEnvironment processingEnvironment, Element typeElement) {
- try {
- FileObject fileObject = processingEnvironment.getFiler().createResource(StandardLocation.SOURCE_OUTPUT, "root", "Jupp.txt", typeElement);
- Writer writer = fileObject.openWriter();
- writer.write("TATA!");
- writer.close();
-
-
- } catch (IOException ignored) {
-
- }
-
- }
- })
-
- .compilationShouldSucceed()
- .expectThatFileObjectExists(StandardLocation.SOURCE_OUTPUT, "root", "Jupp.txt", JavaFileObjectUtils.readFromString("WURST!"))
- .executeTest();
-
- Assert.fail("Should have triggered an assertion error");
-
- } catch (AssertionError e) {
-
- MatcherAssert.assertThat(e.getMessage(), Matchers.containsString("exists but doesn't match passed GeneratedFileObjectMatcher" +
- ""));
-
- }
-
-
- }
-
- @Test
- public void test_JavaFileObjectExists() {
- CompileTestBuilder
- .unitTest()
- .defineTest(new UnitTest() {
- @Override
- public void unitTest(ProcessingEnvironment processingEnvironment, Element typeElement) {
-
- try {
- JavaFileObject javaFileObject = processingEnvironment.getFiler().createSourceFile("io.toolisticon.cute.CheckTest");
- Writer writer = javaFileObject.openWriter();
- writer.write("package io.toolisticon.cute;\n");
- writer.write("public class CheckTest{}");
- writer.flush();
- writer.close();
-
- } catch (IOException e) {
- throw new RuntimeException("WTF: " + e.getMessage(), e);
- }
-
- }
- })
-
- .compilationShouldSucceed()
- .expectThatJavaFileObjectExists(StandardLocation.CLASS_OUTPUT, "io.toolisticon.cute.CheckTest", JavaFileObject.Kind.CLASS)
- .expectThatGeneratedClassExists("io.toolisticon.cute.CheckTest")
- .expectThatJavaFileObjectExists(StandardLocation.SOURCE_OUTPUT, "io.toolisticon.cute.CheckTest", JavaFileObject.Kind.SOURCE)
- .expectThatJavaFileObjectExists(StandardLocation.SOURCE_OUTPUT, "io.toolisticon.cute.CheckTest", JavaFileObject.Kind.SOURCE, JavaFileObjectUtils.readFromString("xyz", "package io.toolisticon.cute;\npublic class CheckTest{}"))
- .expectThatJavaFileObjectExists(StandardLocation.SOURCE_OUTPUT, "io.toolisticon.cute.CheckTest", JavaFileObject.Kind.SOURCE, new GeneratedFileObjectMatcher() {
- @Override
- public boolean check(FileObject fileObject) throws IOException {
- return fileObject.getCharContent(false).toString().contains("public class CheckTest{}");
- }
- })
- .expectThatGeneratedSourceFileExists("io.toolisticon.cute.CheckTest")
- .expectThatGeneratedSourceFileExists("io.toolisticon.cute.CheckTest", JavaFileObjectUtils.readFromString("xyz", "package io.toolisticon.cute;\npublic class CheckTest{}"))
- .expectThatGeneratedSourceFileExists("io.toolisticon.cute.CheckTest", new GeneratedFileObjectMatcher() {
- @Override
- public boolean check(FileObject fileObject) throws IOException {
- return fileObject.getCharContent(false).toString().contains("public class CheckTest{}");
- }
- })
- .expectThatGeneratedSourceFileDoesntExist("io.toolisticon.cute.CheckTestNotExistent")
- .expectThatFileObjectDoesntExist(StandardLocation.SOURCE_OUTPUT, "io.toolisticon.cute", "SomethingThatDoesntExist.txt")
- .executeTest();
-
- }
-
- @Test(expected = InvalidTestConfigurationException.class)
- public void executeTest_CompilationSucceedAndErrorMessageExpectedShouldThowInvalidTestConfigurationException() {
- CompileTestBuilder.unitTest()
- .defineTest(new UnitTest() {
- @Override
- public void unitTest(ProcessingEnvironment processingEnvironment, Element typeElement) {
-
- }
- }).compilationShouldSucceed().expectErrorMessageThatContains("XXX").executeTest();
- }
-
- @Test
- public void executeTest_expectedCompilationShouldHaveSucceededButFailed() {
- boolean assertionErrorWasThrown = false;
- try {
-
- CompileTestBuilder.unitTest()
- .defineTest(new UnitTest() {
- @Override
- public void unitTest(ProcessingEnvironment processingEnvironment, Element typeElement) {
- processingEnvironment.getMessager().printMessage(Diagnostic.Kind.ERROR, "FAIL!");
- }
- })
- .compilationShouldSucceed()
- .executeTest();
-
- } catch (AssertionError e) {
- TestUtilities.assertAssertionMessageContainsMessageTokensAssertion(e, Constants.Messages.MESSAGE_COMPILATION_SHOULD_HAVE_SUCCEEDED_BUT_FAILED.getMessagePattern());
- assertionErrorWasThrown = true;
-
- }
-
- MatcherAssert.assertThat("AssertionError about 'expecting compilation to be successful but failed' should have been thrown", assertionErrorWasThrown);
-
-
- }
-
- @Test
- public void executeTest_expectedCompilationShouldHaveFailedButSucceeded() {
- boolean assertionErrorWasThrown = false;
- try {
-
- CompileTestBuilder.unitTest()
- .defineTest(new UnitTest() {
- @Override
- public void unitTest(ProcessingEnvironment processingEnvironment, Element typeElement) {
-
- }
- })
- .compilationShouldFail()
- .executeTest();
-
- } catch (AssertionError e) {
- TestUtilities.assertAssertionMessageContainsMessageTokensAssertion(e, Constants.Messages.MESSAGE_COMPILATION_SHOULD_HAVE_FAILED_BUT_SUCCEEDED.getMessagePattern());
- assertionErrorWasThrown = true;
-
- }
-
- MatcherAssert.assertThat("AssertionError about 'expecting compilation to fail but was successful' should have been thrown", assertionErrorWasThrown);
-
- }
-
- private static class PassInTestClass_MethodParameter {
-
- public void testMethod(@PassIn String attribute) {
-
- }
-
- }
-
- @Test
- public void executeTest_expectedPassInToWork_withMethodParameter() {
-
-
- CompileTestBuilder.unitTest()
- .defineTestWithPassedInElement(PassInTestClass_MethodParameter.class, new UnitTest() {
- @Override
- public void unitTest(ProcessingEnvironment processingEnvironment, VariableElement element) {
-
- MatcherAssert.assertThat(element, Matchers.notNullValue());
- MatcherAssert.assertThat(element.getKind(), Matchers.is(ElementKind.PARAMETER));
-
-
- }
- })
- .compilationShouldSucceed()
- .executeTest();
-
-
- }
-
- private static class PassInTestClass_ConstructorParameter {
-
- public PassInTestClass_ConstructorParameter(@PassIn String attribute) {
-
- }
-
- }
-
- @Test
- public void executeTest_expectedPassInToWork_withConstructorParameter() {
-
-
- CompileTestBuilder.unitTest()
- .defineTestWithPassedInElement(PassInTestClass_ConstructorParameter.class, new UnitTest() {
- @Override
- public void unitTest(ProcessingEnvironment processingEnvironment, VariableElement element) {
-
- MatcherAssert.assertThat(element, Matchers.notNullValue());
- MatcherAssert.assertThat(element.getKind(), Matchers.is(ElementKind.PARAMETER));
-
- }
- })
- .compilationShouldSucceed()
- .executeTest();
-
-
- }
-
- private static class PassInTestClass_Constructor {
-
- @PassIn
- public PassInTestClass_Constructor(String attribute) {
-
- }
-
- }
-
- @Test
- public void executeTest_expectedPassInToWork_withConstructor() {
-
-
- CompileTestBuilder.unitTest()
- .defineTestWithPassedInElement(PassInTestClass_Constructor.class, new UnitTest() {
- @Override
- public void unitTest(ProcessingEnvironment processingEnvironment, ExecutableElement element) {
-
- MatcherAssert.assertThat(element, Matchers.notNullValue());
- MatcherAssert.assertThat(element.getParameters(), Matchers.hasSize(1));
- MatcherAssert.assertThat(element.getKind(), Matchers.is(ElementKind.CONSTRUCTOR));
-
- }
- })
- .compilationShouldSucceed()
- .executeTest();
-
-
- }
-
- @PassIn
- private static class PassInTestClass_WithMultiplePassInAnnotations {
-
- @PassIn
- public PassInTestClass_WithMultiplePassInAnnotations(String attribute) {
-
- }
-
- }
-
- @Test
- public void executeTest_expectedPassInToFail_withMultiplePassInAnnotations() {
-
- boolean assertionErrorWasThrown = false;
- try {
- CompileTestBuilder.unitTest()
- .defineTestWithPassedInElement(PassInTestClass_WithMultiplePassInAnnotations.class, new UnitTest() {
- @Override
- public void unitTest(ProcessingEnvironment processingEnvironment, ExecutableElement element) {
-
- }
- })
- .compilationShouldSucceed()
- .executeTest();
-
- } catch (AssertionError e) {
- TestUtilities.assertAssertionMessageContainsMessageTokensAssertion(e, Constants.Messages.UNIT_TEST_PASS_IN_PRECONDITION_MUST_FIND_EXACTLY_ONE_ELEMENT.getMessagePattern());
- assertionErrorWasThrown = true;
-
- }
-
- MatcherAssert.assertThat("AssertionError about 'expecting compilation to fail but was successful' should have been thrown", assertionErrorWasThrown);
-
- }
-
- @Test
- public void executeTest_shouldThrowUnexpectedClassCastExceptionCorrectly() {
-
- boolean assertionErrorWasThrown = false;
- try {
- CompileTestBuilder.unitTest()
- .defineTest(new UnitTest() {
- @Override
- public void unitTest(ProcessingEnvironment processingEnvironment, Element element) {
- throw new ClassCastException();
- }
- })
- .executeTest();
-
- } catch (AssertionError e) {
- TestUtilities.assertAssertionMessageContainsMessageTokensAssertion(e, Constants.Messages.ASSERTION_GOT_UNEXPECTED_EXCEPTION.getMessagePattern());
- assertionErrorWasThrown = true;
-
- }
-
- MatcherAssert.assertThat("Should get unexpected ClassCastException assertion error", assertionErrorWasThrown);
-
- }
-
- @Test
- public void executeTest_shouldHandleExpectedClassCastExceptionCorrectly() {
-
-
- CompileTestBuilder.unitTest()
- .defineTest(new UnitTest() {
- @Override
- public void unitTest(ProcessingEnvironment processingEnvironment, Element element) {
- throw new ClassCastException();
- }
- })
- .expectedThrownException(ClassCastException.class)
- .executeTest();
-
-
- }
-
- */
-}
diff --git a/cute/src/test/java/io/toolisticon/cute/CuteTest.java b/cute/src/test/java/io/toolisticon/cute/CuteTest.java
index a5b43f2..ebb9e78 100644
--- a/cute/src/test/java/io/toolisticon/cute/CuteTest.java
+++ b/cute/src/test/java/io/toolisticon/cute/CuteTest.java
@@ -9,6 +9,7 @@
import org.mockito.Mockito;
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;
@@ -19,6 +20,8 @@
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
/**
* Unit tests for {@link Cute}.
@@ -918,17 +921,27 @@ public void unitTest(SimpleTestProcessor1 unit, ProcessingEnvironment processing
@Test(expected = ValidatorException.class)
public void blackBoxTest_nullValuedProcessor() {
- Cute.blackBoxTest().given().processors(null);
+ Cute.blackBoxTest().given().processor((Class extends Processor>)null);
+ }
+
+ @Test(expected = ValidatorException.class)
+ public void blackBoxTest_nullValuedProcessors() {
+ Cute.blackBoxTest().given().processor((Class extends Processor>)null);
}
@Test(expected = ValidatorException.class)
public void blackBoxTest_nullValuedProcessorInArray() {
- Cute.blackBoxTest().given().processors(null, null);
+ Cute.blackBoxTest().given().processors((Class extends Processor>)null, (Class extends Processor>)null);
+ }
+
+ @Test(expected = ValidatorException.class)
+ public void blackBoxTest_nullValuedProcessorCollection() {
+ Cute.blackBoxTest().given().processors((Collection>) null);
}
@Test()
public void blackBoxTest_emptyProcessors_shouldJustCompileCode() {
- Cute.blackBoxTest().given().processors()
+ Cute.blackBoxTest().given().noProcessors()
.andSourceFiles("/TestClass.java")
.whenCompiled()
.thenExpectThat()
@@ -937,6 +950,18 @@ public void blackBoxTest_emptyProcessors_shouldJustCompileCode() {
.executeTest();
}
+ @Test()
+ public void blackBoxTest_emptyProcessorCollection_shouldJustCompileCode() {
+ Cute.blackBoxTest().given().processors(Collections.emptyList())
+ .andSourceFiles("/TestClass.java")
+ .whenCompiled()
+ .thenExpectThat()
+ .compilationSucceeds()
+ .andThat().generatedClass("io.toolisticon.cute.TestClass").exists()
+ .executeTest();
+ }
+
+
@Test()
public void blackBoxTest_noProcessors_shouldJustCompileCode() {
Cute.blackBoxTest().given().noProcessors()
@@ -972,7 +997,7 @@ public void blackBoxTest_executeTest_WithoutChecks_FailedCompilation() {
@Test()
public void blackBoxTest_justCompileCodeAndDoClassTests() {
- Cute.blackBoxTest().given().processors()
+ Cute.blackBoxTest().given().noProcessors()
.andSourceFiles("/TestClass.java")
.whenCompiled()
.thenExpectThat()
@@ -991,7 +1016,7 @@ public void doTests(Class> clazz,CuteClassLoader cuteClassLoader) throws Excep
@Test()
public void blackBoxTest_justCompileCodeAndDoClassTests2() {
- Cute.blackBoxTest().given().processors()
+ Cute.blackBoxTest().given().noProcessors()
.andSourceFiles("/TestClassWithInnerClasses.java")
.whenCompiled()
.thenExpectThat()
@@ -1020,7 +1045,7 @@ public void doTests(Class>clazz, CuteClassLoader cuteClassLoader) throws Excep
@Test()
public void blackBoxTest_justCompileCodeAndDoClassTest3() {
- Cute.blackBoxTest().given().processors()
+ Cute.blackBoxTest().given().noProcessors()
.andSourceFiles("/TestClassWithInnerClasses.java")
.whenCompiled()
.thenExpectThat()
@@ -1050,7 +1075,7 @@ public void doTests(CuteClassLoader cuteClassLoader) throws Exception{
@Test()
public void blackBoxTest_justCompileCodeAndDoClassTest4() {
- Cute.blackBoxTest().given().processors()
+ Cute.blackBoxTest().given().noProcessors()
.andSourceFiles("/TestClassWithInnerClasses.java")
.whenCompiled()
.thenExpectThat()
diff --git a/cute/src/test/java/io/toolisticon/cute/FileObjectUtilsTest.java b/cute/src/test/java/io/toolisticon/cute/FileObjectUtilsTest.java
new file mode 100644
index 0000000..75201e7
--- /dev/null
+++ b/cute/src/test/java/io/toolisticon/cute/FileObjectUtilsTest.java
@@ -0,0 +1,38 @@
+package io.toolisticon.cute;
+
+import org.hamcrest.MatcherAssert;
+import org.hamcrest.Matchers;
+import org.junit.Test;
+
+import javax.tools.FileObject;
+import java.io.BufferedReader;
+import java.io.IOException;
+
+/**
+ * Unit test for {@link FileObjectUtils}.
+ */
+public class FileObjectUtilsTest {
+
+ @Test
+ public void test_fromString() throws IOException {
+
+ FileObject fileObject = FileObjectUtils.fromString("TEST");
+ MatcherAssert.assertThat(fileObject.getCharContent(false), Matchers.is("TEST"));
+ MatcherAssert.assertThat(new BufferedReader(fileObject.openReader(true)).readLine(), Matchers.is("TEST"));
+
+
+
+ }
+
+ @Test
+ public void test_fromResource() throws IOException {
+
+ FileObject fileObject = FileObjectUtils.fromResource("/compiletests/tata.txt");
+ MatcherAssert.assertThat(fileObject.getCharContent(false), Matchers.is("TATA!"));
+ MatcherAssert.assertThat(new BufferedReader(fileObject.openReader(true)).readLine(), Matchers.is("TATA!"));
+
+
+
+ }
+
+}
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 0330abe..3b1a752 100644
--- a/cute/src/test/java/io/toolisticon/cute/integrationtest/CompiledClassesAndGeneratedFilesTest.java
+++ b/cute/src/test/java/io/toolisticon/cute/integrationtest/CompiledClassesAndGeneratedFilesTest.java
@@ -16,6 +16,7 @@
import javax.tools.StandardLocation;
import java.io.BufferedWriter;
import java.io.IOException;
+import java.util.Collections;
import java.util.Set;
/**
@@ -36,6 +37,34 @@ public void testCompiledClassesExist() {
.executeTest();
+ }
+
+ @Test
+ public void testCompiledClassesExist_withProcessorCollection() {
+
+ Cute.blackBoxTest()
+ .given().processors(Collections.singletonList(SimpleTestProcessor1.class))
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java"))
+ .whenCompiled()
+ .thenExpectThat().compilationSucceeds()
+ .andThat().javaFileObject(StandardLocation.CLASS_OUTPUT, "io.toolisticon.cute.integrationtest.CompiledClassesAndGeneratedFilesExistTestcase", JavaFileObject.Kind.CLASS).exists()
+ .executeTest();
+
+
+ }
+
+ @Test
+ public void testCompiledClassesExist_withSingleProcessor() {
+
+ Cute.blackBoxTest()
+ .given().processor(SimpleTestProcessor1.class)
+ .andSourceFiles(JavaFileObjectUtils.readFromResource("/integrationtest/CompiledClassesAndGeneratedFilesExistTestcase.java"))
+ .whenCompiled()
+ .thenExpectThat().compilationSucceeds()
+ .andThat().javaFileObject(StandardLocation.CLASS_OUTPUT, "io.toolisticon.cute.integrationtest.CompiledClassesAndGeneratedFilesExistTestcase", JavaFileObject.Kind.CLASS).exists()
+ .executeTest();
+
+
}
diff --git a/cute/src/test/resources/compiletests/tata.txt b/cute/src/test/resources/compiletests/tata.txt
new file mode 100644
index 0000000..9d12ae3
--- /dev/null
+++ b/cute/src/test/resources/compiletests/tata.txt
@@ -0,0 +1 @@
+TATA!
\ No newline at end of file
diff --git a/extension/api/pom.xml b/extension/api/pom.xml
index b93de35..b34f957 100644
--- a/extension/api/pom.xml
+++ b/extension/api/pom.xml
@@ -7,7 +7,7 @@
io.toolisticon.cute
extension-parent
- 1.0.1
+ 1.1.0
extension-api
diff --git a/extension/junit4/pom.xml b/extension/junit4/pom.xml
index ff9e629..7dccc94 100644
--- a/extension/junit4/pom.xml
+++ b/extension/junit4/pom.xml
@@ -8,7 +8,7 @@
io.toolisticon.cute
extension-parent
- 1.0.1
+ 1.1.0
extension-junit4
diff --git a/extension/junit5/pom.xml b/extension/junit5/pom.xml
index 88978fa..6130b57 100644
--- a/extension/junit5/pom.xml
+++ b/extension/junit5/pom.xml
@@ -8,7 +8,7 @@
io.toolisticon.cute
extension-parent
- 1.0.1
+ 1.1.0
extension-junit5
diff --git a/extension/modulesupport/pom.xml b/extension/modulesupport/pom.xml
index 3e734a3..25af9c1 100644
--- a/extension/modulesupport/pom.xml
+++ b/extension/modulesupport/pom.xml
@@ -7,7 +7,7 @@
io.toolisticon.cute
extension-parent
- 1.0.1
+ 1.1.0
extension-modulesupport
diff --git a/extension/plainjava/pom.xml b/extension/plainjava/pom.xml
index 7b57cc3..6198d0b 100644
--- a/extension/plainjava/pom.xml
+++ b/extension/plainjava/pom.xml
@@ -8,7 +8,7 @@
io.toolisticon.cute
extension-parent
- 1.0.1
+ 1.1.0
extension-plainjava
diff --git a/extension/pom.xml b/extension/pom.xml
index bea82a6..555fe6d 100644
--- a/extension/pom.xml
+++ b/extension/pom.xml
@@ -7,7 +7,7 @@
io.toolisticon.cute
cute-parent
- 1.0.1
+ 1.1.0
extension-parent
diff --git a/extension/testng/pom.xml b/extension/testng/pom.xml
index bf6823f..798702c 100644
--- a/extension/testng/pom.xml
+++ b/extension/testng/pom.xml
@@ -7,7 +7,7 @@
io.toolisticon.cute
extension-parent
- 1.0.1
+ 1.1.0
extension-testng
diff --git a/integration-test/java9/namedAutomaticModule/pom.xml b/integration-test/java9/namedAutomaticModule/pom.xml
index 8296254..f303124 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.0.1
+ 1.1.0
integration-test-java9-namedAutomaticModule
diff --git a/integration-test/java9/pom.xml b/integration-test/java9/pom.xml
index c2cb2a8..dd581e3 100644
--- a/integration-test/java9/pom.xml
+++ b/integration-test/java9/pom.xml
@@ -8,7 +8,7 @@
io.toolisticon.cute
integration-test-parent
- 1.0.1
+ 1.1.0
integration-test-java9-parent
diff --git a/integration-test/java9/regularTestModule/pom.xml b/integration-test/java9/regularTestModule/pom.xml
index 4850be9..3ce2017 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.0.1
+ 1.1.0
integration-test-java9-regularModule
diff --git a/integration-test/java9/test/pom.xml b/integration-test/java9/test/pom.xml
index 0da96a2..c7edfab 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.0.1
+ 1.1.0
integration-test-java9-test
diff --git a/integration-test/java9/unnamedAutomaticModule/pom.xml b/integration-test/java9/unnamedAutomaticModule/pom.xml
index f37ddfa..df8b25e 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.0.1
+ 1.1.0
integration-test-java9-unnamedAutomaticModule
diff --git a/integration-test/junit4/pom.xml b/integration-test/junit4/pom.xml
index 58f503e..5f1a675 100644
--- a/integration-test/junit4/pom.xml
+++ b/integration-test/junit4/pom.xml
@@ -8,7 +8,7 @@
io.toolisticon.cute
integration-test-parent
- 1.0.1
+ 1.1.0
integration-test-junit4
diff --git a/integration-test/junit5/pom.xml b/integration-test/junit5/pom.xml
index c112ed8..3780f94 100644
--- a/integration-test/junit5/pom.xml
+++ b/integration-test/junit5/pom.xml
@@ -8,7 +8,7 @@
io.toolisticon.cute
integration-test-parent
- 1.0.1
+ 1.1.0
integration-test-junit5
diff --git a/integration-test/pom.xml b/integration-test/pom.xml
index 53993f0..1698ac2 100644
--- a/integration-test/pom.xml
+++ b/integration-test/pom.xml
@@ -7,7 +7,7 @@
io.toolisticon.cute
cute-parent
- 1.0.1
+ 1.1.0
integration-test-parent
diff --git a/integration-test/testng/pom.xml b/integration-test/testng/pom.xml
index 1988fd4..4b9f0e3 100644
--- a/integration-test/testng/pom.xml
+++ b/integration-test/testng/pom.xml
@@ -7,7 +7,7 @@
io.toolisticon.cute
integration-test-parent
- 1.0.1
+ 1.1.0
integration-test-testng
diff --git a/legacy/pom.xml b/legacy/pom.xml
index 7b1737b..8645c7b 100644
--- a/legacy/pom.xml
+++ b/legacy/pom.xml
@@ -8,7 +8,7 @@
io.toolisticon.cute
cute-parent
- 1.0.1
+ 1.1.0
cute-legacy
diff --git a/pom.xml b/pom.xml
index f54e293..0268aa4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
io.toolisticon.cute
cute-parent
- 1.0.1
+ 1.1.0
pom
cute-parent
@@ -85,7 +85,7 @@
0.8.0
- 0.8.3
+ 0.9.1
4.13.1