Add tests for different classes
This commit is contained in:
parent
e0f7f95bed
commit
572f41ffd4
@ -1,12 +1,9 @@
|
|||||||
package inferWildcards;
|
package inferWildcards;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.tools.JavaCompiler;
|
|
||||||
import javax.tools.StandardJavaFileManager;
|
|
||||||
import javax.tools.ToolProvider;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -22,40 +19,111 @@ import de.dhbwstuttgart.typeinference.constraints.Pair;
|
|||||||
public class TestInferWildcardsJavaTx
|
public class TestInferWildcardsJavaTx
|
||||||
{
|
{
|
||||||
|
|
||||||
private JavaCompiler compiler;
|
private String resourcePath;
|
||||||
private StandardJavaFileManager fileManager;
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup () {
|
public void setup () {
|
||||||
compiler = ToolProvider.getSystemJavaCompiler();
|
resourcePath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
||||||
fileManager = compiler.getStandardFileManager(null, null, null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private JavaTXCompiler getCompiler (String filename) throws ClassNotFoundException, IOException {
|
||||||
public void test () throws Exception {
|
File[] files1 = { new File(resourcePath + "/" + filename) };
|
||||||
String resourcePath = System.getProperty("user.dir") + "/src/test/resources/inferWildcards";
|
return new JavaTXCompiler(files1);
|
||||||
File[] files1 = { new File(resourcePath + "/TestClassWildcards.java") };
|
}
|
||||||
|
|
||||||
JavaTXCompiler javaTXCompiler = new JavaTXCompiler(files1);
|
private ReplaceTypeparamVisitor generateTph (JavaTXCompiler javaTXCompiler) {
|
||||||
|
|
||||||
// Manipulate AST
|
|
||||||
Map<File, SourceFile> sourceFiles = javaTXCompiler.getSourceFiles();
|
Map<File, SourceFile> sourceFiles = javaTXCompiler.getSourceFiles();
|
||||||
ReplaceTypeparamVisitor visitor = new ReplaceTypeparamVisitor();
|
ReplaceTypeparamVisitor visitor = new ReplaceTypeparamVisitor();
|
||||||
sourceFiles.entrySet().forEach(e -> e.getValue().accept(visitor));
|
sourceFiles.entrySet().forEach(e -> e.getValue().accept(visitor));
|
||||||
|
return visitor;
|
||||||
|
}
|
||||||
|
|
||||||
// Generate Constraints
|
private ConstraintSet getGeneratedConstraints (ReplaceTypeparamVisitor visitor) {
|
||||||
Map<TypePlaceholder, RefType> tphMap = visitor.getTphMap();
|
Map<TypePlaceholder, RefType> tphMap = visitor.getTphMap();
|
||||||
System.out.println(tphMap);
|
System.out.println(tphMap);
|
||||||
ConstraintSet generatedConstraints = ConstraintsGenerationUtils.generateConstraints(tphMap);
|
return ConstraintsGenerationUtils.generateConstraints(tphMap);
|
||||||
// System.out.println(generatedConstraints);
|
}
|
||||||
|
|
||||||
|
private ConstraintSet<Pair> combineConstraints (JavaTXCompiler javaTXCompiler, ConstraintSet generatedConstraints)
|
||||||
// Constraints
|
throws ClassNotFoundException, IOException {
|
||||||
ConstraintSet<Pair> constraints = javaTXCompiler.getConstraints();
|
ConstraintSet<Pair> constraints = javaTXCompiler.getConstraints();
|
||||||
constraints.addAll(generatedConstraints);
|
constraints.addAll(generatedConstraints);
|
||||||
|
|
||||||
System.out.println(constraints);
|
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();
|
// List<ResultSet> typeInference = javaTXCompiler.typeInference();
|
||||||
// System.out.println(typeInference);
|
// System.out.println(typeInference);
|
||||||
}
|
}
|
||||||
|
13
src/test/resources/inferWildcards/TestClassWildcardsMap.java
Normal file
13
src/test/resources/inferWildcards/TestClassWildcardsMap.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,9 @@
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.lang.String;
|
import java.lang.String;
|
||||||
import java.lang.Object;
|
import java.lang.Object;
|
||||||
|
|
||||||
class TestClassWildcards
|
class TestClassWildcardsSingle
|
||||||
{
|
{
|
||||||
|
|
||||||
private List<String> field1;
|
private List<String> field1;
|
||||||
@ -39,9 +38,4 @@ class TestClassWildcards
|
|||||||
input.add(string);
|
input.add(string);
|
||||||
return listOfObjects;
|
return listOfObjects;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Collection<Object>> test3(List<List<String>> input){
|
|
||||||
List<Collection<Object>> listOfObjects = input;
|
|
||||||
return listOfObjects;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user