Skip to content

Mykola mokhnach's actions params: The addition to the #756 #760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 12, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 2 additions & 5 deletions src/main/java/io/appium/java_client/touch/WaitOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Optional.ofNullable;

import java.time.Duration;
import java.util.Map;
Expand Down Expand Up @@ -53,15 +52,13 @@ public WaitOptions withDuration(Duration duration) {

@Override
protected void verify() {
ofNullable(duration).orElseThrow(() ->
new IllegalArgumentException("Duration value should not be a null value"));
//there is nothing to check
}

@Override
public Map<String, Object> build() {
final Map<String, Object> result = super.build();
ofNullable(duration).ifPresent(durationParam ->
result.put("ms", durationParam.toMillis()));
result.put("ms", duration.toMillis());
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;

public final class FailsWithMatcher<E extends Throwable> extends TypeSafeMatcher<IThrowingRunnable<E>> {
public final class FailsWithMatcher<E extends Throwable> extends TypeSafeMatcher<Runnable> {

private final Matcher<? super E> matcher;

private FailsWithMatcher(final Matcher<? super E> matcher) {
this.matcher = matcher;
}

public static <E extends Throwable> Matcher<IThrowingRunnable<E>> failsWith(
public static <E extends Throwable> Matcher<Runnable> failsWith(
final Class<E> throwableType) {
return new FailsWithMatcher<>(instanceOf(throwableType));
}

public static <E extends Throwable> Matcher<IThrowingRunnable<E>> failsWith(
public static <E extends Throwable> Matcher<Runnable> failsWith(
final Class<E> throwableType, final Matcher<? super E> throwableMatcher) {
return new FailsWithMatcher<>(allOf(instanceOf(throwableType), throwableMatcher));
Copy link
Member

Choose a reason for hiding this comment

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

Also compilation error here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

??? ок

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SrinivasanTarget
I can't reproduce it even after removal of the project from the disc and cloning it again.
Could you try again? If you are facing the same issue could you provide some text of the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@SrinivasanTarget even Travis could compile the project

Copy link
Member

Choose a reason for hiding this comment

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

Yes travis wasn't able to catch it. Only IDE throws it on file level but still project builds fine. no instance of type variable exists so that E conforms to capture of ? super.... is error.

Copy link
Member

Choose a reason for hiding this comment

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

looks fine in latest IDE

Copy link
Contributor

Choose a reason for hiding this comment

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

Do you use Eclipse?

Copy link
Member

Choose a reason for hiding this comment

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

Intellij IDEA 2017.1.5 throws this error but no errors in Intellij IDEA 2017.2

}

@Override
protected boolean matchesSafely(final IThrowingRunnable<E> runnable) {
protected boolean matchesSafely(final Runnable runnable) {
try {
runnable.run();
return false;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static io.appium.java_client.touch.WaitOptions.waitOptions;
import static java.time.Duration.ofMillis;
import static java.time.Duration.ofSeconds;
import static junit.framework.TestCase.fail;
import static org.hamcrest.CoreMatchers.everyItem;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.isIn;
Expand All @@ -24,34 +25,28 @@
public class TouchOptionsTests {
private static final WebElement DUMMY_ELEMENT = new DummyElement();

@Test
@Test(expected = IllegalArgumentException.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't know about such possibility %)

public void invalidAbsolutePositionOptionsShouldFailOnBuild() throws Exception {
final List<ActionOptions> invalidOptions = new ArrayList<>();
invalidOptions.add(new AbsoluteOffsetOption());
for (ActionOptions opts : invalidOptions) {
assertThat(opts::build, failsWith(IllegalArgumentException.class));
}
new AbsoluteOffsetOption().build();
fail("The exception throwing was expected");
}

@Test
@Test(expected = IllegalArgumentException.class)
public void invalidRelativePositionOptionsShouldFailOnBuild() throws Exception {
final List<ActionOptions> invalidOptions = new ArrayList<>();
invalidOptions.add(new RelativeOffsetOption());
for (ActionOptions opts : invalidOptions) {
assertThat(opts::build, failsWith(IllegalArgumentException.class));
}
new RelativeOffsetOption().build();
fail("The exception throwing was expected");
}

@Test
public void invalidOptionsArgumentsShouldFailOnAltering() throws Exception {
final List<IThrowingRunnable<RuntimeException>> invalidOptions = new ArrayList<>();
final List<Runnable> invalidOptions = new ArrayList<>();
invalidOptions.add(() -> waitOptions(ofMillis(-1)));
invalidOptions.add(() -> new RelativeOffsetOption().withRelativeOffset(null, 0, 0));
invalidOptions.add(() -> new WaitOptions().withDuration(null));
invalidOptions.add(() -> tapOptions().withTapsCount(-1));
invalidOptions.add(() -> longPressOptions().withDuration(null));
invalidOptions.add(() -> longPressOptions().withDuration(ofMillis(-1)));
for (IThrowingRunnable<RuntimeException> item : invalidOptions) {
for (Runnable item : invalidOptions) {
assertThat(item, failsWith(RuntimeException.class));
}
}
Expand Down