diff options
author | Benjamin Wulfe <benwu@google.com> | 2014-12-08 10:35:36 -0500 |
---|---|---|
committer | Benjamin Wulfe <benwu@google.com> | 2014-12-12 20:44:02 +0000 |
commit | dc8ca50a2476c17880b7ed66836487ded42b83a5 (patch) | |
tree | fec94c035ba19eb2841465e7c7018fa95f6fa038 | |
parent | 9d5ed765f14e232ac4cb7e26f0caa5fb6e850db7 (diff) | |
download | login-dc8ca50a2476c17880b7ed66836487ded42b83a5.tar.gz |
Adds support for unit tests.
Change-Id: I8bf64d67bb3c3bae240c478c0e45ad5d5110fd88
-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 0e77b59..ce5b745 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; @@ -84,6 +85,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); + } +} |