Skip to content

Commit

Permalink
Use more idiomatic Java
Browse files Browse the repository at this point in the history
Co-authored-by: Valery Yatsynovich <valery_yatsynovich@epam.com>
  • Loading branch information
alexh-sauce and valfirst committed Sep 25, 2023
1 parent 06ce008 commit 10c6271
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ public Process openConnection(String username, String apiKey, DataCenter dataCen

//ensure that only a single thread attempts to open a connection
if (sauceRest == null) {
sauceRest = new SauceREST(username, apiKey, dataCenter);
scEndpoint = sauceRest.getSauceConnectEndpoint();
setSauceRest(new SauceREST(username, apiKey, dataCenter));
}
String name = getTunnelName(options, username);
TunnelInformation tunnelInformation = getTunnelInformation(name);
Expand Down Expand Up @@ -486,13 +485,12 @@ private TunnelInformation getTunnelInformation(String name) {
private String activeTunnelID(String username, String tunnelName) {
try {
List<String> tunnels = scEndpoint.getTunnelsForAUser();
if (tunnels.size() == 0) {
if (tunnels.isEmpty()) {
//no active tunnels
return null;
}
//iterate over elements
for (int i = 0; i < tunnels.size(); i++) {
String tunnelId = tunnels.get(i);
for (String tunnelId : tunnels) {

com.saucelabs.saucerest.model.sauceconnect.TunnelInformation tunnelInformation = scEndpoint.getTunnelInformation(tunnelId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
import java.util.ArrayList;
import java.util.List;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -75,7 +76,7 @@ public void testOpenConnectionSuccessfullyWithCleanUpOnExit() throws IOException
}

private void testOpenConnectionSuccessfully(boolean cleanUpOnExit) throws IOException {
ArrayList<String> empty = new ArrayList<String>();
List<String> empty = new ArrayList<String>();
when(mockSCEndpoint.getTunnelsForAUser()).thenReturn(empty);
tunnelManager.setCleanUpOnExit(cleanUpOnExit);
Process process = testOpenConnection("/started_sc.log");
Expand All @@ -84,7 +85,7 @@ private void testOpenConnectionSuccessfully(boolean cleanUpOnExit) throws IOExce

@Test(expected=AbstractSauceTunnelManager.SauceConnectDidNotStartException.class)
public void openConnectionTest_closes() throws IOException, InterruptedException {
ArrayList<String> empty = new ArrayList<String>();
List<String> empty = new ArrayList<String>();
when(mockSCEndpoint.getTunnelsForAUser()).thenReturn(empty);
when(mockProcess.waitFor(30, TimeUnit.SECONDS)).thenReturn(true);
testOpenConnection("/started_sc_closes.log");
Expand All @@ -93,7 +94,7 @@ public void openConnectionTest_closes() throws IOException, InterruptedException

@Test
public void testOpenConnectionWithExtraSpacesInArgs() throws IOException {
ArrayList<String> empty = new ArrayList<String>();
List<String> empty = new ArrayList<String>();
when(mockSCEndpoint.getTunnelsForAUser()).thenReturn(empty);
testOpenConnection("/started_sc.log", " username-with-spaces-around ");
}
Expand Down Expand Up @@ -167,7 +168,7 @@ private Process testOpenConnection(String logFile, String username) throws IOExc

@Test
public void openConnectionTest_existing_tunnel() throws IOException {
ArrayList<String> active = new ArrayList<String>();
List<String> active = new ArrayList<String>();
active.add("8949e55fb5e14fd6bf6230b7a609b494");

TunnelInformation started = new TunnelInformation();
Expand Down

0 comments on commit 10c6271

Please sign in to comment.