Skip to content

Commit

Permalink
test: migrate GetBinaryFilesTest to JUnit 5 (#4486)
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinWitt authored Jan 14, 2022
1 parent 89980bb commit ab769db
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/test/java/spoon/test/compilationunit/GetBinaryFilesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,37 @@
*/
package spoon.test.compilationunit;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import spoon.Launcher;
import spoon.SpoonModelBuilder;
import spoon.reflect.cu.CompilationUnit;

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import spoon.Launcher;
import spoon.SpoonModelBuilder;
import spoon.reflect.cu.CompilationUnit;

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

/**
* Tests {@link CompilationUnit#getBinaryFiles()}.
*/
public class GetBinaryFilesTest {

@Rule
public TemporaryFolder tmpFolder = new TemporaryFolder();
@TempDir
Path tmpFolder;

@Test
public void testSingleBinary() {
final String input = "./src/test/resources/compilation/compilation-tests/IBar.java";
final Launcher launcher = new Launcher();
launcher.addInputResource(input);
launcher.setBinaryOutputDirectory(tmpFolder.getRoot());
launcher.setBinaryOutputDirectory(tmpFolder.toString());
launcher.buildModel();
launcher.getModelBuilder().compile(SpoonModelBuilder.InputType.FILES);

Expand All @@ -60,13 +61,13 @@ public void testSingleBinary() {

@Test
public void testExistingButNotBuiltBinary() throws IOException {
tmpFolder.newFolder("compilation");
tmpFolder.newFile("compilation/IBar$Test.class");
new File(tmpFolder.toFile(), "compilation").mkdir();
new File(tmpFolder.toFile(), "compilation/IBar$Test.class").createNewFile();

final String input = "./src/test/resources/compilation/compilation-tests/IBar.java";
final Launcher launcher = new Launcher();
launcher.addInputResource(input);
launcher.setBinaryOutputDirectory(tmpFolder.getRoot());
launcher.setBinaryOutputDirectory(tmpFolder.toString());
launcher.buildModel();
launcher.getModelBuilder().compile(SpoonModelBuilder.InputType.FILES);

Expand All @@ -89,7 +90,7 @@ public void testMultiClassInSingleFile() throws IOException {
final String input = "./src/test/resources/compilation/compilation-tests/";
final Launcher launcher = new Launcher();
launcher.addInputResource(input);
launcher.setBinaryOutputDirectory(tmpFolder.getRoot());
launcher.setBinaryOutputDirectory(tmpFolder.toString());
launcher.buildModel();
launcher.getModelBuilder().compile(SpoonModelBuilder.InputType.FILES);

Expand All @@ -114,7 +115,7 @@ public void testNestedTypes() throws IOException {
final String input = "./src/test/java/spoon/test/imports/testclasses/internal/PublicInterface2.java";
final Launcher launcher = new Launcher();
launcher.addInputResource(input);
launcher.setBinaryOutputDirectory(tmpFolder.getRoot());
launcher.setBinaryOutputDirectory(tmpFolder.toString());
launcher.buildModel();
launcher.getModelBuilder().compile(SpoonModelBuilder.InputType.FILES);

Expand All @@ -136,7 +137,7 @@ public void testAnonymousClasses() throws IOException {
final String input = "./src/test/java/spoon/test/secondaryclasses/testclasses/AnonymousClass.java";
final Launcher launcher = new Launcher();
launcher.addInputResource(input);
launcher.setBinaryOutputDirectory(tmpFolder.getRoot());
launcher.setBinaryOutputDirectory(tmpFolder.toString());
launcher.buildModel();
launcher.getModelBuilder().compile(SpoonModelBuilder.InputType.FILES);

Expand Down

0 comments on commit ab769db

Please # to comment.