@@ -0,0 +1,3052 @@
+// Copyright 2020 Google LLC%0A//%0A// Licensed under the Apache License, Version 2.0 (the %22License%22);%0A// you may not use this file except in compliance with the License.%0A// You may obtain a copy of the License at%0A//%0A//      http://www.apache.org/licenses/LICENSE-2.0%0A//%0A// Unless required by applicable law or agreed to in writing, software%0A// distributed under the License is distributed on an %22AS IS%22 BASIS,%0A// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A// See the License for the specific language governing permissions and%0A// limitations under the License.%0A%0Apackage com.google.firebase.crashlytics.internal.common;%0A%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.when;%0A%0Aimport android.content.Context;%0Aimport android.content.SharedPreferences;%0Aimport com.google.firebase.FirebaseApp;%0Aimport com.google.firebase.crashlytics.internal.CrashlyticsTestCase;%0Aimport java.lang.reflect.Method;%0A%0Apublic class DataCollectionArbiterTest extends CrashlyticsTestCase %7B%0A%0A  final String PREFS_NAME = CommonUtils.SHARED_PREFS_NAME;%0A%0A  public void testSetCrashlyticsDataCollectionEnabled() throws Exception %7B%0A    Context mockContext = mock(Context.class);%0A    FirebaseApp app = mock(FirebaseApp.class);%0A    when(app.getApplicationContext()).thenReturn(mockContext);%0A    when(app.isDataCollectionDefaultEnabled()).thenReturn(true);%0A    final String PREFS_NAME = CommonUtils.SHARED_PREFS_NAME;%0A    final String PREFS_KEY = %22firebase_crashlytics_collection_enabled%22;%0A    SharedPreferences.Editor mockEditor = mock(SharedPreferences.Editor.class);%0A    when(mockEditor.putBoolean(PREFS_KEY, true)).thenReturn(mockEditor);%0A    when(mockEditor.commit()).thenReturn(true);%0A    SharedPreferences mockPrefs = mock(SharedPreferences.class);%0A    when(mockPrefs.edit()).thenReturn(mockEditor);%0A    when(mockContext.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)).thenReturn(mockPrefs);%0A%0A    DataCollectionArbiter arbiter = new DataCollectionArbiter(app);%0A%0A    assertTrue(arbiter.isAutomaticDataCollectionEnabled());%0A    arbiter.setCrashlyticsDataCollectionEnabled(Boolean.FALSE);%0A    assertFalse(arbiter.isAutomaticDataCollectionEnabled());%0A    arbiter.setCrashlyticsDataCollectionEnabled(Boolean.TRUE);%0A    assertTrue(arbiter.isAutomaticDataCollectionEnabled());%0A    arbiter.setCrashlyticsDataCollectionEnabled(null);%0A    assertTrue(arbiter.isAutomaticDataCollectionEnabled());%0A  %7D%0A%0A  public void testSetCrashlyticsDataCollectionEnabled_reflection() throws Exception %7B%0A    // This test exists because the Crashlytics Unity Plugin uses reflection to access%0A    // DataCollectionArbiter#setCrashlyticsDataCollection(Boolean), which is not part of the public%0A    // API. If this test throws a NoSuchMethodException, the method signature has changed. Before%0A    // updating this test, update crashlytics_android.cc in the Unity repo to match the new method%0A    // signature.%0A    Method m =%0A        DataCollectionArbiter.class.getMethod(%22setCrashlyticsDataCollectionEnabled%22, Boolean.class);%0A    assertNotNull(m);%0A  %7D%0A%7D%0A

Add tests for Crashlytics DataCollectionArbiter (#2077)