Skip to content

Commit a09a612

Browse files
ricardojlrufinoFederico Fissore
authored and
Federico Fissore
committed
updated tests for new Textarea
1 parent ac39794 commit a09a612

10 files changed

+174
-21
lines changed

app/test/processing/app/AutoformatSavesCaretPositionTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import org.fest.swing.fixture.JMenuItemFixture;
3333
import org.junit.Test;
34-
import processing.app.helpers.JEditTextAreaFixture;
34+
import processing.app.helpers.RSyntaxTextAreaFixture;
3535

3636
import static org.junit.Assert.assertEquals;
3737

@@ -42,7 +42,7 @@ public void shouldSaveCaretPositionAfterAutoformat() {
4242
JMenuItemFixture menuToolsAutoFormat = window.menuItem("menuToolsAutoFormat");
4343
menuToolsAutoFormat.requireEnabled();
4444

45-
JEditTextAreaFixture editor = window.jEditTextArea("editor");
45+
RSyntaxTextAreaFixture editor = window.RSyntaxTextArea("editor");
4646
editor.setText("void setup() {\n" +
4747
" // put your setup code here, to run once:\n" +
4848
"\n" +

app/test/processing/app/AutoformatTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import org.fest.swing.fixture.JMenuItemFixture;
3333
import org.junit.Test;
34-
import processing.app.helpers.JEditTextAreaFixture;
34+
import processing.app.helpers.RSyntaxTextAreaFixture;
3535

3636
import static org.junit.Assert.assertEquals;
3737

@@ -42,7 +42,7 @@ public void shouldProduceNicelyFormattedCode() throws Exception {
4242
JMenuItemFixture menuToolsAutoFormat = window.menuItem("menuToolsAutoFormat");
4343
menuToolsAutoFormat.requireEnabled();
4444

45-
JEditTextAreaFixture editor = window.jEditTextArea("editor");
45+
RSyntaxTextAreaFixture editor = window.RSyntaxTextArea("editor");
4646
editor.setText("void setup() {\n" +
4747
"// put your setup code here, to run once:\n" +
4848
"int foo[] = { 1, 2, 3, 4, 5};\n" +

app/test/processing/app/BlockCommentGeneratesOneUndoActionTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,16 @@
2929

3030
package processing.app;
3131

32+
import static org.junit.Assert.assertEquals;
33+
34+
import java.awt.Frame;
35+
3236
import org.fest.swing.edt.GuiActionRunner;
3337
import org.fest.swing.edt.GuiQuery;
3438
import org.fest.swing.fixture.JMenuItemFixture;
3539
import org.junit.Test;
36-
import processing.app.helpers.JEditTextAreaFixture;
3740

38-
import java.awt.*;
39-
40-
import static org.junit.Assert.assertEquals;
41+
import processing.app.helpers.RSyntaxTextAreaFixture;
4142

4243
public class BlockCommentGeneratesOneUndoActionTest extends AbstractGUITest {
4344

@@ -46,7 +47,7 @@ public void shouldUndoAndRedo() throws Exception {
4647
JMenuItemFixture menuEditUndo = window.menuItem("menuEditUndo");
4748
menuEditUndo.requireDisabled();
4849

49-
JEditTextAreaFixture jEditTextArea = window.jEditTextArea("editor");
50+
RSyntaxTextAreaFixture jEditTextArea = window.RSyntaxTextArea("editor");
5051
String previousText = jEditTextArea.getText();
5152

5253
jEditTextArea.selectAll();

app/test/processing/app/HittingEscapeOnCloseConfirmationDialogTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import org.fest.swing.finder.WindowFinder;
3434
import org.fest.swing.fixture.DialogFixture;
3535
import org.junit.Test;
36-
import processing.app.helpers.JEditTextAreaFixture;
36+
import processing.app.helpers.RSyntaxTextAreaFixture;
3737

3838
import javax.swing.*;
3939
import java.awt.event.KeyEvent;
@@ -44,7 +44,7 @@ public class HittingEscapeOnCloseConfirmationDialogTest extends AbstractGUITest
4444

4545
@Test
4646
public void shouldJustCloseTheDialog() throws Exception {
47-
JEditTextAreaFixture editor = window.jEditTextArea("editor");
47+
RSyntaxTextAreaFixture editor = window.RSyntaxTextArea("editor");
4848
editor.setText("test");
4949

5050
window.close();

app/test/processing/app/ReduceIndentWith1CharOnLastLineTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@
3434
import org.fest.swing.fixture.JMenuItemFixture;
3535
import org.junit.Test;
3636

37-
import processing.app.helpers.JEditTextAreaFixture;
37+
import processing.app.helpers.RSyntaxTextAreaFixture;
3838

3939
public class ReduceIndentWith1CharOnLastLineTest extends AbstractGUITest {
4040

4141
@Test
4242
public void shouldJustCloseTheDialog() throws Exception {
4343
JMenuItemFixture menuDecreaseIndent = window.menuItem("menuDecreaseIndent");
4444

45-
JEditTextAreaFixture editor = window.jEditTextArea("editor");
45+
RSyntaxTextAreaFixture editor = window.RSyntaxTextArea("editor");
4646
editor.setText("void loop()\n{\n Serial.begin(9600)\n}");
4747

4848
editor.selectAll();

app/test/processing/app/ReplacingTextGeneratesTwoUndoActionsTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
import org.fest.swing.fixture.JMenuItemFixture;
3333
import org.junit.Test;
34-
import processing.app.helpers.JEditTextAreaFixture;
34+
import processing.app.helpers.RSyntaxTextAreaFixture;
3535

3636
import static org.junit.Assert.assertEquals;
3737

@@ -44,19 +44,19 @@ public void shouldUndoAndRedo() throws Exception {
4444
JMenuItemFixture menuEditRedo = window.menuItem("menuEditRedo");
4545
menuEditRedo.requireDisabled();
4646

47-
JEditTextAreaFixture jEditTextArea = window.jEditTextArea("editor");
47+
RSyntaxTextAreaFixture RSyntaxTextArea = window.RSyntaxTextArea("editor");
4848

49-
jEditTextArea.setText("fake text");
49+
RSyntaxTextArea.setText("fake text");
5050

5151
menuEditUndo.requireEnabled();
5252
menuEditUndo.click();
5353

54-
assertEquals("", jEditTextArea.getText());
54+
assertEquals("", RSyntaxTextArea.getText());
5555

5656
menuEditRedo.requireEnabled();
5757
menuEditRedo.click();
5858

59-
//assertEquals("fake text", jEditTextArea.getText());
59+
//assertEquals("fake text", RSyntaxTextArea.getText());
6060

6161
menuEditUndo.requireEnabled();
6262
menuEditUndo.click();

app/test/processing/app/helpers/ArduinoFrameFixture.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@
3030
package processing.app.helpers;
3131

3232
import org.fest.swing.fixture.FrameFixture;
33+
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
34+
3335
import processing.app.Editor;
34-
import processing.app.syntax.JEditTextArea;
3536

3637
public class ArduinoFrameFixture extends FrameFixture {
3738

@@ -42,8 +43,8 @@ public ArduinoFrameFixture(Editor editor) {
4243
this.editor = editor;
4344
}
4445

45-
public JEditTextAreaFixture jEditTextArea(String name) {
46-
return new JEditTextAreaFixture(robot, (JEditTextArea) this.robot.finder().find(new JEditTextAreaComponentMatcher(name)));
46+
public RSyntaxTextAreaFixture RSyntaxTextArea(String name) {
47+
return new RSyntaxTextAreaFixture(robot, (RSyntaxTextArea) this.robot.finder().find(new RSyntaxTextAreaComponentMatcher(name)));
4748
}
4849

4950
public Editor getEditor() {
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package processing.app.helpers;
2+
3+
import org.fest.swing.core.Robot;
4+
import org.fest.swing.driver.JComponentDriver;
5+
import org.fest.swing.edt.GuiActionRunner;
6+
import org.fest.swing.edt.GuiQuery;
7+
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
8+
9+
public class RSyntaxTextAreaComponentDriver extends JComponentDriver {
10+
11+
public RSyntaxTextAreaComponentDriver(Robot robot) {
12+
super(robot);
13+
}
14+
15+
public void enterText(RSyntaxTextArea target, String text) {
16+
focusAndWaitForFocusGain(target);
17+
robot.enterText(text);
18+
}
19+
20+
public void setText(final RSyntaxTextArea target, final String text) {
21+
focusAndWaitForFocusGain(target);
22+
GuiActionRunner.execute(new GuiQuery<RSyntaxTextArea>() {
23+
24+
protected RSyntaxTextArea executeInEDT() {
25+
target.setText(text);
26+
return target;
27+
}
28+
29+
});
30+
robot.waitForIdle();
31+
}
32+
33+
public String getText(final RSyntaxTextArea target) {
34+
focusAndWaitForFocusGain(target);
35+
return GuiActionRunner.execute(new GuiQuery<String>() {
36+
37+
protected String executeInEDT() {
38+
return target.getText();
39+
}
40+
41+
});
42+
}
43+
44+
public RSyntaxTextArea selectAll(final RSyntaxTextArea target) {
45+
return GuiActionRunner.execute(new GuiQuery<RSyntaxTextArea>() {
46+
47+
protected RSyntaxTextArea executeInEDT() {
48+
target.selectAll();
49+
return target;
50+
}
51+
52+
});
53+
}
54+
55+
public Integer getCaretPosition(final RSyntaxTextArea target) {
56+
focusAndWaitForFocusGain(target);
57+
return GuiActionRunner.execute(new GuiQuery<Integer>() {
58+
59+
protected Integer executeInEDT() {
60+
return target.getCaretPosition();
61+
}
62+
63+
});
64+
}
65+
66+
public void setCaretPosition(final RSyntaxTextArea target, final int caretPosition) {
67+
focusAndWaitForFocusGain(target);
68+
GuiActionRunner.execute(new GuiQuery<RSyntaxTextArea>() {
69+
70+
protected RSyntaxTextArea executeInEDT() {
71+
target.setCaretPosition(caretPosition);
72+
return target;
73+
}
74+
75+
});
76+
robot.waitForIdle();
77+
}
78+
79+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package processing.app.helpers;
2+
3+
import java.awt.Component;
4+
5+
import org.fest.swing.core.ComponentMatcher;
6+
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
7+
8+
public class RSyntaxTextAreaComponentMatcher implements ComponentMatcher {
9+
10+
private final String name;
11+
12+
public RSyntaxTextAreaComponentMatcher(String name) {
13+
this.name = name;
14+
}
15+
16+
@Override
17+
public boolean matches(Component component) {
18+
return component instanceof RSyntaxTextArea && name.equals(component.getName());
19+
}
20+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package processing.app.helpers;
2+
3+
import org.fest.swing.core.Robot;
4+
import org.fest.swing.fixture.ComponentFixture;
5+
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
6+
7+
public class RSyntaxTextAreaFixture extends ComponentFixture {
8+
9+
private final RSyntaxTextAreaComponentDriver driver;
10+
11+
public RSyntaxTextAreaFixture(Robot robot, Class type) {
12+
super(robot, type);
13+
this.driver = new RSyntaxTextAreaComponentDriver(robot);
14+
}
15+
16+
public RSyntaxTextAreaFixture(Robot robot, String name, Class type) {
17+
super(robot, name, type);
18+
this.driver = new RSyntaxTextAreaComponentDriver(robot);
19+
}
20+
21+
public RSyntaxTextAreaFixture(Robot robot, RSyntaxTextArea target) {
22+
super(robot, target);
23+
this.driver = new RSyntaxTextAreaComponentDriver(robot);
24+
}
25+
26+
public RSyntaxTextAreaFixture enterText(String text) {
27+
driver.enterText((RSyntaxTextArea) target, text);
28+
return this;
29+
}
30+
31+
public RSyntaxTextAreaFixture setText(String text) {
32+
driver.setText((RSyntaxTextArea) target, text);
33+
return this;
34+
}
35+
36+
public String getText() {
37+
return driver.getText((RSyntaxTextArea) target);
38+
}
39+
40+
public RSyntaxTextAreaFixture selectAll() {
41+
driver.selectAll((RSyntaxTextArea) target);
42+
return this;
43+
}
44+
45+
public int getCaretPosition() {
46+
return driver.getCaretPosition((RSyntaxTextArea) target);
47+
}
48+
49+
public void setCaretPosition(int caretPosition) {
50+
driver.setCaretPosition((RSyntaxTextArea) target, caretPosition);
51+
}
52+
}

0 commit comments

Comments
 (0)