55 */
66package org .mapstruct .tools .gem .processor ;
77
8+ import java .io .File ;
9+ import java .io .FileInputStream ;
810import java .io .IOException ;
11+ import java .io .InputStream ;
12+ import java .io .UncheckedIOException ;
913import java .net .URI ;
14+ import java .nio .file .Path ;
1015import java .util .Arrays ;
16+ import java .util .Collections ;
1117import javax .annotation .processing .Processor ;
1218import javax .tools .Diagnostic ;
1319import javax .tools .DiagnosticCollector ;
1824import javax .tools .StandardLocation ;
1925import javax .tools .ToolProvider ;
2026
27+ import org .assertj .core .api .JUnitSoftAssertions ;
2128import org .junit .Rule ;
2229import org .junit .Test ;
2330import org .junit .rules .TemporaryFolder ;
@@ -29,6 +36,9 @@ public class ProcessorTest {
2936 // CHECKSTYLE:OFF
3037 @ Rule
3138 public final TemporaryFolder tempDir = new TemporaryFolder (); //NOSONAR
39+
40+ @ Rule
41+ public final JUnitSoftAssertions softly = new JUnitSoftAssertions ();
3242 // CHECKSTYLE:ON
3343
3444 @ Test
@@ -45,7 +55,10 @@ private void compile(Processor processor, JavaFileObject... compilationUnits) th
4555
4656 DiagnosticCollector <JavaFileObject > diagnostics = new DiagnosticCollector <JavaFileObject >();
4757 StandardJavaFileManager fileManager = compiler .getStandardFileManager ( diagnostics , null , null );
48- fileManager .setLocation ( StandardLocation .CLASS_OUTPUT , Arrays .asList ( tempDir .getRoot () ) );
58+ File classesDir = tempDir .newFolder ( "classes" );
59+ fileManager .setLocation ( StandardLocation .CLASS_OUTPUT , Collections .singletonList ( classesDir ) );
60+ File generatedDir = tempDir .newFolder ( "generated" );
61+ fileManager .setLocation ( StandardLocation .SOURCE_OUTPUT , Collections .singletonList ( generatedDir ) );
4962
5063 JavaCompiler .CompilationTask task = compiler .getTask (
5164 null ,
@@ -65,6 +78,32 @@ private void compile(Processor processor, JavaFileObject... compilationUnits) th
6578 System .err .println ( diagnostic );
6679 }
6780 assertThat ( success ).isTrue ();
81+
82+
83+ assertGeneratedFileContent ( "BuilderGem" , generatedDir );
84+ assertGeneratedFileContent ( "SomeAnnotationGem" , generatedDir );
85+ assertGeneratedFileContent ( "SomeAnnotationsGem" , generatedDir );
86+ assertGeneratedFileContent ( "SomeArrayAnnotationGem" , generatedDir );
87+ }
88+
89+ protected void assertGeneratedFileContent (String gemName , File generatedDir ) {
90+ Path gemPath = generatedDir .toPath ().resolve ( "org/mapstruct/tools/gem/processor/" + gemName + ".java" );
91+ softly .assertThat ( gemPath )
92+ .as ( gemName )
93+ .exists ();
94+
95+ try (InputStream generatedGemStream = new FileInputStream ( gemPath .toFile () );
96+ InputStream expectedGemStream = getClass ().getClassLoader ()
97+ .getResourceAsStream ( "fixtures/org/mapstruct/tools/gem/processor/" + gemName + ".java" )
98+ ) {
99+ softly .assertThat ( generatedGemStream )
100+ .as ( gemName )
101+ .hasSameContentAs ( expectedGemStream );
102+ }
103+ catch ( IOException e ) {
104+ throw new UncheckedIOException ( "Failed to assert generated content for gem " + gemName , e );
105+ }
106+
68107 }
69108
70109 private static class StringJavaFileObject extends SimpleJavaFileObject {
0 commit comments