71
71
import spoon .test .imports .testclasses .Tacos ;
72
72
import spoon .test .imports .testclasses .ToBeModified ;
73
73
import spoon .test .imports .testclasses .badimportissue3320 .source .TestSource ;
74
+ import spoon .testing .utils .ModelTest ;
74
75
import spoon .testing .utils .ModelUtils ;
75
76
76
77
import java .io .BufferedReader ;
@@ -1289,17 +1290,9 @@ public void testImportStarredPackageWithNonVisibleClass() throws IOException {
1289
1290
assertEquals (CtImportKind .ALL_TYPES , cu .getImports ().iterator ().next ().getImportKind ());
1290
1291
}
1291
1292
1292
- @ Test
1293
- public void testImportWithGenerics () {
1293
+ @ ModelTest ( value = "./src/test/resources/import-with-generics/TestWithGenerics.java" , autoImport = true )
1294
+ public void testImportWithGenerics (Launcher launcher ) {
1294
1295
// contract: in noclasspath autoimport, we should be able to use generic type
1295
- final Launcher launcher = new Launcher ();
1296
- // this class is not compilable 'spoon.test.imports.testclasses.withgenerics.Target' does not exist
1297
- launcher .addInputResource ("./src/test/resources/import-with-generics/TestWithGenerics.java" );
1298
- launcher .getEnvironment ().setAutoImports (true );
1299
- launcher .getEnvironment ().setNoClasspath (true );
1300
- launcher .setSourceOutputDirectory ("./target/import-with-generics" );
1301
- launcher .run ();
1302
-
1303
1296
PrettyPrinter prettyPrinter = launcher .createPrettyPrinter ();
1304
1297
CtType element = launcher .getFactory ().Class ().get ("spoon.test.imports.testclasses.TestWithGenerics" );
1305
1298
List <CtType <?>> toPrint = new ArrayList <>();
@@ -1441,12 +1434,9 @@ public void testNullable() throws Exception {
1441
1434
assertNotNull (launcher .getFactory ().Type ().get ("TestNullable" ));
1442
1435
}
1443
1436
1444
- @ Test
1445
- public void testBug2369_fqn () {
1437
+ @ ModelTest ( "./src/test/java/spoon/test/imports/testclasses/JavaLongUse.java" )
1438
+ public void testBug2369_fqn (Factory factory ) {
1446
1439
// see https://github.com/INRIA/spoon/issues/2369
1447
- final Launcher launcher = new Launcher ();
1448
- launcher .addInputResource ("./src/test/java/spoon/test/imports/testclasses/JavaLongUse.java" );
1449
- launcher .buildModel ();
1450
1440
final String nl = System .lineSeparator ();
1451
1441
assertEquals ("public class JavaLongUse {" + nl +
1452
1442
" public class Long {}" + nl +
@@ -1458,16 +1448,12 @@ public void testBug2369_fqn() {
1458
1448
" public static void main(java.lang.String[] args) {" + nl +
1459
1449
" java.lang.System.out.println(spoon.test.imports.testclasses.JavaLongUse.method());" + nl +
1460
1450
" }" + nl +
1461
- "}" , launcher . getFactory () .Type ().get ("spoon.test.imports.testclasses.JavaLongUse" ).toString ());
1451
+ "}" , factory .Type ().get ("spoon.test.imports.testclasses.JavaLongUse" ).toString ());
1462
1452
}
1463
1453
1464
- @ Test
1465
- public void testBug2369_autoimports () {
1454
+ @ ModelTest ( value = "./src/test/java/spoon/test/imports/testclasses/JavaLongUse.java" , autoImport = true )
1455
+ public void testBug2369_autoimports (Launcher launcher ) {
1466
1456
// https://github.com/INRIA/spoon/issues/2369
1467
- final Launcher launcher = new Launcher ();
1468
- launcher .addInputResource ("./src/test/java/spoon/test/imports/testclasses/JavaLongUse.java" );
1469
- launcher .getEnvironment ().setAutoImports (true );
1470
- launcher .buildModel ();
1471
1457
final String nl = System .lineSeparator ();
1472
1458
assertEquals ("public class JavaLongUse {" + nl +
1473
1459
" public class Long {}" + nl +
@@ -1581,31 +1567,23 @@ public void testFQNJavadoc() {
1581
1567
assertThat (output , containsString ("import spoon.SpoonException;" ));
1582
1568
}
1583
1569
}
1584
- @ Test
1585
- public void testImportOnSpoon () throws IOException {
1586
- File targetDir = new File ("./target/import-test" );
1587
- Launcher spoon = new Launcher ();
1588
- spoon .addInputResource ("./src/main/java/spoon/" );
1589
- spoon .getEnvironment ().setAutoImports (true );
1590
- spoon .getEnvironment ().setCommentEnabled (true );
1591
- spoon .getEnvironment ().setSourceOutputDirectory (targetDir );
1592
- spoon .getEnvironment ().setLevel ("warn" );
1593
- spoon .buildModel ();
1594
1570
1595
- PrettyPrinter prettyPrinter = new DefaultJavaPrettyPrinter (spoon .getEnvironment ());
1571
+ @ ModelTest (value = "./src/main/java/spoon/" , autoImport = true )
1572
+ public void testImportOnSpoon (Launcher launcher , CtModel model , Factory factory ) throws IOException {
1573
+ PrettyPrinter prettyPrinter = new DefaultJavaPrettyPrinter (launcher .getEnvironment ());
1596
1574
1597
1575
Map <CtType , List <String >> missingImports = new HashMap <>();
1598
1576
Map <CtType , List <String >> unusedImports = new HashMap <>();
1599
1577
1600
1578
JavaOutputProcessor outputProcessor ;
1601
1579
1602
- for (CtType <?> ctType : spoon . getModel () .getAllTypes ()) {
1580
+ for (CtType <?> ctType : model .getAllTypes ()) {
1603
1581
if (!ctType .isTopLevel ()) {
1604
1582
continue ;
1605
1583
}
1606
1584
1607
1585
outputProcessor = new JavaOutputProcessor (prettyPrinter );
1608
- outputProcessor .setFactory (spoon . getFactory () );
1586
+ outputProcessor .setFactory (factory );
1609
1587
outputProcessor .init ();
1610
1588
1611
1589
Set <String > computedTypeImports = new HashSet <>();
0 commit comments