]> git.uio.no Git - ifi-stolz-refaktor.git/blame - software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/CompilationUnitTextSelectionTest.java
Adding guard statement regarding ArrayAccess in UnfixesCollector.
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor.tests / src / no / uio / ifi / refaktor / tests / CompilationUnitTextSelectionTest.java
CommitLineData
f7008f4f
EK
1package no.uio.ifi.refaktor.tests;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertTrue;
5import no.uio.ifi.refaktor.examples.manager.ExampleCodeManager;
6import no.uio.ifi.refaktor.utils.CompilationUnitTextSelection;
7import no.uio.ifi.refaktor.utils.RefaktorHandleUtils;
8
9import org.eclipse.jdt.core.IMethod;
10import org.eclipse.jdt.core.JavaModelException;
11import org.eclipse.jface.text.ITextSelection;
12import org.eclipse.jface.text.TextSelection;
13import org.junit.Before;
14import org.junit.Test;
15
16public class CompilationUnitTextSelectionTest {
17
18 @Before
19 public void setUp() throws Exception {
20 ExampleCodeManager.INSTANCE.loadExampleCode();
21 }
22
23 @Test
24 public void test() throws JavaModelException {
25 CompilationUnitTextSelection textSelection = createTextSelection();
26 IMethod method = getTestDataMethod("testing");
27 ITextSelection otherSelection = new TextSelection(method.getSourceRange().getOffset() + 46, 31);
28 CompilationUnitTextSelection equalTextSelection = new CompilationUnitTextSelection(method.getCompilationUnit(), otherSelection);
29 assertEquals(textSelection, equalTextSelection);
30 assertTrue(textSelection.hashCode() == equalTextSelection.hashCode());
31 }
32
33 private CompilationUnitTextSelection createTextSelection()
34 throws JavaModelException {
35 IMethod method = getTestDataMethod("testing");
36 CompilationUnitTextSelection textSelection = new CompilationUnitTextSelection(method.getCompilationUnit(), method.getSourceRange().getOffset() + 46, 31);
37 return textSelection;
38 }
39
40 private IMethod getTestDataMethod(String methodName) throws JavaModelException {
41 IMethod method = RefaktorHandleUtils.findMethodHandle(ExampleCodeManager.INSTANCE.getProject(), "selection", "Main", methodName, new String[] {});
42 assertTrue(method.exists());
43 return method;
44 }
45}