From 3ad290d9e5b883116bf2cf72f40041288ee43530 Mon Sep 17 00:00:00 2001 From: Bipin Kumar Chaurasia Date: Thu, 1 Sep 2022 22:37:47 +0530 Subject: [PATCH] test: updated JUnit5 test classes and methods to have default package visibility --- .../java_client/internal/ConfigTest.java | 10 +-- .../tests/combined/CombinedAppTest.java | 7 +- .../tests/combined/CombinedWidgetTest.java | 2 +- .../service/local/ServerBuilderTest.java | 65 +++++++++---------- .../local/StartingAppLocallyAndroidTest.java | 23 ++++--- .../local/StartingAppLocallyIosTest.java | 8 +-- .../service/local/ThreadSafetyTest.java | 10 +-- 7 files changed, 61 insertions(+), 64 deletions(-) diff --git a/src/test/java/io/appium/java_client/internal/ConfigTest.java b/src/test/java/io/appium/java_client/internal/ConfigTest.java index cd2bd390c..df8611458 100644 --- a/src/test/java/io/appium/java_client/internal/ConfigTest.java +++ b/src/test/java/io/appium/java_client/internal/ConfigTest.java @@ -8,28 +8,28 @@ import org.junit.jupiter.api.Test; -public class ConfigTest { +class ConfigTest { private static final String EXISTING_KEY = "selenium.version"; private static final String MISSING_KEY = "bla"; @Test - public void verifyGettingExistingValue() { + void verifyGettingExistingValue() { assertThat(Config.main().getValue(EXISTING_KEY, String.class).length(), greaterThan(0)); assertTrue(Config.main().getOptionalValue(EXISTING_KEY, String.class).isPresent()); } @Test - public void verifyGettingNonExistingValue() { + void verifyGettingNonExistingValue() { assertThrows(IllegalArgumentException.class, () -> Config.main().getValue(MISSING_KEY, String.class)); } @Test - public void verifyGettingExistingValueWithWrongClass() { + void verifyGettingExistingValueWithWrongClass() { assertThrows(ClassCastException.class, () -> Config.main().getValue(EXISTING_KEY, Integer.class)); } @Test - public void verifyGettingNonExistingOptionalValue() { + void verifyGettingNonExistingOptionalValue() { assertFalse(Config.main().getOptionalValue(MISSING_KEY, String.class).isPresent()); } } diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedAppTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedAppTest.java index 8c93632ec..80e6eb1b3 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedAppTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedAppTest.java @@ -13,14 +13,13 @@ import io.appium.java_client.pagefactory_tests.widget.tests.DefaultStubWidget; import io.appium.java_client.pagefactory_tests.widget.tests.android.DefaultAndroidWidget; import io.appium.java_client.pagefactory_tests.widget.tests.windows.DefaultWindowsWidget; +import java.util.List; +import java.util.stream.Stream; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import org.openqa.selenium.WebDriver; -import java.util.List; -import java.util.stream.Stream; - @SuppressWarnings({"unused", "unchecked"}) public class CombinedAppTest { @@ -53,7 +52,7 @@ public static Stream data() { @ParameterizedTest @MethodSource("data") - public void checkThatWidgetsAreCreatedCorrectly(AbstractApp app, WebDriver driver, Class widgetClass) { + void checkThatWidgetsAreCreatedCorrectly(AbstractApp app, WebDriver driver, Class widgetClass) { initElements(new AppiumFieldDecorator(driver), app); assertThat("Expected widget class was " + widgetClass.getName(), app.getWidget().getSelfReference().getClass(), diff --git a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedWidgetTest.java b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedWidgetTest.java index 1d686c58e..342e37335 100644 --- a/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedWidgetTest.java +++ b/src/test/java/io/appium/java_client/pagefactory_tests/widget/tests/combined/CombinedWidgetTest.java @@ -59,7 +59,7 @@ public static Stream data() { @ParameterizedTest @MethodSource("data") - public void checkThatWidgetsAreCreatedCorrectly(AbstractApp app, WebDriver driver, Class widgetClass) { + void checkThatWidgetsAreCreatedCorrectly(AbstractApp app, WebDriver driver, Class widgetClass) { initElements(new AppiumFieldDecorator(driver), app); assertThat("Expected widget class was " + widgetClass.getName(), app.getWidget().getSubWidget().getSelfReference().getClass(), diff --git a/src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java b/src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java index cb97479e8..ccdd117d2 100644 --- a/src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java +++ b/src/test/java/io/appium/java_client/service/local/ServerBuilderTest.java @@ -27,20 +27,19 @@ import com.google.common.collect.ImmutableMap; import io.appium.java_client.android.options.UiAutomator2Options; import io.github.bonigarcia.wdm.WebDriverManager; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - import java.io.File; -import java.io.FileOutputStream; import java.io.OutputStream; +import java.nio.file.Files; import java.nio.file.Path; import java.time.Duration; import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; @SuppressWarnings("ResultOfMethodCallIgnored") -public class ServerBuilderTest { +class ServerBuilderTest { /** * It may be impossible to find the path to the instance of appium server due to different circumstance. @@ -93,7 +92,7 @@ public void tearDown() throws Exception { } @Test - public void checkAbilityToAddLogMessageConsumer() { + void checkAbilityToAddLogMessageConsumer() { List log = new ArrayList<>(); service = buildDefaultService(); service.clearOutPutStreams(); @@ -103,21 +102,21 @@ public void checkAbilityToAddLogMessageConsumer() { } @Test - public void checkAbilityToStartDefaultService() { + void checkAbilityToStartDefaultService() { service = buildDefaultService(); service.start(); assertTrue(service.isRunning()); } @Test - public void checkAbilityToFindNodeDefinedInProperties() { + void checkAbilityToFindNodeDefinedInProperties() { File definedNode = PATH_T0_TEST_MAIN_JS.toFile(); setProperty(APPIUM_PATH, definedNode.getAbsolutePath()); assertThat(new AppiumServiceBuilder().createArgs().get(0), is(definedNode.getAbsolutePath())); } @Test - public void checkAbilityToUseNodeDefinedExplicitly() { + void checkAbilityToUseNodeDefinedExplicitly() { File mainJS = PATH_T0_TEST_MAIN_JS.toFile(); AppiumServiceBuilder builder = new AppiumServiceBuilder() .withAppiumJS(mainJS); @@ -126,21 +125,21 @@ public void checkAbilityToUseNodeDefinedExplicitly() { } @Test - public void checkAbilityToStartServiceOnAFreePort() { + void checkAbilityToStartServiceOnAFreePort() { service = new AppiumServiceBuilder().usingAnyFreePort().build(); service.start(); assertTrue(service.isRunning()); } @Test - public void checkAbilityToStartServiceUsingNonLocalhostIP() { + void checkAbilityToStartServiceUsingNonLocalhostIP() { service = new AppiumServiceBuilder().withIPAddress(testIP).build(); service.start(); assertTrue(service.isRunning()); } @Test - public void checkAbilityToStartServiceUsingFlags() { + void checkAbilityToStartServiceUsingFlags() { service = new AppiumServiceBuilder() .withArgument(CALLBACK_ADDRESS, testIP) .withArgument(SESSION_OVERRIDE) @@ -150,7 +149,7 @@ public void checkAbilityToStartServiceUsingFlags() { } @Test - public void checkAbilityToStartServiceUsingCapabilities() { + void checkAbilityToStartServiceUsingCapabilities() { UiAutomator2Options options = new UiAutomator2Options() .fullReset() .setNewCommandTimeout(Duration.ofSeconds(60)) @@ -165,7 +164,7 @@ public void checkAbilityToStartServiceUsingCapabilities() { } @Test - public void checkAbilityToStartServiceUsingCapabilitiesAndFlags() { + void checkAbilityToStartServiceUsingCapabilitiesAndFlags() { File app = ROOT_TEST_PATH.resolve("ApiDemos-debug.apk").toFile(); UiAutomator2Options options = new UiAutomator2Options() @@ -191,10 +190,10 @@ public void checkAbilityToStartServiceUsingCapabilitiesAndFlags() { } @Test - public void checkAbilityToChangeOutputStream() throws Exception { + void checkAbilityToChangeOutputStream() throws Exception { testLogFile = new File("test"); testLogFile.createNewFile(); - stream = new FileOutputStream(testLogFile); + stream = Files.newOutputStream(testLogFile.toPath()); service = buildDefaultService(); service.addOutPutStream(stream); service.start(); @@ -202,10 +201,10 @@ public void checkAbilityToChangeOutputStream() throws Exception { } @Test - public void checkAbilityToChangeOutputStreamAfterTheServiceIsStarted() throws Exception { + void checkAbilityToChangeOutputStreamAfterTheServiceIsStarted() throws Exception { testLogFile = new File("test"); testLogFile.createNewFile(); - stream = new FileOutputStream(testLogFile); + stream = Files.newOutputStream(testLogFile.toPath()); service = buildDefaultService(); service.start(); service.addOutPutStream(stream); @@ -214,7 +213,7 @@ public void checkAbilityToChangeOutputStreamAfterTheServiceIsStarted() throws Ex } @Test - public void checkAbilityToShutDownService() { + void checkAbilityToShutDownService() { service = buildDefaultService(); service.start(); service.stop(); @@ -222,7 +221,7 @@ public void checkAbilityToShutDownService() { } @Test - public void checkAbilityToStartAndShutDownFewServices() throws Exception { + void checkAbilityToStartAndShutDownFewServices() throws Exception { List services = asList( new AppiumServiceBuilder().usingAnyFreePort().build(), new AppiumServiceBuilder().usingAnyFreePort().build(), @@ -236,7 +235,7 @@ public void checkAbilityToStartAndShutDownFewServices() throws Exception { } @Test - public void checkAbilityToStartServiceWithLogFile() throws Exception { + void checkAbilityToStartServiceWithLogFile() throws Exception { testLogFile = new File("Log.txt"); testLogFile.createNewFile(); service = new AppiumServiceBuilder().withLogFile(testLogFile).build(); @@ -246,7 +245,7 @@ public void checkAbilityToStartServiceWithLogFile() throws Exception { } @Test - public void checkAbilityToStartServiceWithPortUsingFlag() { + void checkAbilityToStartServiceWithPortUsingFlag() { String port = "8996"; String expectedUrl = String.format("http://0.0.0.0:%s/", port); @@ -259,7 +258,7 @@ public void checkAbilityToStartServiceWithPortUsingFlag() { } @Test - public void checkAbilityToStartServiceWithPortUsingShortFlag() { + void checkAbilityToStartServiceWithPortUsingShortFlag() { String port = "8996"; String expectedUrl = String.format("http://0.0.0.0:%s/", port); @@ -272,7 +271,7 @@ public void checkAbilityToStartServiceWithPortUsingShortFlag() { } @Test - public void checkAbilityToStartServiceWithIpUsingFlag() { + void checkAbilityToStartServiceWithIpUsingFlag() { String expectedUrl = String.format("http://%s:4723/", testIP); service = new AppiumServiceBuilder() @@ -284,7 +283,7 @@ public void checkAbilityToStartServiceWithIpUsingFlag() { } @Test - public void checkAbilityToStartServiceWithIpUsingShortFlag() { + void checkAbilityToStartServiceWithIpUsingShortFlag() { String expectedUrl = String.format("http://%s:4723/", testIP); service = new AppiumServiceBuilder() @@ -296,7 +295,7 @@ public void checkAbilityToStartServiceWithIpUsingShortFlag() { } @Test - public void checkAbilityToStartServiceWithLogFileUsingFlag() { + void checkAbilityToStartServiceWithLogFileUsingFlag() { testLogFile = new File("Log2.txt"); service = new AppiumServiceBuilder() @@ -307,7 +306,7 @@ public void checkAbilityToStartServiceWithLogFileUsingFlag() { } @Test - public void checkAbilityToStartServiceWithLogFileUsingShortFlag() { + void checkAbilityToStartServiceWithLogFileUsingShortFlag() { testLogFile = new File("Log3.txt"); service = new AppiumServiceBuilder() @@ -318,7 +317,7 @@ public void checkAbilityToStartServiceWithLogFileUsingShortFlag() { } @Test - public void checkAbilityToStartServiceUsingValidBasePathWithMultiplePathParams() { + void checkAbilityToStartServiceUsingValidBasePathWithMultiplePathParams() { String baseUrl = String.format("http://%s:%d/", BROADCAST_IP_ADDRESS, DEFAULT_APPIUM_PORT); String basePath = "wd/hub"; service = new AppiumServiceBuilder().withArgument(BASEPATH, basePath).build(); @@ -328,7 +327,7 @@ public void checkAbilityToStartServiceUsingValidBasePathWithMultiplePathParams() } @Test - public void checkAbilityToStartServiceUsingValidBasePathWithSinglePathParams() { + void checkAbilityToStartServiceUsingValidBasePathWithSinglePathParams() { String baseUrl = String.format("http://%s:%d/", BROADCAST_IP_ADDRESS, DEFAULT_APPIUM_PORT); String basePath = "/wd/"; service = new AppiumServiceBuilder().withArgument(BASEPATH, basePath).build(); @@ -338,17 +337,17 @@ public void checkAbilityToStartServiceUsingValidBasePathWithSinglePathParams() { } @Test - public void checkAbilityToValidateBasePathForEmptyBasePath() { + void checkAbilityToValidateBasePathForEmptyBasePath() { assertThrows(IllegalArgumentException.class, () -> new AppiumServiceBuilder().withArgument(BASEPATH, "")); } @Test - public void checkAbilityToValidateBasePathForBlankBasePath() { + void checkAbilityToValidateBasePathForBlankBasePath() { assertThrows(IllegalArgumentException.class, () -> new AppiumServiceBuilder().withArgument(BASEPATH, " ")); } @Test - public void checkAbilityToValidateBasePathForNullBasePath() { + void checkAbilityToValidateBasePathForNullBasePath() { assertThrows(NullPointerException.class, () -> new AppiumServiceBuilder().withArgument(BASEPATH, null)); } } diff --git a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyAndroidTest.java b/src/test/java/io/appium/java_client/service/local/StartingAppLocallyAndroidTest.java index 3d248f462..55906d13f 100644 --- a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyAndroidTest.java +++ b/src/test/java/io/appium/java_client/service/local/StartingAppLocallyAndroidTest.java @@ -16,6 +16,12 @@ package io.appium.java_client.service.local; +import static io.appium.java_client.TestResources.apiDemosApk; +import static io.github.bonigarcia.wdm.WebDriverManager.chromedriver; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import io.appium.java_client.android.AndroidDriver; import io.appium.java_client.android.options.UiAutomator2Options; import io.appium.java_client.remote.AutomationName; @@ -23,21 +29,14 @@ import io.appium.java_client.remote.MobilePlatform; import io.appium.java_client.service.local.flags.GeneralServerFlag; import io.github.bonigarcia.wdm.WebDriverManager; +import java.time.Duration; import org.junit.jupiter.api.Test; import org.openqa.selenium.Capabilities; -import java.time.Duration; - -import static io.appium.java_client.TestResources.apiDemosApk; -import static io.github.bonigarcia.wdm.WebDriverManager.chromedriver; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class StartingAppLocallyAndroidTest { +class StartingAppLocallyAndroidTest { @Test - public void startingAndroidAppWithCapabilitiesOnlyTest() { + void startingAndroidAppWithCapabilitiesOnlyTest() { AndroidDriver driver = new AndroidDriver(new UiAutomator2Options() .setDeviceName("Android Emulator") .autoGrantPermissions() @@ -57,7 +56,7 @@ public void startingAndroidAppWithCapabilitiesOnlyTest() { } @Test - public void startingAndroidAppWithCapabilitiesAndServiceTest() { + void startingAndroidAppWithCapabilitiesAndServiceTest() { AppiumServiceBuilder builder = new AppiumServiceBuilder() .withArgument(GeneralServerFlag.SESSION_OVERRIDE) .withArgument(GeneralServerFlag.STRICT_CAPS); @@ -79,7 +78,7 @@ public void startingAndroidAppWithCapabilitiesAndServiceTest() { } @Test - public void startingAndroidAppWithCapabilitiesAndFlagsOnServerSideTest() { + void startingAndroidAppWithCapabilitiesAndFlagsOnServerSideTest() { UiAutomator2Options serverOptions = new UiAutomator2Options() .setDeviceName("Android Emulator") .fullReset() diff --git a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyIosTest.java b/src/test/java/io/appium/java_client/service/local/StartingAppLocallyIosTest.java index ec629f8ba..07bf8008a 100644 --- a/src/test/java/io/appium/java_client/service/local/StartingAppLocallyIosTest.java +++ b/src/test/java/io/appium/java_client/service/local/StartingAppLocallyIosTest.java @@ -33,9 +33,9 @@ import org.openqa.selenium.Capabilities; import org.openqa.selenium.Platform; -public class StartingAppLocallyIosTest { +class StartingAppLocallyIosTest { @Test - public void startingIOSAppWithCapabilitiesOnlyTest() { + void startingIOSAppWithCapabilitiesOnlyTest() { XCUITestOptions options = new XCUITestOptions() .setPlatformVersion(BaseIOSTest.PLATFORM_VERSION) .setDeviceName(BaseIOSTest.DEVICE_NAME) @@ -57,7 +57,7 @@ public void startingIOSAppWithCapabilitiesOnlyTest() { @Test - public void startingIOSAppWithCapabilitiesAndServiceTest() { + void startingIOSAppWithCapabilitiesAndServiceTest() { XCUITestOptions options = new XCUITestOptions() .setPlatformVersion(BaseIOSTest.PLATFORM_VERSION) .setDeviceName(BaseIOSTest.DEVICE_NAME) @@ -80,7 +80,7 @@ public void startingIOSAppWithCapabilitiesAndServiceTest() { } @Test - public void startingIOSAppWithCapabilitiesAndFlagsOnServerSideTest() { + void startingIOSAppWithCapabilitiesAndFlagsOnServerSideTest() { XCUITestOptions serverOptions = new XCUITestOptions() .setPlatformVersion(BaseIOSTest.PLATFORM_VERSION) .setDeviceName(BaseIOSTest.DEVICE_NAME) diff --git a/src/test/java/io/appium/java_client/service/local/ThreadSafetyTest.java b/src/test/java/io/appium/java_client/service/local/ThreadSafetyTest.java index 50d59a5df..f4fb55b42 100644 --- a/src/test/java/io/appium/java_client/service/local/ThreadSafetyTest.java +++ b/src/test/java/io/appium/java_client/service/local/ThreadSafetyTest.java @@ -4,11 +4,9 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import io.appium.java_client.service.local.AppiumDriverLocalService; -import io.appium.java_client.service.local.AppiumServerHasNotBeenStartedLocallyException; import org.junit.jupiter.api.Test; -public class ThreadSafetyTest { +class ThreadSafetyTest { private final AppiumDriverLocalService service = AppiumDriverLocalService.buildDefaultService(); private final Action run = new Action() { @@ -32,7 +30,8 @@ public class ThreadSafetyTest { }; private final Action stop2 = stop.clone(); - @Test public void whenFewTreadsDoTheSameWork() throws Throwable { + @Test + void whenFewTreadsDoTheSameWork() throws Throwable { TestThread runTestThread = new TestThread<>(run); TestThread runTestThread2 = new TestThread<>(run2); @@ -116,7 +115,8 @@ public class ThreadSafetyTest { } - @Test public void whenFewTreadsDoDifferentWork() throws Throwable { + @Test + void whenFewTreadsDoDifferentWork() throws Throwable { TestThread runTestThread = new TestThread<>(run); TestThread runTestThread2 = new TestThread<>(run2);