Skip to content

Commit

Permalink
Merge pull request #2871 from jlerbsc/master
Browse files Browse the repository at this point in the history
unconfigure symbol solver so as not to potentially disturb tests in o…
  • Loading branch information
jlerbsc committed Oct 26, 2020
2 parents 777aa23 + 5e41381 commit 482eba3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,25 @@

package com.github.javaparser.symbolsolver;

import com.github.javaparser.utils.CodeGenerationUtils;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.junit.jupiter.api.AfterEach;

import com.github.javaparser.ParserConfiguration;
import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.utils.CodeGenerationUtils;

public abstract class AbstractSymbolResolutionTest {

@AfterEach
public void reset() {
// reset configuration to not potentially disturb others tests.
// So we have to set specific configuration between each test.
StaticJavaParser.setConfiguration(new ParserConfiguration());
}

/**
* An initial attempt at allowing JDK-specific test cases. It is a work-in-progress, and subject to change.
* @deprecated <strong>Note that use of TestJdk should be a last-resort, preferably implementing JDK-agnostic tests.</strong>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@

package com.github.javaparser.symbolsolver.resolution;

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

import java.io.IOException;
import java.util.List;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.AnnotationDeclaration;
Expand All @@ -42,16 +52,6 @@
import com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.JarTypeSolver;
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.List;

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

/**
* Tests resolution of annotation expressions.
Expand All @@ -60,21 +60,15 @@
*/
class AnnotationsResolutionTest extends AbstractResolutionTest {

@BeforeAll
static void configureSymbolSolver() throws IOException {
@BeforeEach
void configureSymbolSolver() throws IOException {
// configure symbol solver before parsing
CombinedTypeSolver typeSolver = new CombinedTypeSolver();
typeSolver.add(new ReflectionTypeSolver());
typeSolver.add(new JarTypeSolver(adaptPath("src/test/resources/junit-4.8.1.jar")));
StaticJavaParser.getConfiguration().setSymbolResolver(new JavaSymbolSolver(typeSolver));
}

@AfterAll
static void unConfigureSymbolSolver() {
// unconfigure symbol solver so as not to potentially disturb tests in other classes
StaticJavaParser.getConfiguration().setSymbolResolver(null);
}

@Test
void solveJavaParserMarkerAnnotation() {
// parse compilation unit and get annotation expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,21 @@

package com.github.javaparser.symbolsolver.resolution;

import com.github.javaparser.ast.expr.MethodCallExpr;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.CompilationUnit;
import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.expr.MethodCallExpr;
import com.github.javaparser.symbolsolver.JavaSymbolSolver;
import com.github.javaparser.symbolsolver.javaparser.Navigator;
import com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver;
import java.io.IOException;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

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

/**
* Tests resolution of FieldAccessExpr with same names in scope and identifier
Expand All @@ -43,17 +44,12 @@
*/
class FieldAccessExprResolutionTest extends AbstractResolutionTest {

@BeforeAll
static void configureSymbolSolver() throws IOException {
@BeforeEach
void configureSymbolSolver() throws IOException {
// configure symbol solver so as not to potentially disturb tests in other classes
StaticJavaParser.getConfiguration().setSymbolResolver(new JavaSymbolSolver(new ReflectionTypeSolver()));
}

@AfterAll
static void unConfigureSymbolSolver() {
// unconfigure symbol solver so as not to potentially disturb tests in other classes
StaticJavaParser.getConfiguration().setSymbolResolver(null);
}

@Test
void solveX() throws IOException {
CompilationUnit cu = parseSample("FieldAccessExprResolution");
Expand Down

0 comments on commit 482eba3

Please sign in to comment.