-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: 1. Add a simple serial executor which will can be used to mock multithread executor and make Runnable execute in serial way 2. Remove AnalytisUserIDTest which is deprecated 3. Add AppEventsLoggerTest, which tests analytics user id Reviewed By: jingping2015, dreamolight Differential Revision: D14340044 fbshipit-source-id: 48db11027340a972cfd89b7d0a4981020a98d3ad
- Loading branch information
1 parent
77d91b4
commit f495c83
Showing
3 changed files
with
106 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 0 additions & 68 deletions
68
facebook/src/test/java/com/facebook/appevents/AnalyticsUserIDTest.java
This file was deleted.
Oops, something went wrong.
93 changes: 93 additions & 0 deletions
93
facebook/src/test/java/com/facebook/appevents/AppEventsLoggerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved. | ||
* | ||
* You are hereby granted a non-exclusive, worldwide, royalty-free license to use, | ||
* copy, modify, and distribute this software in source code or binary form for use | ||
* in connection with the web services and APIs provided by Facebook. | ||
* | ||
* As with any software that integrates with the Facebook platform, your use of | ||
* this software is subject to the Facebook Developer Principles and Policies | ||
* [http://developers.facebook.com/policy/]. This copyright notice shall be | ||
* included in all copies or substantial portions of the software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
*/ | ||
|
||
package com.facebook.appevents; | ||
|
||
import com.facebook.FacebookPowerMockTestCase; | ||
import com.facebook.FacebookSdk; | ||
import com.facebook.appevents.internal.AppEventUtility; | ||
import com.facebook.appevents.internal.AppEventsLoggerUtility; | ||
import com.facebook.internal.Utility; | ||
|
||
import org.json.JSONObject; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.powermock.core.classloader.annotations.PrepareForTest; | ||
import org.robolectric.RuntimeEnvironment; | ||
|
||
import java.util.concurrent.Executor; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNull; | ||
import static org.powermock.api.mockito.PowerMockito.doReturn; | ||
import static org.powermock.api.mockito.PowerMockito.mockStatic; | ||
import static org.powermock.api.mockito.PowerMockito.spy; | ||
import static org.powermock.api.mockito.PowerMockito.when; | ||
|
||
@PrepareForTest({ | ||
AppEventUtility.class, | ||
AppEventsLogger.class, | ||
FacebookSdk.class, | ||
Utility.class, | ||
}) | ||
public class AppEventsLoggerTest extends FacebookPowerMockTestCase { | ||
|
||
private final Executor executor = new FacebookSerialExecutor(); | ||
|
||
@Before | ||
public void init() throws Exception { | ||
mockStatic(FacebookSdk.class); | ||
when(FacebookSdk.isInitialized()).thenReturn(true); | ||
when(FacebookSdk.getApplicationContext()).thenReturn(RuntimeEnvironment.application); | ||
|
||
// Mock Utility class with empty stub functions, which will be called in | ||
// AppEventsLoggerUtility.getJSONObjectForGraphAPICall | ||
mockStatic(Utility.class); | ||
|
||
// Disable AppEventUtility.isMainThread since executor now runs in main thread | ||
spy(AppEventUtility.class); | ||
doReturn(false).when(AppEventUtility.class, "isMainThread"); | ||
mockStatic(AppEventsLogger.class); | ||
spy(AppEventsLogger.class); | ||
doReturn(executor).when(AppEventsLogger.class, "getAnalyticsExecutor"); | ||
} | ||
|
||
@Test | ||
public void testSetAndClearUserID() throws Exception { | ||
String userID = "12345678"; | ||
AppEventsLogger.setUserID(userID); | ||
assertEquals(AppEventsLogger.getUserID(), userID); | ||
AppEventsLogger.clearUserID(); | ||
assertNull(AppEventsLogger.getUserID()); | ||
} | ||
|
||
@Test | ||
public void testUserIDAddedToAppEvent() throws Exception { | ||
String userID = "12345678"; | ||
AppEventsLogger.setUserID(userID); | ||
JSONObject jsonObject =AppEventsLoggerUtility.getJSONObjectForGraphAPICall( | ||
AppEventsLoggerUtility.GraphAPIActivityType.MOBILE_INSTALL_EVENT, | ||
null, | ||
"123", | ||
true, | ||
FacebookSdk.getApplicationContext()); | ||
assertEquals(jsonObject.getString("app_user_id"), userID); | ||
} | ||
} |