package no.uio.ifi.refaktor.tests;
+import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertThat;
import no.uio.ifi.refaktor.analyze.Analyzer;
import no.uio.ifi.refaktor.analyze.FavorNoUnfixesAnalysisResultComparator;
import no.uio.ifi.refaktor.analyze.NoTargetFoundException;
@Test
public void testSimpleMethod() throws JavaModelException {
IMethod method = getTestDataMethod("simpleMethod");
+
SearchBasedExtractAndMoveMethodAnalyzer analyzer = new SearchBasedExtractAndMoveMethodAnalyzer(method);
analyzer.analyze();
+
int methodOffset = method.getSourceRange().getOffset();
CompilationUnitTextSelection textSelection = new CompilationUnitTextSelection(method.getCompilationUnit(), methodOffset + 69, 10);
assertEquals(textSelection, analyzer.getTextSelection());
+
ASTNode coveredNode = textSelection.getCoveredNode();
- assertTrue(coveredNode instanceof ExpressionStatement);
+ assertThat(coveredNode, instanceOf(ExpressionStatement.class));
+
ExpressionStatement expressionStatement = (ExpressionStatement) coveredNode;
- assertTrue(expressionStatement.getExpression() instanceof MethodInvocation);
+ assertThat(expressionStatement.getExpression(), instanceOf(MethodInvocation.class));
+
MethodInvocation methodInvocation = (MethodInvocation) expressionStatement.getExpression();
Prefix prefix = new Prefix(methodInvocation);
assertTrue(prefix.getVariableBindingOfFirstExpression().isEqualTo(analyzer.calculateOriginalTarget()));
@Test
public void testSearchableMethodFavorNoUnfixes() throws Exception {
IMethod method = getTestDataMethod("searchableMethod");
+
SearchBasedExtractAndMoveMethodAnalyzer analyzer = new SearchBasedExtractAndMoveMethodAnalyzer(method, new FavorNoUnfixesAnalysisResultComparator());
analyzer.analyze();
+
int methodOffset = method.getSourceRange().getOffset();
CompilationUnitTextSelection textSelection = new CompilationUnitTextSelection(method.getCompilationUnit(), methodOffset + 100, 31);
- assertEquals(textSelection, analyzer.getTextSelection());
+ assertEquals(textSelection, analyzer.getTextSelection());
+
ASTNode coveredNode = textSelection.getCoveredNode();
- assertTrue(coveredNode instanceof ExpressionStatement);
+ assertThat(coveredNode, instanceOf(ExpressionStatement.class));
+
ExpressionStatement expressionStatement = (ExpressionStatement) coveredNode;
- assertTrue(expressionStatement.getExpression() instanceof MethodInvocation);
+ assertThat(expressionStatement.getExpression(), instanceOf(MethodInvocation.class));
+
MethodInvocation methodInvocation = (MethodInvocation) expressionStatement.getExpression();
Prefix prefix = new Prefix(methodInvocation);
assertTrue(prefix.getVariableBindingOfFirstExpression().isEqualTo(analyzer.calculateOriginalTarget()));