]> git.uio.no Git - ifi-stolz-refaktor.git/commitdiff
added test, failing
authorAnna <anna.eilertsen@student.uib.no>
Fri, 18 Dec 2015 10:43:51 +0000 (11:43 +0100)
committerAnna <anna.eilertsen@student.uib.no>
Fri, 18 Dec 2015 10:43:51 +0000 (11:43 +0100)
software/no.uio.ifi.refaktor.examples/examples/src/searchBased/Main.java
software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/analyzertests/SearchBasedRefactorAnalyzerTestForExtractLocal.java

index ea2ac473f37d34b35c7385baeb5359eabec34f5d..9820e6cc132b017d2cca45314a2a0bf4e623096e 100644 (file)
@@ -86,6 +86,19 @@ public abstract class Main {
                b.c.fred();
        }
        
+       public void iHaveALocalVariableShadowingAFieldAndIsNotAnUnfix(){
+               b.c.fred();
+               b.c.fred();
+               b.c.fred();
+               b.c = new C();
+               b.c.fred();
+               if(true){
+                       B b = new B();
+                       b.c.fred();
+                       b.c.fred();
+               }
+       }
+       
        public void iWillBeNullInElse(){
                b.c.fred();
                if(b.c != null){
index d5bf4a0846316be853546462a540d1cb4aeb46c4..c87f5d4278c99f332b9d7d6d2fd87efa9b6fc124 100644 (file)
@@ -63,6 +63,36 @@ public class SearchBasedRefactorAnalyzerTestForExtractLocal {
                analyzer.analyze();
        }
        
+       @Test
+       public void testShadowingAssignedField() throws Exception {
+               IMethod testDataMethod = getTestDataMethod("iHaveALocalVariableShadowingAFieldAndIsNotAnUnfix");
+
+               SearchBasedRefactorAnalyzer<ExtractLocalVariableCandidate> analyzer = new SearchBasedRefactorAnalyzer<ExtractLocalVariableCandidate>(testDataMethod, new FavorNoUnfixesComparator<ExtractLocalVariableCandidate>(), new ExtractLocalVariableFactory());
+               analyzer.analyze();
+
+               assertThat("b.c".equals(analyzer.getCandidate().getTextSelection().getText())); 
+               
+               int methodOffset = testDataMethod.getSourceRange().getOffset();
+               
+               CompilationUnitTextSelection textSelection = new CompilationUnitTextSelection(testDataMethod.getCompilationUnit(), methodOffset + 186, 3);
+
+               System.out.println("Currently " + textSelection.getText());
+               System.out.println(textSelection);
+               System.out.println("Should be equal to " + analyzer.getCandidate().getTextSelection().getText());
+               System.out.println(analyzer.getCandidate().getTextSelection());
+               assertThat(textSelection.isEquivalentTo(analyzer.getCandidate().getTextSelection()));
+
+//             ASTNode coveredNode = textSelection.getCoveredNode();
+//             assertThat(coveredNode, instanceOf(ExpressionStatement.class));
+//
+//             ExpressionStatement expressionStatement = (ExpressionStatement) coveredNode;
+//             assertThat(expressionStatement.getExpression(), instanceOf(MethodInvocation.class));
+//
+//             MethodInvocation methodInvocation = (MethodInvocation) expressionStatement.getExpression();
+//             Prefix prefix = new Prefix(methodInvocation);
+//             assertTrue(prefix.getVariableBindingOfFirstExpression().isEqualTo(analyzer.getCandidate().calculateOriginalTarget()));
+       }
+       
        @Test(expected=NoTargetFoundException.class)
        public void testNoTargetNullInElse() {
                IMethod testDataMethod = getTestDataMethod("iWillBeNullInElse");