]>
Commit | Line | Data |
---|---|---|
f7008f4f EK |
1 | package no.uio.ifi.refaktor.tests; |
2 | ||
3 | import static org.junit.Assert.assertEquals; | |
4 | import static org.junit.Assert.assertTrue; | |
5 | import no.uio.ifi.refaktor.examples.manager.ExampleCodeManager; | |
6 | import no.uio.ifi.refaktor.utils.CompilationUnitTextSelection; | |
7 | import no.uio.ifi.refaktor.utils.RefaktorHandleUtils; | |
8 | ||
9 | import org.eclipse.jdt.core.IMethod; | |
10 | import org.eclipse.jdt.core.JavaModelException; | |
11 | import org.eclipse.jface.text.ITextSelection; | |
12 | import org.eclipse.jface.text.TextSelection; | |
13 | import org.junit.Before; | |
14 | import org.junit.Test; | |
15 | ||
16 | public 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 | } |