diff options
author | Benjamin Wulfe <benwu@google.com> | 2014-12-19 19:20:08 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2014-12-19 19:20:08 +0000 |
commit | c6c3707685daf46a049df86c727a444094fe7638 (patch) | |
tree | 365ec10545086839ba4fb51185740152a6803b2a | |
parent | a8cbca2cbe417601e03a9432e77170e209a528d8 (diff) | |
parent | dc8ca50a2476c17880b7ed66836487ded42b83a5 (diff) | |
download | login-c6c3707685daf46a049df86c727a444094fe7638.tar.gz |
Adds support for unit tests.
automerge: dc8ca50
* commit 'dc8ca50a2476c17880b7ed66836487ded42b83a5':
Adds support for unit tests.
-rw-r--r-- | google-login.iml | 11 | ||||
-rw-r--r-- | src/com/google/gct/login/GoogleLogin.java | 6 | ||||
-rw-r--r-- | testSrc/com/google/gct/login/MockGoogleLogin.java | 36 |
3 files changed, 53 insertions, 0 deletions
diff --git a/google-login.iml b/google-login.iml index 98d6565..a34e18a 100644 --- a/google-login.iml +++ b/google-login.iml @@ -71,6 +71,17 @@ </library> </orderEntry> <orderEntry type="library" scope="TEST" name="JUnit3" level="project" /> + <orderEntry type="module-library"> + <library> + <CLASSES> + <root url="jar://$MODULE_DIR$/../../../adt/idea/android/lib/mockito-all-1.9.5.jar!/" /> + </CLASSES> + <JAVADOC /> + <SOURCES> + <root url="jar://$MODULE_DIR$/../../../adt/idea/android/lib/mockito-all-1.9.5.jar!/" /> + </SOURCES> + </library> + </orderEntry> </component> </module> diff --git a/src/com/google/gct/login/GoogleLogin.java b/src/com/google/gct/login/GoogleLogin.java index 92c7813..e5f1a76 100644 --- a/src/com/google/gct/login/GoogleLogin.java +++ b/src/com/google/gct/login/GoogleLogin.java @@ -20,6 +20,7 @@ import com.google.api.client.auth.oauth2.Credential; import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeRequestUrl; import com.google.api.client.googleapis.auth.oauth2.GoogleOAuthConstants; import com.google.api.client.http.HttpRequestFactory; +import com.google.api.client.repackaged.com.google.common.annotations.VisibleForTesting; import com.google.common.base.Strings; import com.google.gct.login.ui.GoogleLoginActionButton; import com.google.gct.login.ui.GoogleLoginCopyAndPasteDialog; @@ -85,6 +86,11 @@ public class GoogleLogin { return instance; } + @VisibleForTesting + static void setInstance(GoogleLogin newInstance) { + instance = newInstance; + } + /** * Displays a dialog to prompt the user to login into Google Services. * @throws InvalidThreadTypeException diff --git a/testSrc/com/google/gct/login/MockGoogleLogin.java b/testSrc/com/google/gct/login/MockGoogleLogin.java new file mode 100644 index 0000000..d17652c --- /dev/null +++ b/testSrc/com/google/gct/login/MockGoogleLogin.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.google.gct.login; + +import org.mockito.Mockito; + +import java.io.*; + +/** + * Helper to install a mock googleLogin + */ +public class MockGoogleLogin { + GoogleLogin myGoogleLogin; + + public void install() { + myGoogleLogin = GoogleLogin.getInstance(); + GoogleLogin.setInstance(Mockito.mock(GoogleLogin.class)); + } + + public void cleanup() { + GoogleLogin.setInstance(myGoogleLogin); + } +} |