Skip to content

Commit 5a51da0

Browse files
#565: Issues which were found by codecy were fixed
Also documentation was improved
1 parent 8fc9a82 commit 5a51da0

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

docs/Page-objects.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ import org.openqa.selenium.support.FindBy;
238238
//The default value is 0 (the highest priority)
239239
@HowToUseLocators(iOSAutomation = ALL_POSSIBLE)
240240
@iOSFindBy(someStrategy1)
241-
@iOSFindBys(value = {@iOSBy(subloctor1), @iOSBy(subloctor1)}, priority = 1) //this possible variant is
241+
@iOSFindAll(value = {@iOSBy(subloctor1), @iOSBy(subloctor1)}, priority = 1) //this possible variant is
242242
// the chain
243243
@iOSFindBy(someStrategy2, priority = 2)
244244
@iOSFindBy(someStrategy3, priority = 3)
@@ -248,7 +248,7 @@ RemoteWebElement someElement;
248248

249249
@HowToUseLocators(iOSAutomation = ALL_POSSIBLE)
250250
@iOSFindBy(someStrategy1)
251-
@iOSFindBys(value = {@iOSBy(subloctor1), @iOSBy(subloctor1)}, priority = 1) //this possible variant is
251+
@iOSFindAll(value = {@iOSBy(subloctor1), @iOSBy(subloctor1)}, priority = 1) //this possible variant is
252252
// the chain
253253
@iOSFindBy(someStrategy2, priority = 2)
254254
@iOSFindBy(someStrategy3, priority = 3)

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

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -232,41 +232,41 @@ private By returnMappedBy(By byDefault, By nativeAppBy) {
232232

233233
private static class AnnotationComparator implements Comparator<Annotation> {
234234

235-
@Override
236-
public int compare(Annotation o1, Annotation o2) {
237-
int p1;
238-
int p2;
239-
Method priority1;
240-
Method priority2;
241-
242-
Class<?> c1 = o1.annotationType();
243-
Class<?> c2 = o2.annotationType();
244-
235+
private static Method getPriorityMethod(Class<? extends Annotation> clazz) {
245236
try {
246-
priority1 = c1.getMethod(PRIORITY, ANNOTATION_ARGUMENTS);
237+
return clazz.getMethod(PRIORITY, ANNOTATION_ARGUMENTS);
247238
} catch (NoSuchMethodException e) {
248-
throw new ClassCastException(String.format("Class %s has no '%s' method", c1.getName(), PRIORITY));
239+
throw new ClassCastException(String.format("Class %s has no '%s' method", clazz.getName(), PRIORITY));
249240
}
241+
}
250242

243+
private static int getPriorityValue(Method priorityMethod, Annotation annotation,
244+
Class<? extends Annotation> clazz) {
251245
try {
252-
priority2 = c2.getMethod(PRIORITY, ANNOTATION_ARGUMENTS);
253-
} catch (NoSuchMethodException e) {
254-
throw new ClassCastException(String.format("Class %s has no '%s' method", c2.getName(), PRIORITY));
246+
return (int) priorityMethod.invoke(annotation, ANNOTATION_PARAMETERS);
247+
} catch (IllegalAccessException | InvocationTargetException e) {
248+
throw new IllegalArgumentException(String
249+
.format("It is impossible to get priority. Annotation class: %s", clazz.toString()), e);
255250
}
251+
}
256252

257-
try {
258-
p1 = (int) priority1.invoke(o1, ANNOTATION_PARAMETERS);
259-
p2 = (int) priority2.invoke(o2, ANNOTATION_PARAMETERS);
260-
261-
if (p2 > p1) {
262-
return -1;
263-
} else if (p2 < p1) {
264-
return 1;
265-
} else {
266-
return 0;
267-
}
268-
} catch (IllegalAccessException | InvocationTargetException e) {
269-
throw new RuntimeException(e);
253+
@Override
254+
public int compare(Annotation o1, Annotation o2) {
255+
Class<? extends Annotation> c1 = o1.annotationType();
256+
Class<? extends Annotation> c2 = o2.annotationType();
257+
258+
Method priority1 = getPriorityMethod(c1);
259+
Method priority2 = getPriorityMethod(c2);
260+
261+
int p1 = getPriorityValue(priority1, o1, c1);
262+
int p2 = getPriorityValue(priority2, o2, c2);
263+
264+
if (p2 > p1) {
265+
return -1;
266+
} else if (p2 < p1) {
267+
return 1;
268+
} else {
269+
return 0;
270270
}
271271
}
272272
}

0 commit comments

Comments
 (0)