Skip to content

Commit 8547f15

Browse files
committed
Fixed unit tests mostly around drag and drop issues
1 parent bcbadec commit 8547f15

25 files changed

+130
-170
lines changed

maven/core-unittests/src/test/java/com/codename1/junit/UITestBase.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.codename1.testing.SafeL10NManager;
66
import com.codename1.testing.TestCodenameOneImplementation;
77
import com.codename1.testing.TestUtils;
8+
import com.codename1.ui.Component;
89
import com.codename1.ui.Display;
910
import com.codename1.ui.DisplayTest;
1011
import com.codename1.ui.plaf.UIManager;
@@ -126,4 +127,9 @@ private void resetUIManager() throws Exception {
126127
protected void flushSerialCalls() {
127128
DisplayTest.flushEdt();
128129
}
130+
131+
protected void tapComponent(Component c) {
132+
implementation.tapComponent(c);
133+
flushSerialCalls();
134+
}
129135
}

maven/core-unittests/src/test/java/com/codename1/samples/AddComponentToRightBarSampleTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void rightBarCommandCanBeTriggeredThroughToolbarComponent() {
3939
assertNotNull(commandComponent);
4040
ensureSized(commandComponent, form);
4141

42-
implementation.tapComponent(commandComponent);
42+
tapComponent(commandComponent);
4343
flushSerialCalls();
4444
DisplayTest.flushEdt();
4545
flushSerialCalls();
@@ -86,7 +86,7 @@ void commandComponentCanBeReplacedWithCustomButton() {
8686
assertFalse(rightBarContainer.contains(commandComponent));
8787

8888
ensureSized(replacement, form);
89-
implementation.tapComponent(replacement);
89+
tapComponent(replacement);
9090
flushSerialCalls();
9191
DisplayTest.flushEdt();
9292
flushSerialCalls();

maven/core-unittests/src/test/java/com/codename1/samples/AutocompleteSample2788PortTest.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,23 +66,4 @@ private Container findVisibleAutocompletePopup(Form form) {
6666
}
6767
return null;
6868
}
69-
70-
private void tapComponent(Component component) {
71-
ensureSized(component);
72-
int x = component.getAbsoluteX() + component.getWidth() / 2;
73-
int y = component.getAbsoluteY() + component.getHeight() / 2;
74-
implementation.dispatchPointerPressAndRelease(x, y);
75-
flushSerialCalls();
76-
}
77-
78-
private void ensureSized(Component component) {
79-
Form parentForm = component.getComponentForm();
80-
for (int i = 0; i < 5 && (component.getWidth() <= 0 || component.getHeight() <= 0); i++) {
81-
if (parentForm != null) {
82-
parentForm.revalidate();
83-
}
84-
DisplayTest.flushEdt();
85-
flushSerialCalls();
86-
}
87-
}
8869
}

