Skip to content

Commit

Permalink
Remove guava dep from interactions package
Browse files Browse the repository at this point in the history
  • Loading branch information
shs96c committed Jul 8, 2018
1 parent 5a8b480 commit d8f6fd3
Show file tree
Hide file tree
Showing 18 changed files with 110 additions and 112 deletions.
28 changes: 15 additions & 13 deletions java/client/src/org/openqa/selenium/interactions/Actions.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,21 @@
import static org.openqa.selenium.interactions.PointerInput.MouseButton.LEFT;
import static org.openqa.selenium.interactions.PointerInput.MouseButton.RIGHT;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;

import org.openqa.selenium.Keys;
import org.openqa.selenium.UnsupportedCommandException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.PointerInput.Origin;
import org.openqa.selenium.interactions.internal.MouseAction.Button;
import org.openqa.selenium.interactions.internal.Locatable;
import org.openqa.selenium.interactions.internal.MouseAction.Button;

import java.time.Duration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.IntConsumer;
import java.util.logging.Logger;
Expand Down Expand Up @@ -65,7 +63,7 @@ public class Actions {
protected CompositeAction action = new CompositeAction();

public Actions(WebDriver driver) {
this.driver = Preconditions.checkNotNull(driver);
this.driver = Objects.requireNonNull(driver);

if (driver instanceof HasInputDevices) {
HasInputDevices deviceOwner = (HasInputDevices) driver;
Expand Down Expand Up @@ -241,9 +239,10 @@ private Actions sendKeysInTicks(CharSequence... keys) {

private Actions addKeyAction(CharSequence key, IntConsumer consumer) {
// Verify that we only have a single character to type.
Preconditions.checkState(
key.codePoints().count() == 1,
"Only one code point is allowed at a time: %s", key);
if (key.codePoints().count() != 1) {
throw new IllegalStateException(String.format(
"Only one code point is allowed at a time: %s", key));
}

key.codePoints().forEach(consumer);

Expand Down Expand Up @@ -523,7 +522,7 @@ public Actions pause(long pause) {
}

public Actions pause(Duration duration) {
Preconditions.checkNotNull(duration, "Duration of pause not set");
Objects.requireNonNull(duration, "Duration of pause not set");
if (isBuildingActions()) {
action.addAction(new PauseAction(duration.toMillis()));
}
Expand All @@ -550,7 +549,8 @@ public Actions tick(Interaction... actions) {
}

// And now pad the remaining sequences with a pause.
Set<InputSource> unseen = Sets.difference(sequences.keySet(), seenSources);
Set<InputSource> unseen = new HashSet<>(sequences.keySet());
unseen.removeAll(seenSources);
for (InputSource source : unseen) {
getSequence(source).addAction(new Pause(source, Duration.ZERO));
}
Expand All @@ -559,7 +559,9 @@ public Actions tick(Interaction... actions) {
}

public Actions tick(Action action) {
Preconditions.checkState(action instanceof IsInteraction);
if (!(action instanceof IsInteraction)) {
throw new IllegalStateException("Expected action to implement IsInteraction");
}

for (Interaction interaction :
((IsInteraction) action).asInteractions(defaultMouse, defaultKeyboard)) {
Expand All @@ -581,7 +583,7 @@ public Actions tick(Action action) {
* @return the composite action
*/
public Action build() {
Action toReturn = new BuiltAction(driver, ImmutableMap.copyOf(sequences), action);
Action toReturn = new BuiltAction(driver, new LinkedHashMap<>(sequences), action);
action = new CompositeAction();
sequences.clear();
return toReturn;
Expand Down
1 change: 0 additions & 1 deletion java/client/src/org/openqa/selenium/interactions/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ java_library(name = 'interactions',
deps = [
'//java/client/src/org/openqa/selenium:beta',
'//java/client/src/org/openqa/selenium:exceptions',
'//third_party/java/guava:guava',
],
visibility = [
'//java/client/src/org/openqa/selenium:selenium',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

package org.openqa.selenium.interactions;

import com.google.common.collect.ImmutableList;

import org.openqa.selenium.interactions.internal.MouseAction;
import org.openqa.selenium.interactions.internal.Locatable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand Down Expand Up @@ -49,11 +49,10 @@ public void perform() {

@Override
public List<Interaction> asInteractions(PointerInput mouse, KeyInput keyboard) {
ImmutableList.Builder<Interaction> interactions = ImmutableList.builder();
List<Interaction> interactions = new ArrayList<>(moveToLocation(mouse));

moveToLocation(mouse, interactions);
interactions.add(mouse.createPointerUp(Button.LEFT.asArg()));

return interactions.build();
return Collections.unmodifiableList(interactions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package org.openqa.selenium.interactions;

import com.google.common.collect.ImmutableList;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.internal.MouseAction;
import org.openqa.selenium.interactions.internal.Locatable;
import org.openqa.selenium.interactions.internal.MouseAction;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -42,12 +42,11 @@ public void perform() {

@Override
public List<Interaction> asInteractions(PointerInput mouse, KeyInput keyboard) {
ImmutableList.Builder<Interaction> interactions = ImmutableList.builder();
List<Interaction> interactions = new ArrayList<>(moveToLocation(mouse));

moveToLocation(mouse, interactions);
interactions.add(mouse.createPointerDown(Button.LEFT.asArg()));
interactions.add(mouse.createPointerUp(Button.LEFT.asArg()));

return interactions.build();
return Collections.unmodifiableList(interactions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package org.openqa.selenium.interactions;

import com.google.common.collect.ImmutableList;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.internal.MouseAction;
import org.openqa.selenium.interactions.internal.Locatable;
import org.openqa.selenium.interactions.internal.MouseAction;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -48,10 +48,8 @@ public void perform() {

@Override
public List<Interaction> asInteractions(PointerInput mouse, KeyInput keyboard) {
ImmutableList.Builder<Interaction> interactions = ImmutableList.builder();

moveToLocation(mouse, interactions);
List<Interaction> interactions = new ArrayList<>(moveToLocation(mouse));

return interactions.build();
return Collections.unmodifiableList(interactions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@

package org.openqa.selenium.interactions;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* An action for aggregating actions and triggering all of them at the same time.
Expand All @@ -38,23 +36,23 @@ public void perform() {
}

public CompositeAction addAction(Action action) {
Preconditions.checkNotNull(action, "Null actions are not supported.");
Objects.requireNonNull(action, "Null actions are not supported.");
actionsList.add(action);
return this;
}

/**
* @deprecated No replacement.
*/
@VisibleForTesting
//VisibleForTesting
@Deprecated
int getNumberOfActions() {
return actionsList.size();
}

@Override
public List<Interaction> asInteractions(PointerInput mouse, KeyInput keyboard) {
ImmutableList.Builder<Interaction> interactions = ImmutableList.builder();
List<Interaction> interactions = new ArrayList<>();

for (Action action : actionsList) {
if (!(action instanceof IsInteraction)) {
Expand All @@ -65,6 +63,6 @@ public List<Interaction> asInteractions(PointerInput mouse, KeyInput keyboard) {
interactions.addAll(((IsInteraction) action).asInteractions(mouse, keyboard));
}

return interactions.build();
return Collections.unmodifiableList(interactions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package org.openqa.selenium.interactions;

import com.google.common.collect.ImmutableList;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.internal.MouseAction;
import org.openqa.selenium.interactions.internal.Locatable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -46,12 +46,12 @@ public void perform() {

@Override
public List<Interaction> asInteractions(PointerInput mouse, KeyInput keyboard) {
ImmutableList.Builder<Interaction> interactions = ImmutableList.builder();
List<Interaction> interactions = new ArrayList<>();

moveToLocation(mouse, interactions);
interactions.addAll(moveToLocation(mouse));
interactions.add(mouse.createPointerDown(Button.RIGHT.asArg()));
interactions.add(mouse.createPointerUp(Button.RIGHT.asArg()));

return interactions.build();
return Collections.unmodifiableList(interactions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package org.openqa.selenium.interactions;

import com.google.common.collect.ImmutableList;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.internal.MouseAction;
import org.openqa.selenium.interactions.internal.Locatable;
import org.openqa.selenium.interactions.internal.MouseAction;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -46,14 +46,13 @@ public void perform() {

@Override
public List<Interaction> asInteractions(PointerInput mouse, KeyInput keyboard) {
ImmutableList.Builder<Interaction> interactions = ImmutableList.builder();
List<Interaction> interactions = new ArrayList<>(moveToLocation(mouse));

moveToLocation(mouse, interactions);
interactions.add(mouse.createPointerDown(Button.LEFT.asArg()));
interactions.add(mouse.createPointerUp(Button.LEFT.asArg()));
interactions.add(mouse.createPointerDown(Button.LEFT.asArg()));
interactions.add(mouse.createPointerUp(Button.LEFT.asArg()));

return interactions.build();
return Collections.unmodifiableList(interactions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

package org.openqa.selenium.interactions;

import com.google.common.collect.ImmutableList;

import org.openqa.selenium.Keys;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.internal.SingleKeyAction;
import org.openqa.selenium.interactions.internal.Locatable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -49,11 +49,11 @@ public void perform() {

@Override
public List<Interaction> asInteractions(PointerInput mouse, KeyInput keyboard) {
ImmutableList.Builder<Interaction> interactions = ImmutableList.builder();
ArrayList<Interaction> interactions = new ArrayList<>();

optionallyClickElement(mouse, interactions);
interactions.addAll(optionallyClickElement(mouse));
interactions.add(keyboard.createKeyDown(key.getCodePoint()));

return interactions.build();
return Collections.unmodifiableList(interactions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package org.openqa.selenium.interactions;

import com.google.common.collect.ImmutableList;

import org.openqa.selenium.Keys;
import org.openqa.selenium.interactions.internal.SingleKeyAction;
import org.openqa.selenium.interactions.internal.Locatable;
import org.openqa.selenium.interactions.internal.SingleKeyAction;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -48,12 +48,11 @@ public void perform() {

@Override
public List<Interaction> asInteractions(PointerInput mouse, KeyInput keyboard) {
ImmutableList.Builder<Interaction> toReturn = ImmutableList.builder();
List<Interaction> toReturn = new ArrayList<>(optionallyClickElement(mouse));

optionallyClickElement(mouse, toReturn);
toReturn.add(keyboard.createKeyUp(key.getCodePoint()));

return toReturn.build();
return Collections.unmodifiableList(toReturn);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@

package org.openqa.selenium.interactions;

import com.google.common.collect.ImmutableList;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.internal.MouseAction;
import org.openqa.selenium.interactions.internal.Locatable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand All @@ -45,10 +45,8 @@ public void perform() {

@Override
public List<Interaction> asInteractions(PointerInput mouse, KeyInput keyboard) {
ImmutableList.Builder<Interaction> interactions = ImmutableList.builder();

moveToLocation(mouse, interactions);
List<Interaction> interactions = new ArrayList<>(moveToLocation(mouse));

return interactions.build();
return Collections.unmodifiableList(interactions);
}
}
Loading

0 comments on commit d8f6fd3

Please sign in to comment.