Skip to content

Commit 8d379b3

Browse files
authored
Update CombinedWidgetTest to also check growth
1 parent dd7e767 commit 8d379b3

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedWidgetTest.java

+40-18
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import io.appium.java_client.pagefactory_tests.widget.tests.AbstractStubWebDriver;
77
import io.appium.java_client.pagefactory_tests.widget.tests.DefaultStubWidget;
88
import io.appium.java_client.pagefactory_tests.widget.tests.android.DefaultAndroidWidget;
9+
import io.appium.java_client.proxy.Helpers;
10+
import org.junit.jupiter.api.RepeatedTest;
911
import org.junit.jupiter.params.ParameterizedTest;
1012
import org.junit.jupiter.params.provider.Arguments;
1113
import org.junit.jupiter.params.provider.MethodSource;
@@ -20,6 +22,7 @@
2022
import static org.hamcrest.MatcherAssert.assertThat;
2123
import static org.hamcrest.Matchers.contains;
2224
import static org.hamcrest.Matchers.equalTo;
25+
import static org.hamcrest.Matchers.lessThan;
2326
import static org.openqa.selenium.support.PageFactory.initElements;
2427

2528

@@ -33,30 +36,31 @@ public class CombinedWidgetTest {
3336
*/
3437
public static Stream<Arguments> data() {
3538
return Stream.of(
36-
Arguments.of(new AppWithCombinedWidgets(),
37-
new AbstractStubWebDriver.StubAndroidDriver(), DefaultAndroidWidget.class),
38-
Arguments.of(new AppWithCombinedWidgets(),
39-
new AbstractStubWebDriver.StubIOSXCUITDriver(), DefaultIosXCUITWidget.class),
40-
Arguments.of(new AppWithCombinedWidgets(),
41-
new AbstractStubWebDriver.StubBrowserDriver(), DefaultFindByWidget.class),
42-
Arguments.of(new AppWithCombinedWidgets(),
43-
new AbstractStubWebDriver.StubAndroidBrowserOrWebViewDriver(), DefaultFindByWidget.class),
44-
Arguments.of(new AppWithPartiallyCombinedWidgets(),
45-
new AbstractStubWebDriver.StubAndroidDriver(), DefaultAndroidWidget.class),
46-
Arguments.of(new AppWithPartiallyCombinedWidgets(),
47-
new AbstractStubWebDriver.StubIOSXCUITDriver(), DefaultStubWidget.class),
48-
Arguments.of(new AppWithPartiallyCombinedWidgets(),
49-
new AbstractStubWebDriver.StubWindowsDriver(), DefaultStubWidget.class),
50-
Arguments.of(new AppWithPartiallyCombinedWidgets(),
51-
new AbstractStubWebDriver.StubBrowserDriver(), DefaultFindByWidget.class),
52-
Arguments.of(new AppWithPartiallyCombinedWidgets(),
53-
new AbstractStubWebDriver.StubAndroidBrowserOrWebViewDriver(), DefaultFindByWidget.class)
39+
Arguments.of(new AppWithCombinedWidgets(),
40+
new AbstractStubWebDriver.StubAndroidDriver(), DefaultAndroidWidget.class),
41+
Arguments.of(new AppWithCombinedWidgets(),
42+
new AbstractStubWebDriver.StubIOSXCUITDriver(), DefaultIosXCUITWidget.class),
43+
Arguments.of(new AppWithCombinedWidgets(),
44+
new AbstractStubWebDriver.StubBrowserDriver(), DefaultFindByWidget.class),
45+
Arguments.of(new AppWithCombinedWidgets(),
46+
new AbstractStubWebDriver.StubAndroidBrowserOrWebViewDriver(), DefaultFindByWidget.class),
47+
Arguments.of(new AppWithPartiallyCombinedWidgets(),
48+
new AbstractStubWebDriver.StubAndroidDriver(), DefaultAndroidWidget.class),
49+
Arguments.of(new AppWithPartiallyCombinedWidgets(),
50+
new AbstractStubWebDriver.StubIOSXCUITDriver(), DefaultStubWidget.class),
51+
Arguments.of(new AppWithPartiallyCombinedWidgets(),
52+
new AbstractStubWebDriver.StubWindowsDriver(), DefaultStubWidget.class),
53+
Arguments.of(new AppWithPartiallyCombinedWidgets(),
54+
new AbstractStubWebDriver.StubBrowserDriver(), DefaultFindByWidget.class),
55+
Arguments.of(new AppWithPartiallyCombinedWidgets(),
56+
new AbstractStubWebDriver.StubAndroidBrowserOrWebViewDriver(), DefaultFindByWidget.class)
5457
);
5558
}
5659

5760
@ParameterizedTest
5861
@MethodSource("data")
5962
void checkThatWidgetsAreCreatedCorrectly(AbstractApp app, WebDriver driver, Class<?> widgetClass) {
63+
assertProxyClassCacheGrowth();
6064
initElements(new AppiumFieldDecorator(driver), app);
6165
assertThat("Expected widget class was " + widgetClass.getName(),
6266
app.getWidget().getSubWidget().getSelfReference().getClass(),
@@ -161,4 +165,22 @@ public List<PartiallyCombinedWidget> getWidgets() {
161165
return multipleWidgets;
162166
}
163167
}
168+
169+
170+
/**
171+
* Assert proxy class cache growth for this test class.
172+
* The (@link io.appium.java_client.proxy.Helpers#CACHED_PROXY_CLASSES) should be populated during these tests.
173+
* Prior to the Caching issue being resolved
174+
* - the CACHED_PROXY_CLASSES would grow indefinitely, resulting in an Out Of Memory exception.
175+
* - this ParameterizedTest would have the CACHED_PROXY_CLASSES grow to 266 entries.
176+
*/
177+
private void assertProxyClassCacheGrowth() {
178+
System.gc(); //Trying to force a collection for more accurate check numbers
179+
int thresholdSize = 50;
180+
assertThat(
181+
"Proxy Class Cache threshold is " + thresholdSize,
182+
Helpers.getCachedProxyClassesSize(),
183+
lessThan(thresholdSize)
184+
);
185+
}
164186
}

0 commit comments

Comments
 (0)