Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
<artifactId>mockito-core</artifactId>
<version>3.3.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -94,6 +94,11 @@
<version>1.25</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.3.4</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.saucelabs.saucebindings;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public enum DeviceOrientation {
LANDSCAPE("landscape"),
PORTRAIT("portrait");

@Getter
private final String value;

private static final class DeviceOrientationLookup {
private static final Map<String, String> lookup = new HashMap<String, String>();
}

public static Set keys() {
return DeviceOrientationLookup.lookup.keySet();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also be return Stream.of(this.values()).map((x) -> x.name()).collect(toList())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it took me a while to find an approach that worked for what I needed. This code matches what I'm doing in all the other enums. Is the an advantage to replacing the code in all of them?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say it makes sense since we get rid of the redundant data structure. All operations could be done using native methods of the Enum class itself

}

DeviceOrientation(String value) {
this.value = value;
DeviceOrientationLookup.lookup.put(value, this.name());
}

public static String fromString(String value) {
return DeviceOrientationLookup.lookup.get(value);
Copy link

@mykola-mokhnach mykola-mokhnach May 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return this.valueOf(value.toUpperCase())
or
return Stream.of(this.values()).findFirst((x) -> x.value.equalsIgnoreCase(value)).orElse(null)

}

public String toString() {
return this.value;
}
}
36 changes: 36 additions & 0 deletions java/src/main/java/com/saucelabs/saucebindings/DeviceType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.saucelabs.saucebindings;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public enum DeviceType {
PHONE("phone"),
TABLET("tablet");

@Getter
private final String value;

private static final class DeviceTypeLookup {
private static final Map<String, String> lookup = new HashMap<String, String>();
}

public static Set keys() {
return DeviceTypeLookup.lookup.keySet();
}

DeviceType(String value) {
this.value = value;
DeviceTypeLookup.lookup.put(value, this.name());
}

public static String fromString(String value) {
return DeviceTypeLookup.lookup.get(value);
}

public String toString() {
return this.value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.saucelabs.saucebindings;

import io.appium.java_client.android.AndroidDriver;
import lombok.Getter;
import org.openqa.selenium.MutableCapabilities;

import java.net.URL;

public class SauceAndroidSession extends SauceSession<AndroidDriver> {
@Getter private AndroidDriver driver;

public SauceAndroidSession() {
this(SauceOptions.android());
}

public SauceAndroidSession(SauceOptions options) {
setSauceOptions(options);
}

protected AndroidDriver createDriver(URL url, MutableCapabilities capabilities) {
this.driver = new AndroidDriver(url, capabilities);
return driver;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.saucelabs.saucebindings;

import lombok.Getter;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public enum SauceAutomationName {
UIAUTOMATOR2("UiAutomator2"),
APPIUM("Appium");

@Getter
private final String value;

private static final class AutomationNameLookup {
private static final Map<String, String> lookup = new HashMap<String, String>();
}

public static Set keys() {
return AutomationNameLookup.lookup.keySet();
}

SauceAutomationName(String value) {
this.value = value;
AutomationNameLookup.lookup.put(value, this.name());
}

public static String fromString(String value) {
return AutomationNameLookup.lookup.get(value);
}

public String toString() {
return this.value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.saucelabs.saucebindings;

import io.appium.java_client.ios.IOSDriver;
import lombok.Getter;
import org.openqa.selenium.MutableCapabilities;

import java.net.URL;

public class SauceIOSSession extends SauceSession<IOSDriver> {
@Getter private IOSDriver driver;

public SauceIOSSession() {
this(SauceOptions.ios());
}

public SauceIOSSession(SauceOptions options) {
setSauceOptions(options);
}

protected IOSDriver createDriver(URL url, MutableCapabilities capabilities) {
this.driver = new IOSDriver(url, capabilities);
return driver;
}
}
Loading