下面列出了android.support.annotation.VisibleForTesting#PRIVATE 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
static Single<String> checkGhostBlog(@NonNull String blogUrl,
@NonNull OkHttpClient client) {
final String adminPagePath = "/ghost/";
String adminPageUrl = NetworkUtils.makeAbsoluteUrl(blogUrl, adminPagePath);
return checkUrl(adminPageUrl, client).flatMap(response -> {
if (response.isSuccessful()) {
// the request may have been redirected, most commonly from HTTP => HTTPS
// so pick up the eventual URL of the blog and use that
// (even if the user manually entered HTTP - it's certainly a mistake)
// to get that, chop off the admin page path from the end
String potentiallyRedirectedUrl = response.request().url().toString();
String finalBlogUrl = potentiallyRedirectedUrl.replaceFirst(adminPagePath + "?$", "");
return Single.just(finalBlogUrl);
} else if (response.code() == HttpURLConnection.HTTP_NOT_FOUND) {
return Single.error(new UrlNotFoundException(blogUrl));
} else {
return Single.error(new RuntimeException("Response code " + response.code()
+ " on requesting admin page at " + adminPageUrl));
}
});
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
LoginOrchestrator(BlogUrlValidator blogUrlValidator, ApiProviderFactory apiProviderFactory,
CredentialSource credentialSource, CredentialSink credentialSink,
HACKListener hackListener) {
mBlogUrlValidator = blogUrlValidator;
mApiProviderFactory = apiProviderFactory;
mCredentialSource = credentialSource;
mCredentialSink = credentialSink;
mHACKListener = hackListener;
mListeners = new HashSet<>();
reset();
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
AuthService(String blogUrl, GhostApiService api,
CredentialSource credSource, CredentialSink credSink) {
mBlogUrl = blogUrl;
mApi = api;
mCredentialSource = credSource;
mCredentialSink = credSink;
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
public void setObjectGraph(ObjectGraph objectGraph) {
this.objectGraph = objectGraph;
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
static boolean isMinutesDiffMax(DateTime dateTime1, DateTime dateTime2, int maxMinutes) {
Period period = new Period(dateTime1, dateTime2);
Duration duration = period.toDurationFrom(dateTime1);
return Math.abs(duration.toStandardMinutes().getMinutes()) <= maxMinutes;
}
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
static String normalizeBlogUrl(String inputBlogUrl) {
return inputBlogUrl.trim().replaceFirst("^(.*)/ghost/?$", "$1");
}