Beispiel #1
0
  @Test
  public void testOutputOfSpoon() throws Exception {
    final File sourceOutput = new File("./target/spoon/test/output/");
    final SpoonAPI launcher = new Launcher();
    launcher.addInputResource("./src/test/java/spoon/test/api/testclasses");
    launcher.setSourceOutputDirectory(sourceOutput);
    launcher.run();

    assertTrue(sourceOutput.exists());
  }
Beispiel #2
0
 @Before
 public void setUp() throws Exception {
   SpoonAPI launcher = new Launcher();
   launcher.run(
       new String[] {
         "-i", "./src/test/java/spoon/test/constructor/testclasses/",
         "-o", "./target/spooned/"
       });
   factory = launcher.getFactory();
   aClass = factory.Class().get(Tacos.class);
 }
Beispiel #3
0
  @Test
  public void testAddProcessorMethodInSpoonAPI() throws Exception {
    final SpoonAPI launcher = new Launcher();
    launcher.addInputResource("./src/test/java/spoon/test/api/testclasses");
    launcher.setSourceOutputDirectory("./target/spooned");
    final AwesomeProcessor processor = new AwesomeProcessor();
    launcher.addProcessor(processor);
    launcher.run();

    assertEquals(1, processor.getElements().size());
    final CtClass<Bar> actual = processor.getElements().get(0);
    assertEquals(2, actual.getMethods().size());
    assertNotNull(actual.getMethodsByName("prepareMojito").get(0));
    assertNotNull(actual.getMethodsByName("makeMojito").get(0));
  }
Beispiel #4
0
  @Test
  public void testPrintNotAllSourcesInCommandLine() throws Exception {
    final File target = new File("./target/print-not-all/command");
    final SpoonAPI launcher = new Launcher();
    launcher.run(
        new String[] {
          "-i", "./src/main/java", //
          "-o", "./target/print-not-all/command", //
          "-f", "spoon.Launcher:spoon.template.AbstractTemplate", //
          "--noclasspath"
        });

    List<File> list = new ArrayList<>(FileUtils.listFiles(target, new String[] {"java"}, true));
    final List<String> filesName =
        list.stream().map(File::getName).sorted().collect(Collectors.<String>toList());

    assertEquals(2, filesName.size());
    assertEquals("AbstractTemplate.java", filesName.get(0));
    assertEquals("Launcher.java", filesName.get(1));
  }
Beispiel #5
0
  @Test
  public void testPrintNotAllSourcesWithFilter() throws Exception {
    final File target = new File("./target/print-not-all/default");
    final SpoonAPI launcher = new Launcher();
    launcher.getEnvironment().setNoClasspath(true);
    launcher.addInputResource("./src/main/java");
    launcher.setSourceOutputDirectory(target);
    launcher.setOutputFilter(
        new AbstractFilter<CtType<?>>(CtType.class) {
          @Override
          public boolean matches(CtType<?> element) {
            return "spoon.Launcher".equals(element.getQualifiedName())
                || "spoon.template.AbstractTemplate".equals(element.getQualifiedName());
          }
        });
    launcher.run();

    List<File> list = new ArrayList<>(FileUtils.listFiles(target, new String[] {"java"}, true));
    final List<String> filesName =
        list.stream().map(File::getName).sorted().collect(Collectors.<String>toList());

    assertEquals(2, filesName.size());
    assertEquals("AbstractTemplate.java", filesName.get(0));
    assertEquals("Launcher.java", filesName.get(1));
  }
Beispiel #6
0
 @Test
 public void testBasicAPIUsage() throws Exception {
   // this test shows a basic usage of the Launcher API without command line
   // and asserts there is no exception
   SpoonAPI spoon = new Launcher();
   spoon.addInputResource("src/test/resources/spoon/test/api");
   spoon.setSourceOutputDirectory("target/spooned");
   spoon.run();
   Factory factory = spoon.getFactory();
   for (CtPackage p : factory.Package().getAll()) {
     spoon.getEnvironment().debugMessage("package: " + p.getQualifiedName());
   }
   for (CtType<?> s : factory.Class().getAll()) {
     spoon.getEnvironment().debugMessage("class: " + s.getQualifiedName());
   }
 }
Beispiel #7
0
  @Test
  public void testPrintNotAllSourcesWithNames() throws Exception {
    final File target = new File("./target/print-not-all/array");
    final SpoonAPI launcher = new Launcher();
    launcher.getEnvironment().setNoClasspath(true);
    launcher.addInputResource("./src/main/java");
    launcher.setSourceOutputDirectory(target);
    launcher.setOutputFilter("spoon.Launcher", "spoon.template.AbstractTemplate");
    launcher.run();

    List<File> list = new ArrayList<>(FileUtils.listFiles(target, new String[] {"java"}, true));
    final List<String> filesName =
        list.stream().map(File::getName).sorted().collect(Collectors.<String>toList());

    assertEquals(2, filesName.size());
    assertEquals("AbstractTemplate.java", filesName.get(0));
    assertEquals("Launcher.java", filesName.get(1));
  }