]>
Commit | Line | Data |
---|---|---|
0f9013c4 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.extractors.PropertyExtractor; | |
6 | import no.uio.ifi.refaktor.extractors.PropertyExtractorExecutor; | |
7 | import no.uio.ifi.refaktor.utils.ParseUtils; | |
8 | import no.uio.ifi.refaktor.utils.SmartTextSelection; | |
9 | ||
10 | import org.eclipse.jdt.core.dom.MethodDeclaration; | |
11 | import org.eclipse.jface.text.Document; | |
12 | import org.junit.Before; | |
13 | import org.junit.Test; | |
14 | ||
15 | public class PropertyExtractorExecutorTest { | |
16 | ||
17 | private String methodText; | |
18 | private SmartTextSelection selection; | |
19 | private SimplePropertyExtractor extractor; | |
20 | private PropertyExtractorExecutor executor; | |
21 | ||
22 | class SimplePropertyExtractor extends PropertyExtractor { | |
23 | ||
24 | private String property; | |
25 | ||
26 | public SimplePropertyExtractor(SmartTextSelection selection) { | |
27 | super(selection); | |
28 | } | |
29 | ||
30 | @Override | |
31 | public boolean selectionIsValid() { | |
32 | return getSelection() != null && getSelection().getText().equals(methodText); | |
33 | } | |
34 | ||
35 | public String property() { | |
36 | return property; | |
37 | } | |
38 | ||
39 | public boolean visit(MethodDeclaration node) { | |
40 | property = ParseUtils.getNodeText(node, getDocument()); | |
41 | return false; | |
42 | } | |
43 | } | |
44 | ||
45 | @Before | |
46 | public void setUp() throws Exception { | |
47 | methodText = "public void foo() { System.out.println(\"bar\"); }"; | |
48 | String classStart = "class TestCode { "; | |
49 | String testCode = classStart + methodText + "}"; | |
50 | selection = new SmartTextSelection(new Document(testCode), classStart.length(), methodText.length()); | |
51 | extractor = new SimplePropertyExtractor(selection); | |
52 | executor = new PropertyExtractorExecutor(extractor); | |
53 | } | |
54 | ||
55 | @Test | |
56 | public void testExtractProperty() { | |
57 | assertEquals("The selection range may have been poorly defined.", methodText, selection.getText()); | |
58 | executor.extractProperty(); | |
59 | assertEquals(selection.getText(), extractor.property()); | |
60 | } | |
61 | ||
62 | @Test | |
63 | public void testSelectionIsValid() { | |
64 | assertTrue(executor.selectionIsValid()); | |
65 | } | |
66 | ||
67 | } |