Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
KnollFrank committed Dec 18, 2024
1 parent cb5d9af commit dda12aa
Showing 1 changed file with 12 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void shouldSearchAndFindSpeedCameraSettings4EachApplicationMode() {
@Test
public void shouldSearchAndFind_ResetProfilePrefsBottomSheet_within_AccessibilityPlugin() {
// Given
enablePlugin(getAccessibilityPlugin());
enablePlugin(AccessibilityPlugin.class);
clickSearchButton(app);

// When
Expand All @@ -91,13 +91,13 @@ public void shouldSearchAndFind_ResetProfilePrefsBottomSheet_within_Accessibilit

@Test
public void shouldSearchAndFind_LocationInterpolationBottomSheet_title() {
enablePlugin(getDevelopmentPlugin());
enablePlugin(OsmandDevelopmentPlugin.class);
shouldSearchAndFind(app.getString(R.string.location_interpolation_percent));
}

@Test
public void shouldSearchAndFind_LocationInterpolationBottomSheet_description() {
enablePlugin(getDevelopmentPlugin());
enablePlugin(OsmandDevelopmentPlugin.class);
shouldSearchAndFind(app.getString(R.string.location_interpolation_percent_desc));
}

Expand Down Expand Up @@ -135,27 +135,20 @@ public static Matcher<View> hasSearchResultWithSubstring(final String substring)
return recyclerViewHasItem(hasDescendant(withSubstring(substring)));
}

private void enablePlugin(final OsmandPlugin osmandPlugin) {
PluginsHelper.enablePlugin(null, app, osmandPlugin, true);
private void enablePlugin(final Class<? extends OsmandPlugin> plugin) {
PluginsHelper.enablePlugin(
null,
app,
getPlugin(plugin),
true);
}

// FK-TODO: DRY with getDevelopmentPlugin()
private static AccessibilityPlugin getAccessibilityPlugin() {
private static <T extends OsmandPlugin> T getPlugin(final Class<T> plugin) {
return PluginsHelper
.getAvailablePlugins()
.stream()
.filter(osmandPlugin -> osmandPlugin instanceof AccessibilityPlugin)
.map(osmandPlugin -> (AccessibilityPlugin) osmandPlugin)
.findFirst()
.orElseThrow();
}

private OsmandDevelopmentPlugin getDevelopmentPlugin() {
return PluginsHelper
.getAvailablePlugins()
.stream()
.filter(osmandPlugin -> osmandPlugin instanceof OsmandDevelopmentPlugin)
.map(osmandPlugin -> (OsmandDevelopmentPlugin) osmandPlugin)
.filter(plugin::isInstance)
.map(plugin::cast)
.findFirst()
.orElseThrow();
}
Expand Down

0 comments on commit dda12aa

Please sign in to comment.