From 577772ae5fd318ccfb2b479472ffc193af82dd6c Mon Sep 17 00:00:00 2001 From: Erlend Kristiansen Date: Fri, 20 Dec 2013 21:53:38 +0100 Subject: [PATCH] Changing test to utilize the hamcrest instanceOf matcher. --- software/no.uio.ifi.refaktor.tests/.classpath | 1 + ...BasedExtractAndMoveMethodAnalyzerTest.java | 22 ++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/software/no.uio.ifi.refaktor.tests/.classpath b/software/no.uio.ifi.refaktor.tests/.classpath index ad32c83a..23f11b11 100644 --- a/software/no.uio.ifi.refaktor.tests/.classpath +++ b/software/no.uio.ifi.refaktor.tests/.classpath @@ -3,5 +3,6 @@ + diff --git a/software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/SearchBasedExtractAndMoveMethodAnalyzerTest.java b/software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/SearchBasedExtractAndMoveMethodAnalyzerTest.java index d02b01e4..f9bc3763 100644 --- a/software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/SearchBasedExtractAndMoveMethodAnalyzerTest.java +++ b/software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/SearchBasedExtractAndMoveMethodAnalyzerTest.java @@ -1,7 +1,9 @@ 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; @@ -50,15 +52,20 @@ public class SearchBasedExtractAndMoveMethodAnalyzerTest { @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())); @@ -67,15 +74,20 @@ public class SearchBasedExtractAndMoveMethodAnalyzerTest { @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())); -- 2.43.5