Skip to content
Permalink
Browse files
[JENKINS-38058] explicit check for constructor existence
  • Loading branch information
Manuel Franco committed Sep 13, 2016
1 parent 7454e77 commit b26cce4360c36228d60393a2d3a4ce8d06497b66
Showing with 16 additions and 6 deletions.
  1. +16 −6 src/main/java/org/jenkinsci/test/acceptance/po/JobsMixIn.java
@@ -1,5 +1,6 @@
package org.jenkinsci.test.acceptance.po;

import java.net.URL;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
@@ -58,14 +59,23 @@ public Object call() throws Exception {
}

public <T extends TopLevelItem> T get(Class<T> type, String name) {
try {
assert getContext() != null;
if (contextAvailable() && typeAcceptsContext(type)) {
return newInstance(type, getContext(), url("job/%s/", name), name);
} catch (AssertionError e) {
// will get here either if the contructor with 'context' parameter
// was not found or if we have no context
return newInstance(type, injector, url("job/%s/", name), name);
}
return newInstance(type, injector, url("job/%s/", name), name);
}

private <T extends TopLevelItem> boolean typeAcceptsContext(Class<T> type) {
try {
type.getConstructor(PageObject.class, URL.class, String.class);
return true;
} catch (NoSuchMethodException e) {
return false;
}
}

private boolean contextAvailable() {
return getContext() != null;
}

public FreeStyleJob create() {

0 comments on commit b26cce4

Please sign in to comment.