Skip to content

Commit

Permalink
test VariableReferenceFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky committed Jan 22, 2017
1 parent 124179b commit ff538a4
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/test/java/spoon/test/query_function/QueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import spoon.reflect.reference.CtExecutableReference;
import spoon.reflect.reference.CtVariableReference;
import spoon.reflect.visitor.chain.CtConsumableFunction;
import spoon.reflect.visitor.filter.ParameterReferenceFunction;
import spoon.reflect.visitor.filter.VariableReferenceFunction;
import spoon.test.query_function.testclasses.packageA.ClassA;

import java.util.HashMap;
Expand Down Expand Up @@ -95,6 +95,22 @@ class Context {
assertEquals(countOfModelClasses, context.classCount);
}

@Test
public void testVariableReferenceFunction() throws Exception {
//visits all the CtVariable elements whose name is "field" and search for all their references
//The test detects whether found references are correct by these two checks:
//1) the each found reference is on the left side of binary operator and on the right side there is unique reference identification number. Like: (field == 7)
//2) the model is searched for all variable references which has same identification number and counts them
//Then it checks that counted number of references and found number of references is same
factory.Package().getRootPackage().filterChildren((CtVariable<?> var)->{
if(var.getSimpleName().equals("field")) {
int value = getLiteralValue(var);
checkVariableAccess(var, value, new VariableReferenceFunction());
}
return false;
}).list();
}

private void checkVariableAccess(CtVariable<?> var, int value, CtConsumableFunction<?> query) {
class Context {
int classCount = 0;
Expand Down

0 comments on commit ff538a4

Please sign in to comment.