Skip to content

Commit

Permalink
test: updated JUnit5 test classes and methods to have default package…
Browse files Browse the repository at this point in the history
… visibility (#1755)
  • Loading branch information
bipin-k committed Sep 1, 2022
1 parent c9a5c92 commit 54fdd4b
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 64 deletions.
10 changes: 5 additions & 5 deletions src/test/java/io/appium/java_client/internal/ConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -53,7 +52,7 @@ public static Stream<Arguments> data() {

@ParameterizedTest
@MethodSource("data")
public void checkThatWidgetsAreCreatedCorrectly(AbstractApp app, WebDriver driver, Class<? extends DefaultStubWidget> widgetClass) {
void checkThatWidgetsAreCreatedCorrectly(AbstractApp app, WebDriver driver, Class<? extends DefaultStubWidget> widgetClass) {
initElements(new AppiumFieldDecorator(driver), app);
assertThat("Expected widget class was " + widgetClass.getName(),
app.getWidget().getSelfReference().getClass(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static Stream<Arguments> 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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -93,7 +92,7 @@ public void tearDown() throws Exception {
}

@Test
public void checkAbilityToAddLogMessageConsumer() {
void checkAbilityToAddLogMessageConsumer() {
List<String> log = new ArrayList<>();
service = buildDefaultService();
service.clearOutPutStreams();
Expand All @@ -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);
Expand All @@ -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)
Expand All @@ -150,7 +149,7 @@ public void checkAbilityToStartServiceUsingFlags() {
}

@Test
public void checkAbilityToStartServiceUsingCapabilities() {
void checkAbilityToStartServiceUsingCapabilities() {
UiAutomator2Options options = new UiAutomator2Options()
.fullReset()
.setNewCommandTimeout(Duration.ofSeconds(60))
Expand All @@ -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()
Expand All @@ -191,21 +190,21 @@ 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();
assertThat(testLogFile.length(), greaterThan(0L));
}

@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);
Expand All @@ -214,15 +213,15 @@ public void checkAbilityToChangeOutputStreamAfterTheServiceIsStarted() throws Ex
}

@Test
public void checkAbilityToShutDownService() {
void checkAbilityToShutDownService() {
service = buildDefaultService();
service.start();
service.stop();
assertFalse(service.isRunning());
}

@Test
public void checkAbilityToStartAndShutDownFewServices() throws Exception {
void checkAbilityToStartAndShutDownFewServices() throws Exception {
List<AppiumDriverLocalService> services = asList(
new AppiumServiceBuilder().usingAnyFreePort().build(),
new AppiumServiceBuilder().usingAnyFreePort().build(),
Expand All @@ -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();
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -272,7 +271,7 @@ public void checkAbilityToStartServiceWithPortUsingShortFlag() {
}

@Test
public void checkAbilityToStartServiceWithIpUsingFlag() {
void checkAbilityToStartServiceWithIpUsingFlag() {
String expectedUrl = String.format("http://%s:4723/", testIP);

service = new AppiumServiceBuilder()
Expand All @@ -284,7 +283,7 @@ public void checkAbilityToStartServiceWithIpUsingFlag() {
}

@Test
public void checkAbilityToStartServiceWithIpUsingShortFlag() {
void checkAbilityToStartServiceWithIpUsingShortFlag() {
String expectedUrl = String.format("http://%s:4723/", testIP);

service = new AppiumServiceBuilder()
Expand All @@ -296,7 +295,7 @@ public void checkAbilityToStartServiceWithIpUsingShortFlag() {
}

@Test
public void checkAbilityToStartServiceWithLogFileUsingFlag() {
void checkAbilityToStartServiceWithLogFileUsingFlag() {
testLogFile = new File("Log2.txt");

service = new AppiumServiceBuilder()
Expand All @@ -307,7 +306,7 @@ public void checkAbilityToStartServiceWithLogFileUsingFlag() {
}

@Test
public void checkAbilityToStartServiceWithLogFileUsingShortFlag() {
void checkAbilityToStartServiceWithLogFileUsingShortFlag() {
testLogFile = new File("Log3.txt");

service = new AppiumServiceBuilder()
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,27 @@

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;
import io.appium.java_client.remote.MobileCapabilityType;
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()
Expand All @@ -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);
Expand All @@ -79,7 +78,7 @@ public void startingAndroidAppWithCapabilitiesAndServiceTest() {
}

@Test
public void startingAndroidAppWithCapabilitiesAndFlagsOnServerSideTest() {
void startingAndroidAppWithCapabilitiesAndFlagsOnServerSideTest() {
UiAutomator2Options serverOptions = new UiAutomator2Options()
.setDeviceName("Android Emulator")
.fullReset()
Expand Down

0 comments on commit 54fdd4b

Please sign in to comment.