2929import spoon .test .processing .processors .MyProcessor ;
3030import spoon .test .template .testclasses .AssertToIfAssertedStatementTemplate ;
3131
32+ import spoon .reflect .declaration .CtType ;
33+ import spoon .reflect .factory .Factory ;
34+ import spoon .testing .utils .ModelTest ;
35+
3236import java .io .File ;
3337import java .io .IOException ;
3438import java .nio .file .Files ;
3539import java .nio .file .Path ;
40+ import java .util .List ;
3641
37- import static org .junit . jupiter .api .Assertions .assertArrayEquals ;
42+ import static org .assertj . core .api .Assertions .assertThatThrownBy ;
3843import static org .junit .jupiter .api .Assertions .assertFalse ;
3944import static org .junit .jupiter .api .Assertions .assertTrue ;
4045import static org .junit .jupiter .api .Assertions .fail ;
41- import static spoon .testing .Assert .assertThat ;
46+ import static spoon .testing .assertions .SpoonAssertions .assertThat ;
47+ import static spoon .testing .utils .ModelUtils .build ;
4248
4349public class ProcessingTest {
4450
@@ -130,8 +136,8 @@ public void testNullPointerException() throws IOException {
130136 l .run ();
131137 }
132138
133- @ Test
134- public void testTemplateNotInOutput () throws IOException {
139+ @ ModelTest ( "src/test/resources/spoon/test/template/SimpleIfAsserted.java" )
140+ public void testTemplateNotInOutput (Factory expectedFactory ) throws IOException {
135141 // https://github.com/INRIA/spoon/issues/2987
136142 class AssertProcessor extends AbstractProcessor <CtAssert <?>> {
137143 public void process (CtAssert <?> element ) {
@@ -141,24 +147,29 @@ public void process(CtAssert<?> element) {
141147 );
142148 }
143149 }
144-
150+
145151 String templatePath = "src/test/java/spoon/test/template/testclasses/AssertToIfAssertedStatementTemplate.java" ;
146152 String resourcePath = "src/test/resources/spoon/test/template/" ;
147-
153+
148154 final Launcher l = new Launcher ();
149155 Path outputPath = Files .createTempDirectory ("emptydir" );
150-
156+
151157 l .addProcessor (new AssertProcessor ());
152158 l .addTemplateResource (new FileSystemFile (templatePath ));
153-
159+
154160 l .addInputResource (resourcePath + "SimpleAssert.java" );
155161 l .setSourceOutputDirectory (outputPath .toFile ());
156162 l .run ();
157163
158164 // If template is applied to itself then there will be modified spoon/...Template.java on output
159- assertArrayEquals (new String []{"SimpleAssert.java" }, outputPath .toFile ().list (), "Template source found in output" );
165+ org .assertj .core .api .Assertions .assertThat (outputPath .toFile ().list ())
166+ .containsExactly ("SimpleAssert.java" );
160167 // Check that the template worked as intended
161- assertThat (outputPath .toString () + "/SimpleAssert.java" )
162- .isEqualTo (resourcePath + "SimpleIfAsserted.java" );
168+ List <CtType <?>> actualTypes = build (new File (outputPath .toString () + "/SimpleAssert.java" )).Type ().getAll ();
169+ List <CtType <?>> expectedTypes = expectedFactory .Type ().getAll ();
170+ org .assertj .core .api .Assertions .assertThat (actualTypes ).hasSameSizeAs (expectedTypes );
171+ for (int i = 0 ; i < actualTypes .size (); i ++) {
172+ assertThat (actualTypes .get (i )).isEqualTo (expectedTypes .get (i ));
173+ }
163174 }
164175}
0 commit comments