Skip to content

Commit 2419dca

Browse files
Code style issues which were found by reviewer were fixed
1 parent 938ec64 commit 2419dca

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

src/main/java/io/appium/java_client/pagefactory/AppiumElementLocatorFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import java.lang.reflect.AnnotatedElement;
2828
import java.lang.reflect.Field;
29+
import javax.annotation.Nullable;
2930

3031
public class AppiumElementLocatorFactory implements CacheableElementLocatorFactory {
3132
private final SearchContext searchContext;
@@ -47,11 +48,11 @@ public AppiumElementLocatorFactory(SearchContext searchContext, TimeOutDuration
4748
this.builder = builder;
4849
}
4950

50-
public CacheableLocator createLocator(Field field) {
51+
public @Nullable CacheableLocator createLocator(Field field) {
5152
return this.createLocator((AnnotatedElement) field);
5253
}
5354

54-
@Override public CacheableLocator createLocator(AnnotatedElement annotatedElement) {
55+
@Override public @Nullable CacheableLocator createLocator(AnnotatedElement annotatedElement) {
5556
TimeOutDuration customDuration;
5657
if (annotatedElement.isAnnotationPresent(WithTimeout.class)) {
5758
WithTimeout withTimeout = annotatedElement.getAnnotation(WithTimeout.class);

src/test/java/io/appium/java_client/ChromeDriverPathUtil.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ public static File getChromeDriver() {
2323
return ROOT_TEST_PATH.resolve("chromedriver.exe").toFile();
2424
} else if (current.is(MAC)) {
2525
return ROOT_TEST_PATH.resolve("chromedriver_mac").toFile();
26-
} else {
27-
return ROOT_TEST_PATH.resolve("chromedriver_linux").toFile();
2826
}
27+
28+
return ROOT_TEST_PATH.resolve("chromedriver_linux").toFile();
2929
}
3030
}

src/test/java/io/appium/java_client/pagefactory_tests/TimeoutTest.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
public class TimeoutTest {
5050

51-
private static final long ACCEPTABLE_TIME_DIFF = 1500;
51+
private static final long ACCEPTABLE_TIME_DIFF_MS = 1500;
5252
private static final String MESSAGE = "Check difference from the expected waiting duration %s %s";
5353

5454
private WebDriver driver;
@@ -65,15 +65,15 @@ public class TimeoutTest {
6565

6666
private TimeOutDuration timeOutDuration;
6767

68-
private static long getBenchmark(Runnable runnable) {
68+
private static long getExpectedMillis(long value, TimeUnit sourceTimeUnit) {
69+
return MILLISECONDS.convert(value, sourceTimeUnit);
70+
}
71+
72+
private static long getPerformanceDiff(long expectedMs, Runnable runnable) {
6973
long startMark = currentTimeMillis();
7074
runnable.run();
7175
long endMark = currentTimeMillis();
72-
return endMark - startMark;
73-
}
74-
75-
private static long getExpectedMillis(long value, TimeUnit sourceTimeUnit) {
76-
return MILLISECONDS.convert(value, sourceTimeUnit);
76+
return abs(expectedMs - (endMark - startMark));
7777
}
7878

7979
/**
@@ -96,37 +96,37 @@ private static long getExpectedMillis(long value, TimeUnit sourceTimeUnit) {
9696

9797
@Test public void defaultTimeOutTest() {
9898
assertThat(format(MESSAGE, DEFAULT_TIMEOUT, DEFAULT_TIMEUNIT),
99-
abs(getExpectedMillis(DEFAULT_TIMEOUT, DEFAULT_TIMEUNIT) - getBenchmark(() -> stubElements.size())),
100-
lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF));
99+
getPerformanceDiff(getExpectedMillis(DEFAULT_TIMEOUT, DEFAULT_TIMEUNIT), () -> stubElements.size()),
100+
lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF_MS));
101101

102102
timeOutDuration.setTime(15500000, MICROSECONDS);
103103
assertThat(format(MESSAGE, 15500000, MICROSECONDS),
104-
abs(getExpectedMillis(15500000, MICROSECONDS) - getBenchmark(() -> stubElements.size())),
105-
lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF));
104+
getPerformanceDiff(getExpectedMillis(15500000, MICROSECONDS), () -> stubElements.size()),
105+
lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF_MS));
106106

107107
timeOutDuration.setTime(3, SECONDS);
108108
assertThat(format(MESSAGE, 3, SECONDS),
109-
abs(getExpectedMillis(3, SECONDS) - getBenchmark(() -> stubElements.size())),
110-
lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF));
109+
getPerformanceDiff(getExpectedMillis(3, SECONDS), () -> stubElements.size()),
110+
lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF_MS));
111111
}
112112

113113
@Test public void withCustomizedTimeOutTest() {
114114
assertThat(format(MESSAGE, DEFAULT_TIMEOUT, DEFAULT_TIMEUNIT),
115-
abs(getExpectedMillis(DEFAULT_TIMEOUT, DEFAULT_TIMEUNIT) - getBenchmark(() -> stubElements.size())),
116-
lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF));
115+
getPerformanceDiff(getExpectedMillis(DEFAULT_TIMEOUT, DEFAULT_TIMEUNIT), () -> stubElements.size()),
116+
lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF_MS));
117117

118118
assertThat(format(MESSAGE, 5, SECONDS),
119-
abs(getExpectedMillis(5, SECONDS) - getBenchmark(() -> stubElements2.size())),
120-
lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF));
119+
getPerformanceDiff(getExpectedMillis(5, SECONDS), () -> stubElements2.size()),
120+
lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF_MS));
121121

122122
timeOutDuration.setTime(15500000, MICROSECONDS);
123123

124124
assertThat(format(MESSAGE, 15500000, MICROSECONDS),
125-
abs(getExpectedMillis(15500000, MICROSECONDS) - getBenchmark(() -> stubElements.size())),
126-
lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF));
125+
getPerformanceDiff(getExpectedMillis(15500000, MICROSECONDS), () -> stubElements.size()),
126+
lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF_MS));
127127

128128
assertThat(format(MESSAGE, 5, SECONDS),
129-
abs(getExpectedMillis(5, SECONDS) - getBenchmark(() -> stubElements2.size())),
130-
lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF));
129+
getPerformanceDiff(getExpectedMillis(5, SECONDS), () -> stubElements2.size()),
130+
lessThanOrEqualTo(ACCEPTABLE_TIME_DIFF_MS));
131131
}
132132
}

0 commit comments

Comments
 (0)