Skip to content

Commit

Permalink
test: add tests for JavaOutputProcessor class (#4043)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rohitesh-Kumar-Jain authored Jul 16, 2021
1 parent cee869f commit 09a609b
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions src/test/java/spoon/support/JavaOutputProcessorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package spoon.support;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import spoon.Launcher;
import spoon.reflect.declaration.*;
import spoon.reflect.factory.Factory;

import java.io.File;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

class JavaOutputProcessorTest {


@Test
void testCreateModuleFileAssertAnnotationFileCreated(@TempDir File tempDir) {
// contract : createModuleFile creates an annotation file for module and prints it

// arrange
Launcher launcher = new Launcher();
launcher.setSourceOutputDirectory(tempDir.getAbsolutePath());
launcher.getEnvironment().setComplianceLevel(9);
Factory factory = launcher.getFactory();

String moduleName = "emptyModule";
CtModule module = factory.Module().getOrCreate(moduleName);
JavaOutputProcessor javaOutputProcessor = new JavaOutputProcessor();
javaOutputProcessor.setFactory(factory);

// act
javaOutputProcessor.process(module);

// assert
File expectedFile = tempDir.toPath().resolve("emptyModule/module-info.java").toFile();
assertTrue(expectedFile.exists());
assertEquals(1, javaOutputProcessor.printedFiles.size());
}

@Test
void testCreatePackageFileAssertAnnotationFileCreated(@TempDir File tempDir) {
// contract : createPackageFile creates a package annotation file for rootPackage

// arrange
Launcher launcher = new Launcher();
launcher.setSourceOutputDirectory(tempDir.getAbsolutePath());
Factory factory = launcher.getFactory();

CtPackage rootPackage = factory.Package().getOrCreate("spoon.support.JavaOutputProcessor");
JavaOutputProcessor javaOutputProcessor = new JavaOutputProcessor();
javaOutputProcessor.setFactory(factory);

// act
javaOutputProcessor.process(rootPackage);

// assert
File expectedFile = tempDir.toPath().resolve("spoon/support/JavaOutputProcessor/package-info.java").toFile();
assertTrue(expectedFile.exists());
assertEquals(1, javaOutputProcessor.printedFiles.size());
}
}

0 comments on commit 09a609b

Please sign in to comment.