Add tests for different classes

This commit is contained in:
Till Schnell 2021-04-08 18:31:02 +02:00
parent e0f7f95bed
commit 572f41ffd4
5 changed files with 133 additions and 27 deletions

View File

@ -1,12 +1,9 @@
package inferWildcards;
import java.io.File;
import java.io.IOException;
import java.util.Map;
import javax.tools.JavaCompiler;
import javax.tools.StandardJavaFileManager;
import javax.tools.ToolProvider;
import org.junit.Before;
import org.junit.Test;
@ -22,40 +19,111 @@ import de.dhbwstuttgart.typeinference.constraints.Pair;
public class TestInferWildcardsJavaTx
{
private JavaCompiler compiler;
private StandardJavaFileManager fileManager;
private String resourcePath;
@Before
public void setup () {
compiler = ToolProvider.getSystemJavaCompiler();
fileManager = compiler.getStandardFileManager(null, null, null);
resourcePath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
}
@Test
public void test () throws Exception {
String resourcePath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
File[] files1 = { new File(resourcePath + "/TestClassWildcards.java") };
private JavaTXCompiler getCompiler (String filename) throws ClassNotFoundException, IOException {
File[] files1 = { new File(resourcePath + "/" + filename) };
return new JavaTXCompiler(files1);
}
JavaTXCompiler javaTXCompiler = new JavaTXCompiler(files1);
// Manipulate AST
private ReplaceTypeparamVisitor generateTph (JavaTXCompiler javaTXCompiler) {
Map<File, SourceFile> sourceFiles = javaTXCompiler.getSourceFiles();
ReplaceTypeparamVisitor visitor = new ReplaceTypeparamVisitor();
sourceFiles.entrySet().forEach(e -> e.getValue().accept(visitor));
return visitor;
}
// Generate Constraints
private ConstraintSet getGeneratedConstraints (ReplaceTypeparamVisitor visitor) {
Map<TypePlaceholder, RefType> tphMap = visitor.getTphMap();
System.out.println(tphMap);
ConstraintSet generatedConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
// System.out.println(generatedConstraints);
return ConstraintsGenerationUtils.generateConstraints(tphMap);
}
// Constraints
private ConstraintSet<Pair> combineConstraints (JavaTXCompiler javaTXCompiler, ConstraintSet generatedConstraints)
throws ClassNotFoundException, IOException {
ConstraintSet<Pair> constraints = javaTXCompiler.getConstraints();
constraints.addAll(generatedConstraints);
System.out.println(constraints);
return constraints;
}
@Test
public void testSingle () throws Exception {
JavaTXCompiler javaTXCompiler = getCompiler("TestClassWildcardsSingle.java");
// Manipulate AST
ReplaceTypeparamVisitor visitor = generateTph(javaTXCompiler);
// Generate Constraints
ConstraintSet generatedConstraints = getGeneratedConstraints(visitor);
// System.out.println(generatedConstraints);
// Constraints
ConstraintSet<Pair> constraints = combineConstraints(javaTXCompiler, generatedConstraints);
// List<ResultSet> typeInference = javaTXCompiler.typeInference();
// System.out.println(typeInference);
}
@Test
public void testNested () throws Exception {
JavaTXCompiler javaTXCompiler = getCompiler("TestClassWildcardsNested.java");
// Manipulate AST
ReplaceTypeparamVisitor visitor = generateTph(javaTXCompiler);
// Generate Constraints
ConstraintSet generatedConstraints = getGeneratedConstraints(visitor);
// System.out.println(generatedConstraints);
// Constraints
ConstraintSet<Pair> constraints = combineConstraints(javaTXCompiler, generatedConstraints);
// List<ResultSet> typeInference = javaTXCompiler.typeInference();
// System.out.println(typeInference);
}
@Test
public void testMap () throws Exception {
JavaTXCompiler javaTXCompiler = getCompiler("TestClassWildcardsMap.java");
// Manipulate AST
ReplaceTypeparamVisitor visitor = generateTph(javaTXCompiler);
// Generate Constraints
ConstraintSet generatedConstraints = getGeneratedConstraints(visitor);
// System.out.println(generatedConstraints);
// Constraints
ConstraintSet<Pair> constraints = combineConstraints(javaTXCompiler, generatedConstraints);
// List<ResultSet> typeInference = javaTXCompiler.typeInference();
// System.out.println(typeInference);
}
@Test
public void testMapNested () throws Exception {
JavaTXCompiler javaTXCompiler = getCompiler("TestClassWildcardsMapNested.java");
// Manipulate AST
ReplaceTypeparamVisitor visitor = generateTph(javaTXCompiler);
// Generate Constraints
ConstraintSet generatedConstraints = getGeneratedConstraints(visitor);
// System.out.println(generatedConstraints);
// Constraints
ConstraintSet<Pair> constraints = combineConstraints(javaTXCompiler, generatedConstraints);
// List<ResultSet> typeInference = javaTXCompiler.typeInference();
// System.out.println(typeInference);
}

View File

@ -0,0 +1,13 @@
import java.lang.String;
import java.lang.Object;
import java.util.Map;
import java.lang.Integer;
class TestClassWildcardsMap
{
public Map<Integer, Object> test4(Map<Integer, String> input){
Map<Integer, Object> listOfObjects = input;
return listOfObjects;
}
}

View File

@ -0,0 +1,16 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.lang.String;
import java.lang.Object;
import java.util.Map;
import java.lang.Integer;
class TestClassWildcardsMapNested
{
public Map<Integer, Collection<Object>> test(Map<Integer, List<String>> input){
Map<Integer, Collection<Object>> listOfObjects = input;
return listOfObjects;
}
}

View File

@ -0,0 +1,15 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.lang.String;
import java.lang.Object;
import java.util.Map;
import java.lang.Integer;
class TestClassWildcardsNested
{
public List<Collection<Object>> test3(List<List<String>> input){
List<Collection<Object>> listOfObjects = input;
return listOfObjects;
}
}

View File

@ -1,10 +1,9 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.lang.String;
import java.lang.Object;
class TestClassWildcards
class TestClassWildcardsSingle
{
private List<String> field1;
@ -39,9 +38,4 @@ class TestClassWildcards
input.add(string);
return listOfObjects;
}
public List<Collection<Object>> test3(List<List<String>> input){
List<Collection<Object>> listOfObjects = input;
return listOfObjects;
}
}