]> git.uio.no Git - ifi-stolz-refaktor.git/blame - software/no.uio.ifi.refaktor.tests/src/no/uio/ifi/refaktor/tests/PropertyExtractorExecutorTest.java
Adding test for PropertyExtractorExecutor.
[ifi-stolz-refaktor.git] / software / no.uio.ifi.refaktor.tests / src / no / uio / ifi / refaktor / tests / PropertyExtractorExecutorTest.java
CommitLineData
0f9013c4
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.extractors.PropertyExtractor;
6import no.uio.ifi.refaktor.extractors.PropertyExtractorExecutor;
7import no.uio.ifi.refaktor.utils.ParseUtils;
8import no.uio.ifi.refaktor.utils.SmartTextSelection;
9
10import org.eclipse.jdt.core.dom.MethodDeclaration;
11import org.eclipse.jface.text.Document;
12import org.junit.Before;
13import org.junit.Test;
14
15public 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}