Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Stamann committed Mar 18, 2024
2 parents 4a306fb + 7d79af3 commit 98f8b69
Show file tree
Hide file tree
Showing 30 changed files with 587 additions and 72 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Black-Box-Compilation test allow you to define testcase source files and to appl
```java
Cute.blackBoxTest()
.given()
.processors(YourProcessorUnderTest.class)
.processor(YourProcessorUnderTest.class)
.andSourceFiles("/exampletestcase/Testcase1.java")
.whenCompiled()
.thenExpectThat()
Expand Down
2 changes: 1 addition & 1 deletion coverage/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>cute-parent</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
</parent>

<name>coverage</name>
Expand Down
2 changes: 1 addition & 1 deletion cute/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>io.toolisticon.cute</groupId>
<artifactId>cute-parent</artifactId>
<version>1.1.0</version>
<version>1.2.0</version>
</parent>

<name>cute</name>
Expand Down
5 changes: 3 additions & 2 deletions cute/src/main/java/io/toolisticon/cute/CompileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public CompileTest(final CuteApi.CompilerTestBB compileTestConfiguration) {
/**
* The compile-test execution main method.
*/
public void executeTest() {
CompilationResult executeTest() {

CompilationResult compilationResult = null;

Expand Down Expand Up @@ -193,6 +193,7 @@ public void executeTest() {

}


} catch (FailingAssertionException e) {

// now trigger failing assertion, but also enrich message with debug output
Expand All @@ -216,7 +217,7 @@ public void executeTest() {


}

return compilationResult;
}


Expand Down
82 changes: 69 additions & 13 deletions cute/src/main/java/io/toolisticon/cute/CompileTestFileManager.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.toolisticon.cute;

import io.toolisticon.cute.Constants;

import javax.tools.FileObject;
import javax.tools.ForwardingJavaFileManager;
import javax.tools.JavaFileManager;
Expand Down Expand Up @@ -59,20 +57,20 @@ public boolean isEmpty() {
}


private final FileObjectCache<JavaFileObject> generatedJavaFileObjectCache = new FileObjectCache<>();
private final FileObjectCache<FileObject> generatedFileObjectCache = new FileObjectCache<>();
private final FileObjectCache<InMemoryOutputJavaFileObject> generatedJavaFileObjectCache = new FileObjectCache<>();
private final FileObjectCache<InMemoryOutputFileObject> generatedFileObjectCache = new FileObjectCache<>();


public CompileTestFileManager(StandardJavaFileManager standardJavaFileManager) {
super(standardJavaFileManager);

}

List<JavaFileObject> getGeneratedJavaFileObjects() {
List<InMemoryOutputJavaFileObject> getGeneratedJavaFileObjects() {
return new ArrayList<>(generatedJavaFileObjectCache.getEntries());
}

List<FileObject> getGeneratedFileObjects() {
List<InMemoryOutputFileObject> getGeneratedFileObjects() {
return new ArrayList<>(generatedFileObjectCache.getEntries());
}

Expand All @@ -84,15 +82,15 @@ public boolean isSameFile(FileObject a, FileObject b) {
@Override
public JavaFileObject getJavaFileForOutput(Location location, String className, JavaFileObject.Kind kind, FileObject sibling) {

JavaFileObject result = new InMemoryOutputJavaFileObject(uriForJavaFileObject(location, className, kind), kind);
InMemoryOutputJavaFileObject result = new InMemoryOutputJavaFileObject(location, className, kind);
generatedJavaFileObjectCache.addFileObject(result.toUri(), result);
return result;

}

@Override
public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling) {
JavaFileObject result = new InMemoryOutputJavaFileObject(uriForFileObject(location, packageName, relativeName), JavaFileObject.Kind.OTHER);
InMemoryOutputFileObject result = new InMemoryOutputFileObject(location, packageName, relativeName);
generatedFileObjectCache.addFileObject(result.toUri(), result);
return result;
}
Expand Down Expand Up @@ -183,14 +181,18 @@ private static URI uriForJavaFileObject(Location location, String className, Jav
}


public static class InMemoryOutputJavaFileObject extends SimpleJavaFileObject implements OutputStreamCallback {
public static abstract class AbstractInMemoryOutputFileObject extends SimpleJavaFileObject implements OutputStreamCallback {

private byte[] content = new byte[0];

public InMemoryOutputJavaFileObject(URI uri, Kind kind) {
public AbstractInMemoryOutputFileObject(URI uri, Kind kind) {
super(uri, kind);
}

public byte[] getContent() {
return content;
}

@Override
public void setContent(byte[] content) {
this.content = content != null ? content : new byte[0];
Expand All @@ -212,16 +214,70 @@ public Reader openReader(boolean ignoreEncodingErrors) {
}

@Override
public CharSequence getCharContent(boolean ignoreEncodingErrors){
public CharSequence getCharContent(boolean ignoreEncodingErrors) {
return new String(content);
}

@Override
public Writer openWriter(){
public Writer openWriter() {
return new OutputStreamWriter(openOutputStream());
}
}

public static class InMemoryOutputJavaFileObject extends AbstractInMemoryOutputFileObject {

private final Location location;
private final String className;
private final JavaFileObject.Kind kind;

InMemoryOutputJavaFileObject(Location location, String className, JavaFileObject.Kind kind) {
super(uriForJavaFileObject(location, className, kind), kind);
this.location = location;
this.className = className;
this.kind = kind;
}

public Location getLocation() {
return location;
}

public String getClassName() {
return className;
}

@Override
public Kind getKind() {
return kind;
}
}

public static class InMemoryOutputFileObject extends AbstractInMemoryOutputFileObject {

private final Location location;
private final String packageName;
private final String relativeName;

InMemoryOutputFileObject(Location location, String packageName, String relativeName) {
super(uriForFileObject(location, packageName, relativeName), JavaFileObject.Kind.OTHER);
this.location = location;
this.packageName = packageName;
this.relativeName = relativeName;
}


public Location getLocation() {
return location;
}

public String getPackageName() {
return packageName;
}

public String getRelativeName() {
return relativeName;
}
}

/**
* Does call a callback function on close to set content.
* Have to check if it is sufficient to pass content on close.
Expand All @@ -243,7 +299,7 @@ public void close() throws IOException {
}

@Override
public void write( byte[] b) throws IOException {
public void write(byte[] b) throws IOException {
super.write(b);
outputStreamCallback.setContent(this.toByteArray());
}
Expand Down
Loading

0 comments on commit 98f8b69

Please sign in to comment.