maven/core-unittests/src/test/java/com/codename1/samples/BlockLeadIssue3246Test.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void blockedComponentReceivesEventsInsteadOfLeadComponent() {
4242
flushSerialCalls();
4343
ensureSized(blocked, form);
4444

45-
implementation.tapComponent(blocked);
45+
tapComponent(blocked);
4646
flushSerialCalls();
4747
DisplayTest.flushEdt();
4848
flushSerialCalls();
@@ -60,8 +60,7 @@ void blockedComponentReceivesEventsInsteadOfLeadComponent() {
6060
flushSerialCalls();
6161
DisplayTest.flushEdt();
6262

63-
implementation.tapComponent(blocked);
64-
flushSerialCalls();
63+
tapComponent(blocked);
6564
DisplayTest.flushEdt();
6665
flushSerialCalls();
6766

maven/core-unittests/src/test/java/com/codename1/samples/CircleProgressSampleTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ void circleProgressIndicatorIsReplacedWhenDataIsReady() {
4040
flushSerialCalls();
4141

4242
ensureSized(showDetails, launcher);
43-
implementation.tapComponent(showDetails);
43+
tapComponent(showDetails);
4444
flushSerialCalls();
4545
DisplayTest.flushEdt();
46-
flushSerialCalls();
4746

4847
assertNotNull(detailsHolder[0]);
4948
assertSame(detailsHolder[0], Display.getInstance().getCurrent());

maven/core-unittests/src/test/java/com/codename1/samples/DateFormatTest2772PortTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void tappingShowDateFormatsUsingLocalizationManager() {
3232
form.show();
3333
ensureSized(showDate, form);
3434

35-
implementation.tapComponent(showDate);
35+
tapComponent(showDate);
3636
flushSerialCalls();
3737
DisplayTest.flushEdt();
3838
flushSerialCalls();

maven/core-unittests/src/test/java/com/codename1/samples/DialogPositioningSampleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void dialogPositionsItselfBelowTitleAreaAndStretchesOnPhone() {
5050
flushSerialCalls();
5151

5252
ensureSized(trigger, form);
53-
implementation.tapComponent(trigger);
53+
tapComponent(trigger);
5454
flushSerialCalls();
5555
DisplayTest.flushEdt();
5656
flushSerialCalls();

maven/core-unittests/src/test/java/com/codename1/samples/ListFilesSampleTest.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ public class ListFilesSampleTest extends UITestBase {
1414

1515
@FormTest
1616
public void testListFilesSample() {
17-
TestCodenameOneImplementation impl = TestCodenameOneImplementation.getInstance();
18-
impl.clearFileSystem();
19-
String appHome = impl.getAppHomePath();
20-
impl.mkdir(appHome);
17+
implementation.clearFileSystem();
18+
String appHome = implementation.getAppHomePath();
19+
implementation.mkdir(appHome);
2120

2221
Form hi = new Form("Hi World", new BorderLayout());
2322

@@ -51,18 +50,18 @@ public void testListFilesSample() {
5150
hi.show();
5251
waitForFormTitle("Hi World");
5352

54-
impl.tapComponent(add);
55-
assertTrue(impl.exists(appHome + "NewDir"), "Directory NewDir should exist");
56-
assertTrue(impl.isDirectory(appHome + "NewDir"), "NewDir should be a directory");
53+
tapComponent(add);
54+
assertTrue(implementation.exists(appHome + "NewDir"), "Directory NewDir should exist");
55+
assertTrue(implementation.isDirectory(appHome + "NewDir"), "NewDir should be a directory");
5756

58-
impl.tapComponent(refresh);
57+
tapComponent(refresh);
5958
assertTrue(listing.getText().contains("NewDir"), "Listing should contain NewDir");
6059

61-
impl.tapComponent(rename);
62-
assertFalse(impl.exists(appHome + "NewDir"), "Old directory should not exist");
63-
assertTrue(impl.exists(appHome + "RenamedDir"), "Renamed directory should exist");
60+
tapComponent(rename);
61+
assertFalse(implementation.exists(appHome + "NewDir"), "Old directory should not exist");
62+
assertTrue(implementation.exists(appHome + "RenamedDir"), "Renamed directory should exist");
6463

65-
impl.tapComponent(refresh);
64+
tapComponent(refresh);
6665
assertTrue(listing.getText().contains("RenamedDir"), "Listing should contain RenamedDir");
6766
assertFalse(listing.getText().contains("NewDir"), "Listing should not contain NewDir");
6867
}

maven/core-unittests/src/test/java/com/codename1/samples/LocationSampleTest.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ public class LocationSampleTest extends UITestBase {
1313

1414
@FormTest
1515
public void testLocationSample() {
16-
TestCodenameOneImplementation impl = TestCodenameOneImplementation.getInstance();
1716
MockLocationManager mockLoc = new MockLocationManager();
18-
impl.setLocationManager(mockLoc);
17+
implementation.setLocationManager(mockLoc);
1918

2019
Form hi = new Form("Hi World", BoxLayout.y());
2120
Button checkIfDetectionAvailable = new Button("Check if GPS Detection Available");
@@ -40,13 +39,13 @@ public void testLocationSample() {
4039
hi.show();
4140
waitForFormTitle("Hi World");
4241

43-
impl.tapComponent(checkIfDetectionAvailable);
42+
tapComponent(checkIfDetectionAvailable);
4443
assertEquals("GPS Detection IS supported", checkIfDetectionAvailable.getClientProperty("lastMessage"));
4544

46-
impl.tapComponent(isGPSEnabled);
45+
tapComponent(isGPSEnabled);
4746
assertEquals("GPS IS enabled", isGPSEnabled.getClientProperty("lastMessage"));
4847

49-
impl.tapComponent(getLocation);
48+
tapComponent(getLocation);
5049
String locMsg = (String) getLocation.getClientProperty("lastMessage");
5150
assertTrue(locMsg != null && locMsg.contains("Location is"), "Should find location");
5251
}

maven/core-unittests/src/test/java/com/codename1/samples/LongPointerPressSampleTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,11 @@ public void pointerPressed(int x, int y) {
4040
int y = centerCnt.getAbsoluteY() + 10;
4141

4242
impl.dispatchPointerPress(x, y);
43+
flushSerialCalls();
4344
assertTrue(pointerPressedTriggered, "pointerPressed should be triggered");
4445

4546
centerCnt.longPointerPress(x, y);
47+
flushSerialCalls();
4648
assertTrue(longPressTriggered, "longPointerPress should be triggered");
4749

4850
impl.dispatchPointerRelease(x, y);

0 commit comments

Comments
 (0)