@react-native-firebase/app 26.4.0 → 27.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/README.md +10 -27
- package/RNFBApp.podspec +13 -5
- package/android/build.gradle +3 -0
- package/android/src/main/java/io/invertase/firebase/common/RNFBHandleCollisionException.kt +29 -0
- package/android/src/main/java/io/invertase/firebase/common/RNFBHandleMap.kt +146 -0
- package/android/src/main/java/io/invertase/firebase/common/TaskExecutorService.kt +156 -0
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebaseModule.kt +44 -0
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebasePreferences.kt +100 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/NativeRNFBTurboApp.kt +250 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseApp.kt +64 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/{ReactNativeFirebaseAppInitProvider.java → ReactNativeFirebaseAppInitProvider.kt} +3 -4
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppPackage.kt +47 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.kt +33 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseVersion.java +1 -1
- package/android/src/reactnative/java/io/invertase/firebase/common/RCTConvertFirebase.kt +185 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEvent.kt +35 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitter.kt +662 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseJSON.kt +103 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseMeta.kt +96 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.kt +140 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebasePreferences.kt +109 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.kt +451 -0
- package/android/src/reactnative/java/io/invertase/firebase/interfaces/{ContextProvider.java → ContextProvider.kt} +8 -8
- package/android/src/reactnative/java/io/invertase/firebase/interfaces/{NativeError.java → NativeError.kt} +8 -8
- package/android/src/reactnative/java/io/invertase/firebase/interfaces/{NativeEvent.java → NativeEvent.kt} +6 -6
- package/android/src/reactnative/java/io/invertase/firebase/utils/NativeRNFBTurboUtils.kt +219 -0
- package/android/src/test/java/expo/core/ModuleRegistry.java +9 -0
- package/android/src/test/java/io/invertase/firebase/app/NativeRNFBTurboAppTest.java +182 -59
- package/android/src/test/java/io/invertase/firebase/app/ReactNativeFirebaseAppComponentsJavaCompatibilityTest.java +70 -0
- package/android/src/test/java/io/invertase/firebase/app/ReactNativeFirebaseAppJavaCompatibilityTest.java +60 -0
- package/android/src/test/java/io/invertase/firebase/app/ReactNativeFirebaseAppPackageTest.java +165 -0
- package/android/src/test/java/io/invertase/firebase/app/ReactNativeFirebaseAppTest.kt +167 -0
- package/android/src/test/java/io/invertase/firebase/common/RCTConvertFirebaseJavaCompatibilityTest.java +112 -0
- package/android/src/test/java/io/invertase/firebase/common/RCTConvertFirebaseTest.kt +317 -0
- package/android/src/test/java/io/invertase/firebase/common/RNFBHandleMapTest.kt +309 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitterJavaCompatibilityTest.java +176 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitterTest.java +143 -12
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseEventTest.kt +61 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseJSONJavaCompatibilityTest.java +85 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseJSONTest.kt +296 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseMetaJavaCompatibilityTest.java +67 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseMetaTest.kt +246 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseModuleTest.kt +254 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebasePreferencesJavaCompatibilityTest.java +87 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebasePreferencesTest.kt +260 -0
- package/android/src/test/java/io/invertase/firebase/common/SharedUtilsJavaCompatibilityTest.java +255 -0
- package/android/src/test/java/io/invertase/firebase/common/SharedUtilsTest.kt +674 -0
- package/android/src/test/java/io/invertase/firebase/common/TaskExecutorServiceTest.kt +290 -0
- package/android/src/test/java/io/invertase/firebase/common/UniversalFirebaseModuleJavaCompatibilityTest.java +178 -0
- package/android/src/test/java/io/invertase/firebase/common/UniversalFirebasePreferencesJavaCompatibilityTest.java +99 -0
- package/android/src/test/java/io/invertase/firebase/common/UniversalFirebasePreferencesTest.kt +217 -0
- package/android/src/test/java/io/invertase/firebase/commoncompat/ReactNativeFirebaseModuleJavaCompatibilityTest.java +176 -0
- package/android/src/test/java/io/invertase/firebase/commoncompat/ReactNativeFirebaseModuleKotlinCompatibilityTest.kt +52 -0
- package/android/src/test/java/io/invertase/firebase/interfaces/InterfacesJavaCompatibilityTest.java +144 -0
- package/android/src/test/java/io/invertase/firebase/interfaces/NativeEventTest.kt +56 -0
- package/android/src/test/java/io/invertase/firebase/utils/NativeRNFBTurboUtilsTest.java +517 -21
- package/dist/module/FirebaseApp.js +10 -0
- package/dist/module/FirebaseApp.js.map +1 -1
- package/dist/module/common/deeps.js +3 -0
- package/dist/module/common/deeps.js.map +1 -1
- package/dist/module/internal/FirebaseModule.js.map +1 -1
- package/dist/module/internal/RNFBNativeEventEmitter.js +12 -1
- package/dist/module/internal/RNFBNativeEventEmitter.js.map +1 -1
- package/dist/module/internal/SharedEventEmitter.js +3 -1
- package/dist/module/internal/SharedEventEmitter.js.map +1 -1
- package/dist/module/internal/index.js +1 -0
- package/dist/module/internal/index.js.map +1 -1
- package/dist/module/internal/registry/app.js +7 -1
- package/dist/module/internal/registry/app.js.map +1 -1
- package/dist/module/types/app.js.map +1 -1
- package/dist/module/types/internal.js +2 -0
- package/dist/module/version.js +1 -1
- package/dist/typescript/lib/FirebaseApp.d.ts +7 -0
- package/dist/typescript/lib/FirebaseApp.d.ts.map +1 -1
- package/dist/typescript/lib/common/deeps.d.ts.map +1 -1
- package/dist/typescript/lib/internal/FirebaseModule.d.ts +2 -3
- package/dist/typescript/lib/internal/FirebaseModule.d.ts.map +1 -1
- package/dist/typescript/lib/internal/NativeModules.d.ts +4 -1
- package/dist/typescript/lib/internal/NativeModules.d.ts.map +1 -1
- package/dist/typescript/lib/internal/RNFBNativeEventEmitter.d.ts +2 -2
- package/dist/typescript/lib/internal/RNFBNativeEventEmitter.d.ts.map +1 -1
- package/dist/typescript/lib/internal/SharedEventEmitter.d.ts +3 -3
- package/dist/typescript/lib/internal/SharedEventEmitter.d.ts.map +1 -1
- package/dist/typescript/lib/internal/index.d.ts +1 -0
- package/dist/typescript/lib/internal/index.d.ts.map +1 -1
- package/dist/typescript/lib/internal/registry/app.d.ts.map +1 -1
- package/dist/typescript/lib/types/app.d.ts +10 -3
- package/dist/typescript/lib/types/app.d.ts.map +1 -1
- package/dist/typescript/lib/types/internal.d.ts +12 -0
- package/dist/typescript/lib/types/internal.d.ts.map +1 -1
- package/dist/typescript/lib/version.d.ts +1 -1
- package/firebase-schema.json +4 -0
- package/firebase_spm.rb +552 -96
- package/ios/RNFBApp/RCTConvert+FIRApp.h +2 -5
- package/ios/RNFBApp/RCTConvert+FIRApp.m +11 -6
- package/ios/RNFBApp/RCTConvert+FIROptions.h +2 -5
- package/ios/RNFBApp/RCTConvert+FIROptions.m +11 -10
- package/ios/RNFBApp/RCTConvertFIRApp.swift +86 -0
- package/ios/RNFBApp/RCTConvertFIROptions.swift +259 -0
- package/ios/RNFBApp/RNFBAppCustomAuthDomains.swift +63 -0
- package/ios/RNFBApp/RNFBAppInitializeOptionsMapper.swift +113 -0
- package/ios/RNFBApp/RNFBAppLogLevelMapper.swift +53 -0
- package/ios/RNFBApp/RNFBAppModule+CustomAuthDomain.m +35 -0
- package/ios/RNFBApp/RNFBAppModule.h +6 -2
- package/ios/RNFBApp/RNFBAppModule.mm +65 -228
- package/ios/RNFBApp/RNFBAppModuleFirebase.swift +439 -0
- package/ios/RNFBApp/RNFBAppModuleImplementation.h +68 -0
- package/ios/RNFBApp/RNFBAppModuleImplementation.m +195 -0
- package/ios/RNFBApp/RNFBHandleMap.m +27 -56
- package/ios/RNFBApp/RNFBHandleMapStorage.swift +90 -0
- package/ios/RNFBApp/RNFBInitializeAppArguments.swift +82 -0
- package/ios/RNFBApp/RNFBJSON.m +22 -38
- package/ios/RNFBApp/RNFBJSONImplementation.swift +71 -0
- package/ios/RNFBApp/RNFBMeta.m +24 -26
- package/ios/RNFBApp/RNFBMetaStorage.swift +76 -0
- package/ios/RNFBApp/RNFBNullSentinelDecoding.swift +135 -0
- package/ios/RNFBApp/RNFBNullSentinelInterceptor.h +30 -3
- package/ios/RNFBApp/RNFBNullSentinelInterceptor.m +28 -5
- package/ios/RNFBApp/RNFBPreferences.m +22 -20
- package/ios/RNFBApp/RNFBPreferencesStorage.swift +101 -0
- package/ios/RNFBApp/RNFBRCTEventEmitter.m +36 -93
- package/ios/RNFBApp/RNFBRCTEventEmitterCore.swift +161 -0
- package/ios/RNFBApp/RNFBSharedUtils.h +2 -5
- package/ios/RNFBApp/RNFBSharedUtils.m +109 -198
- package/ios/RNFBApp/RNFBSharedUtilsConfig.swift +72 -0
- package/ios/RNFBApp/RNFBSharedUtilsFIRApp.swift +271 -0
- package/ios/RNFBApp/RNFBSharedUtilsFormatting.swift +59 -0
- package/ios/RNFBApp/RNFBSharedUtilsPromiseRejection.swift +88 -0
- package/ios/RNFBApp/RNFBUtilsHelpers.swift +116 -0
- package/ios/RNFBApp/RNFBUtilsModule+Foundation.m +44 -0
- package/ios/RNFBApp/RNFBUtilsModule+PhotoAssets.m +47 -0
- package/ios/RNFBApp/RNFBUtilsModule.h +11 -1
- package/ios/RNFBApp/RNFBUtilsModule.mm +10 -85
- package/ios/RNFBApp/RNFBUtilsModuleImplementation.h +32 -0
- package/ios/RNFBApp/RNFBUtilsModuleImplementation.m +56 -0
- package/ios/RNFBApp/RNFBVersion.m +1 -1
- package/ios/RNFBApp.xcodeproj/project.pbxproj +100 -0
- package/ios/RNFBAppUnitTests/HostStubs/FirebaseCore/FIRApp.m +171 -0
- package/ios/RNFBAppUnitTests/HostStubs/FirebaseCore/FirebaseCore.h +78 -0
- package/ios/RNFBAppUnitTests/HostStubs/FirebaseInstallations/FIRInstallations.m +7 -0
- package/ios/RNFBAppUnitTests/HostStubs/FirebaseInstallations/FirebaseInstallations.h +8 -0
- package/ios/RNFBAppUnitTests/HostStubs/RNFBAppModuleHostStub.m +55 -0
- package/ios/RNFBAppUnitTests/HostStubs/RNFBAppTurboModules.h +89 -0
- package/ios/RNFBAppUnitTests/HostStubs/RNFBAppTurboModules.mm +30 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTBridge.h +19 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTBridge.m +32 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTBridgeModule.h +19 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTConvert.h +28 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTConvert.m +23 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTEventEmitter.h +9 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTInvalidating.h +24 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTUtils.h +9 -0
- package/ios/RNFBAppUnitTests/HostStubs/module.modulemap +13 -0
- package/ios/RNFBAppUnitTests/RCTConvertFIRAppFacadeTests.m +61 -0
- package/ios/RNFBAppUnitTests/RCTConvertFIRAppTests.swift +73 -0
- package/ios/RNFBAppUnitTests/RCTConvertFIROptionsFacadeTests.m +57 -0
- package/ios/RNFBAppUnitTests/RCTConvertFIROptionsTests.swift +243 -0
- package/ios/RNFBAppUnitTests/RNFBAppCustomAuthDomainsFacadeTests.m +73 -0
- package/ios/RNFBAppUnitTests/RNFBAppCustomAuthDomainsTests.swift +70 -0
- package/ios/RNFBAppUnitTests/RNFBAppInitializeOptionsMapperTests.swift +190 -0
- package/ios/RNFBAppUnitTests/RNFBAppLogLevelFacadeTests.m +76 -0
- package/ios/RNFBAppUnitTests/RNFBAppLogLevelMapperTests.swift +59 -0
- package/ios/RNFBAppUnitTests/RNFBAppModuleFirebaseFacadeTests.m +215 -0
- package/ios/RNFBAppUnitTests/RNFBAppModuleFirebaseTests.swift +430 -0
- package/ios/RNFBAppUnitTests/RNFBAppModuleLifecycleTests.m +206 -0
- package/ios/RNFBAppUnitTests/RNFBAppModuleShellTests.mm +367 -0
- package/ios/RNFBAppUnitTests/RNFBAppUnitTests.xcodeproj/project.pbxproj +355 -2
- package/ios/RNFBAppUnitTests/RNFBFirebaseAppClientTests.swift +165 -0
- package/ios/RNFBAppUnitTests/RNFBHandleMapStorageTests.swift +121 -0
- package/ios/RNFBAppUnitTests/RNFBInitializeAppArgumentsTests.swift +256 -0
- package/ios/RNFBAppUnitTests/RNFBJSONImplementationTests.swift +126 -0
- package/ios/RNFBAppUnitTests/RNFBJSONTests.m +172 -0
- package/ios/RNFBAppUnitTests/RNFBMetaStorageTests.swift +106 -0
- package/ios/RNFBAppUnitTests/RNFBMetaTests.m +65 -0
- package/ios/RNFBAppUnitTests/RNFBNullSentinelDecodingTests.swift +286 -0
- package/ios/RNFBAppUnitTests/RNFBNullSentinelInterceptorTests.m +312 -0
- package/ios/RNFBAppUnitTests/RNFBPreferencesStorageTests.swift +105 -0
- package/ios/RNFBAppUnitTests/RNFBPreferencesTests.m +110 -0
- package/ios/RNFBAppUnitTests/RNFBRCTEventEmitterCoreTests.swift +163 -0
- package/ios/RNFBAppUnitTests/RNFBRCTEventEmitterFacadeTests.m +141 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsConfigFacadeTests.m +100 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsConfigTests.swift +234 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsFIRAppFacadeTests.m +145 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsFIRAppTests.swift +173 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsFormattingFacadeTests.m +38 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsFormattingTests.swift +82 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsNullSentinelTests.m +35 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsPromiseRejectionFacadeTests.m +107 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsPromiseRejectionTests.swift +133 -0
- package/ios/RNFBAppUnitTests/RNFBUtilsHelpersTests.swift +144 -0
- package/ios/RNFBAppUnitTests/RNFBUtilsModuleFacadeTests.m +72 -0
- package/ios/RNFBAppUnitTests/RNFBUtilsModuleShellTests.mm +282 -0
- package/ios/RNFBFirebase/Package.swift +53 -0
- package/ios/RNFBFirebase/Sources/RNFBFirebase/RNFBFirebase.swift +285 -0
- package/ios/RNFBFirebase/Sources/RNFBFirebaseBridge/Public/.gitkeep +0 -0
- package/ios/RNFBFirebase/Sources/RNFBFirebaseBridge/RNFBFirebaseBridge.m +169 -0
- package/ios/RNFBFirebase/Sources/RNFBFirebaseBridge/include/RNFBFirebaseBridge.h +52 -0
- package/ios/RNFBFirebaseUnitTests/RNFBAppDynamicFacadeTests.swift +240 -0
- package/{android/src/main/java/io/invertase/firebase/common/RNFBHandleCollisionException.java → ios/RNFBFirebaseUnitTests/RNFBFirebaseClientImport.swift} +23 -14
- package/ios/RNFBFirebaseUnitTests/RNFBFirebaseUnitTests.xcodeproj/project.pbxproj +588 -0
- package/ios/RNFBFirebaseUnitTests/RNFBFirebaseUnitTests.xcodeproj/xcshareddata/xcschemes/RNFBFirebaseUnitTests.xcscheme +83 -0
- package/ios_config.sh +50 -22
- package/lib/FirebaseApp.ts +10 -0
- package/lib/common/deeps.ts +3 -0
- package/lib/internal/FirebaseModule.ts +6 -3
- package/lib/internal/NativeModules.ts +4 -1
- package/lib/internal/RNFBNativeEventEmitter.ts +14 -5
- package/lib/internal/SharedEventEmitter.ts +5 -1
- package/lib/internal/index.ts +1 -0
- package/lib/internal/react-native-vendor-emitter.d.ts +11 -0
- package/lib/internal/registry/app.ts +7 -1
- package/lib/types/app.ts +10 -3
- package/lib/types/internal.ts +19 -0
- package/lib/version.ts +1 -1
- package/package.json +8 -8
- package/plugin/build/ios/appDelegate.js +2 -2
- package/plugin/build/ios/podfile.js +16 -16
- package/plugin/build/pluginConfig.d.ts +4 -2
- package/plugin/src/ios/appDelegate.ts +2 -2
- package/plugin/src/ios/podfile.ts +20 -23
- package/plugin/src/pluginConfig.ts +4 -2
- package/android/src/main/java/io/invertase/firebase/common/RNFBHandleMap.java +0 -150
- package/android/src/main/java/io/invertase/firebase/common/TaskExecutorService.java +0 -148
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebaseModule.java +0 -62
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebasePreferences.java +0 -91
- package/android/src/reactnative/java/io/invertase/firebase/app/NativeRNFBTurboApp.java +0 -224
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseApp.java +0 -46
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppPackage.java +0 -49
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.java +0 -35
- package/android/src/reactnative/java/io/invertase/firebase/common/RCTConvertFirebase.java +0 -192
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEvent.java +0 -53
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitter.java +0 -606
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseJSON.java +0 -109
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseMeta.java +0 -101
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.java +0 -146
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebasePreferences.java +0 -96
- package/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java +0 -441
- package/android/src/reactnative/java/io/invertase/firebase/utils/NativeRNFBTurboUtils.java +0 -223
- package/android/src/test/java/io/invertase/firebase/common/RNFBHandleMapTest.java +0 -275
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseJSONTest.java +0 -108
- package/android/src/test/java/io/invertase/firebase/common/TaskExecutorServiceTest.java +0 -97
package/android/src/test/java/io/invertase/firebase/common/UniversalFirebasePreferencesTest.kt
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
package io.invertase.firebase.common
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import android.content.Context
|
|
20
|
+
import android.content.SharedPreferences
|
|
21
|
+
import android.util.Log
|
|
22
|
+
import io.invertase.firebase.app.ReactNativeFirebaseApp
|
|
23
|
+
import org.junit.Assert.assertEquals
|
|
24
|
+
import org.junit.Assert.assertFalse
|
|
25
|
+
import org.junit.Assert.assertSame
|
|
26
|
+
import org.junit.Assert.assertTrue
|
|
27
|
+
import org.junit.Test
|
|
28
|
+
import org.mockito.Mockito.mock
|
|
29
|
+
import org.mockito.Mockito.mockStatic
|
|
30
|
+
import org.mockito.Mockito.never
|
|
31
|
+
import org.mockito.Mockito.times
|
|
32
|
+
import org.mockito.Mockito.verify
|
|
33
|
+
import org.mockito.Mockito.verifyNoMoreInteractions
|
|
34
|
+
import org.mockito.Mockito.`when`
|
|
35
|
+
import java.lang.reflect.Modifier
|
|
36
|
+
|
|
37
|
+
/** Plain JUnit4 + Mockito coverage for universal preferences (AndroidTest-AD-1). */
|
|
38
|
+
class UniversalFirebasePreferencesTest {
|
|
39
|
+
@Test
|
|
40
|
+
fun javaVisibleApiPreservesConstructorSingletonAndExactMethodTypes() {
|
|
41
|
+
val preferencesClass = UniversalFirebasePreferences::class.java
|
|
42
|
+
val constructor = preferencesClass.getConstructor()
|
|
43
|
+
val sharedInstanceMethod = preferencesClass.getMethod("getSharedInstance")
|
|
44
|
+
|
|
45
|
+
assertTrue(Modifier.isPublic(constructor.modifiers))
|
|
46
|
+
assertFalse(Modifier.isFinal(preferencesClass.modifiers))
|
|
47
|
+
assertTrue(Modifier.isStatic(sharedInstanceMethod.modifiers))
|
|
48
|
+
assertEquals(preferencesClass, sharedInstanceMethod.returnType)
|
|
49
|
+
assertSame(
|
|
50
|
+
UniversalFirebasePreferences.getSharedInstance(),
|
|
51
|
+
UniversalFirebasePreferences.getSharedInstance(),
|
|
52
|
+
)
|
|
53
|
+
assertEquals(
|
|
54
|
+
Boolean::class.javaPrimitiveType,
|
|
55
|
+
preferencesClass.getMethod("contains", String::class.java).returnType,
|
|
56
|
+
)
|
|
57
|
+
assertEquals(
|
|
58
|
+
Void.TYPE,
|
|
59
|
+
preferencesClass
|
|
60
|
+
.getMethod("setBooleanValue", String::class.java, Boolean::class.javaPrimitiveType)
|
|
61
|
+
.returnType,
|
|
62
|
+
)
|
|
63
|
+
assertEquals(
|
|
64
|
+
Boolean::class.javaPrimitiveType,
|
|
65
|
+
preferencesClass
|
|
66
|
+
.getMethod("getBooleanValue", String::class.java, Boolean::class.javaPrimitiveType)
|
|
67
|
+
.returnType,
|
|
68
|
+
)
|
|
69
|
+
assertEquals(
|
|
70
|
+
Void.TYPE,
|
|
71
|
+
preferencesClass
|
|
72
|
+
.getMethod("setIntValue", String::class.java, Int::class.javaPrimitiveType)
|
|
73
|
+
.returnType,
|
|
74
|
+
)
|
|
75
|
+
assertEquals(
|
|
76
|
+
Int::class.javaPrimitiveType,
|
|
77
|
+
preferencesClass
|
|
78
|
+
.getMethod("getIntValue", String::class.java, Int::class.javaPrimitiveType)
|
|
79
|
+
.returnType,
|
|
80
|
+
)
|
|
81
|
+
assertEquals(
|
|
82
|
+
Void.TYPE,
|
|
83
|
+
preferencesClass
|
|
84
|
+
.getMethod("setLongValue", String::class.java, Long::class.javaPrimitiveType)
|
|
85
|
+
.returnType,
|
|
86
|
+
)
|
|
87
|
+
assertEquals(
|
|
88
|
+
Long::class.javaPrimitiveType,
|
|
89
|
+
preferencesClass
|
|
90
|
+
.getMethod("getLongValue", String::class.java, Long::class.javaPrimitiveType)
|
|
91
|
+
.returnType,
|
|
92
|
+
)
|
|
93
|
+
assertEquals(
|
|
94
|
+
Void.TYPE,
|
|
95
|
+
preferencesClass
|
|
96
|
+
.getMethod("setStringValue", String::class.java, String::class.java)
|
|
97
|
+
.returnType,
|
|
98
|
+
)
|
|
99
|
+
assertEquals(
|
|
100
|
+
String::class.java,
|
|
101
|
+
preferencesClass
|
|
102
|
+
.getMethod("getStringValue", String::class.java, String::class.java)
|
|
103
|
+
.returnType,
|
|
104
|
+
)
|
|
105
|
+
assertEquals(Void.TYPE, preferencesClass.getMethod("clearAll").returnType)
|
|
106
|
+
assertEquals(
|
|
107
|
+
SharedPreferences.Editor::class.java,
|
|
108
|
+
preferencesClass.getMethod("remove", String::class.java).returnType,
|
|
109
|
+
)
|
|
110
|
+
preferencesClass.declaredMethods
|
|
111
|
+
.filterNot { Modifier.isStatic(it.modifiers) || Modifier.isPrivate(it.modifiers) }
|
|
112
|
+
.forEach { method ->
|
|
113
|
+
assertFalse("${method.name} must remain overridable", Modifier.isFinal(method.modifiers))
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@Test
|
|
118
|
+
fun lazyPreferencesUseApplicationContextFileAndModeOnce() {
|
|
119
|
+
val preferences = mock(SharedPreferences::class.java)
|
|
120
|
+
val applicationContext = mock(Context::class.java)
|
|
121
|
+
`when`(
|
|
122
|
+
applicationContext.getSharedPreferences("io.invertase.firebase", Context.MODE_PRIVATE),
|
|
123
|
+
).thenReturn(preferences)
|
|
124
|
+
`when`(preferences.contains("present")).thenReturn(true)
|
|
125
|
+
|
|
126
|
+
val previous: Context? = ReactNativeFirebaseApp.getApplicationContext()
|
|
127
|
+
mockStatic(Log::class.java).use {
|
|
128
|
+
ReactNativeFirebaseApp.setApplicationContext(applicationContext)
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
val subject = UniversalFirebasePreferences()
|
|
132
|
+
|
|
133
|
+
assertTrue(subject.contains("present"))
|
|
134
|
+
assertTrue(subject.contains("present"))
|
|
135
|
+
|
|
136
|
+
verify(applicationContext, times(1))
|
|
137
|
+
.getSharedPreferences("io.invertase.firebase", Context.MODE_PRIVATE)
|
|
138
|
+
verify(preferences, times(2)).contains("present")
|
|
139
|
+
} finally {
|
|
140
|
+
mockStatic(Log::class.java).use {
|
|
141
|
+
ReactNativeFirebaseApp.setApplicationContext(previous)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
@Test
|
|
147
|
+
fun scalarGettersDelegateAndReturnStoredValues() {
|
|
148
|
+
val preferences = mock(SharedPreferences::class.java)
|
|
149
|
+
val subject = subjectWith(preferences)
|
|
150
|
+
`when`(preferences.contains("present")).thenReturn(true)
|
|
151
|
+
`when`(preferences.contains("missing")).thenReturn(false)
|
|
152
|
+
`when`(preferences.getBoolean("boolean", false)).thenReturn(true)
|
|
153
|
+
`when`(preferences.getInt("integer", 0)).thenReturn(42)
|
|
154
|
+
`when`(preferences.getLong("long", 0L)).thenReturn(4_294_967_296L)
|
|
155
|
+
`when`(preferences.getString("string", "fallback")).thenReturn("value")
|
|
156
|
+
|
|
157
|
+
assertTrue(subject.contains("present"))
|
|
158
|
+
assertFalse(subject.contains("missing"))
|
|
159
|
+
assertTrue(subject.getBooleanValue("boolean", false))
|
|
160
|
+
assertEquals(42, subject.getIntValue("integer", 0))
|
|
161
|
+
assertEquals(4_294_967_296L, subject.getLongValue("long", 0L))
|
|
162
|
+
assertEquals("value", subject.getStringValue("string", "fallback"))
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
@Test
|
|
166
|
+
fun scalarSettersAndClearApplyAsynchronously() {
|
|
167
|
+
val preferences = mock(SharedPreferences::class.java)
|
|
168
|
+
val editor = mock(SharedPreferences.Editor::class.java)
|
|
169
|
+
val subject = subjectWith(preferences)
|
|
170
|
+
`when`(preferences.edit()).thenReturn(editor)
|
|
171
|
+
`when`(editor.putBoolean("boolean", true)).thenReturn(editor)
|
|
172
|
+
`when`(editor.putInt("integer", 42)).thenReturn(editor)
|
|
173
|
+
`when`(editor.putLong("long", 4_294_967_296L)).thenReturn(editor)
|
|
174
|
+
`when`(editor.putString("string", "value")).thenReturn(editor)
|
|
175
|
+
`when`(editor.clear()).thenReturn(editor)
|
|
176
|
+
|
|
177
|
+
subject.setBooleanValue("boolean", true)
|
|
178
|
+
subject.setIntValue("integer", 42)
|
|
179
|
+
subject.setLongValue("long", 4_294_967_296L)
|
|
180
|
+
subject.setStringValue("string", "value")
|
|
181
|
+
subject.clearAll()
|
|
182
|
+
|
|
183
|
+
verify(editor).putBoolean("boolean", true)
|
|
184
|
+
verify(editor).putInt("integer", 42)
|
|
185
|
+
verify(editor).putLong("long", 4_294_967_296L)
|
|
186
|
+
verify(editor).putString("string", "value")
|
|
187
|
+
verify(editor).clear()
|
|
188
|
+
verify(editor, times(5)).apply()
|
|
189
|
+
verify(editor, never()).commit()
|
|
190
|
+
verifyNoMoreInteractions(editor)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
@Test
|
|
194
|
+
fun removeReturnsEditorWithoutApplyingOrCommitting() {
|
|
195
|
+
val preferences = mock(SharedPreferences::class.java)
|
|
196
|
+
val editor = mock(SharedPreferences.Editor::class.java)
|
|
197
|
+
val subject = subjectWith(preferences)
|
|
198
|
+
`when`(preferences.edit()).thenReturn(editor)
|
|
199
|
+
`when`(editor.remove("obsolete")).thenReturn(editor)
|
|
200
|
+
|
|
201
|
+
assertSame(editor, subject.remove("obsolete"))
|
|
202
|
+
|
|
203
|
+
verify(preferences).edit()
|
|
204
|
+
verify(editor).remove("obsolete")
|
|
205
|
+
verify(editor, never()).apply()
|
|
206
|
+
verify(editor, never()).commit()
|
|
207
|
+
verifyNoMoreInteractions(editor)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
private fun subjectWith(preferences: SharedPreferences): UniversalFirebasePreferences {
|
|
211
|
+
val subject = UniversalFirebasePreferences()
|
|
212
|
+
val field = UniversalFirebasePreferences::class.java.getDeclaredField("preferences")
|
|
213
|
+
field.isAccessible = true
|
|
214
|
+
field.set(subject, preferences)
|
|
215
|
+
return subject
|
|
216
|
+
}
|
|
217
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
package io.invertase.firebase.commoncompat;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import static org.junit.Assert.assertEquals;
|
|
20
|
+
import static org.junit.Assert.assertFalse;
|
|
21
|
+
import static org.junit.Assert.assertTrue;
|
|
22
|
+
import static org.mockito.Mockito.mock;
|
|
23
|
+
import static org.mockito.Mockito.mockStatic;
|
|
24
|
+
import static org.mockito.Mockito.verify;
|
|
25
|
+
import static org.mockito.Mockito.when;
|
|
26
|
+
|
|
27
|
+
import com.facebook.react.bridge.Arguments;
|
|
28
|
+
import com.facebook.react.bridge.Promise;
|
|
29
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
30
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
31
|
+
import com.facebook.react.bridge.WritableMap;
|
|
32
|
+
import io.invertase.firebase.common.ReactNativeFirebaseModule;
|
|
33
|
+
import java.lang.reflect.Constructor;
|
|
34
|
+
import java.lang.reflect.Method;
|
|
35
|
+
import java.lang.reflect.Modifier;
|
|
36
|
+
import java.lang.reflect.ParameterizedType;
|
|
37
|
+
import java.util.Map;
|
|
38
|
+
import java.util.concurrent.ExecutorService;
|
|
39
|
+
import org.junit.Test;
|
|
40
|
+
import org.mockito.MockedStatic;
|
|
41
|
+
|
|
42
|
+
/** Compile-time and reflection contract for external Java subclasses and callers. */
|
|
43
|
+
public class ReactNativeFirebaseModuleJavaCompatibilityTest {
|
|
44
|
+
@Test
|
|
45
|
+
public void outerClassPreservesConstructorsMethodsAndModifiers() throws Exception {
|
|
46
|
+
assertTrue(Modifier.isPublic(ReactNativeFirebaseModule.class.getModifiers()));
|
|
47
|
+
assertFalse(Modifier.isFinal(ReactNativeFirebaseModule.class.getModifiers()));
|
|
48
|
+
|
|
49
|
+
Constructor<ReactNativeFirebaseModule> constructor =
|
|
50
|
+
ReactNativeFirebaseModule.class.getConstructor(ReactApplicationContext.class, String.class);
|
|
51
|
+
assertTrue(Modifier.isPublic(constructor.getModifiers()));
|
|
52
|
+
|
|
53
|
+
assertOpen("initialize");
|
|
54
|
+
assertOpen("invalidate");
|
|
55
|
+
assertOpen("onCatalystInstanceDestroy");
|
|
56
|
+
assertOpen("getName");
|
|
57
|
+
assertOpen("getConstants");
|
|
58
|
+
assertFinal("getExecutor");
|
|
59
|
+
assertFinal("getTransactionalExecutor");
|
|
60
|
+
assertFinal("getTransactionalExecutor", String.class);
|
|
61
|
+
assertFinal("removeEventListeningExecutor", String.class);
|
|
62
|
+
|
|
63
|
+
assertTrue(
|
|
64
|
+
ReactNativeFirebaseModule.class
|
|
65
|
+
.getMethod("onCatalystInstanceDestroy")
|
|
66
|
+
.isAnnotationPresent(Deprecated.class));
|
|
67
|
+
|
|
68
|
+
Method constants = ReactNativeFirebaseModule.class.getMethod("getConstants");
|
|
69
|
+
assertEquals(Map.class, constants.getReturnType());
|
|
70
|
+
ParameterizedType genericReturn = (ParameterizedType) constants.getGenericReturnType();
|
|
71
|
+
assertEquals(String.class, genericReturn.getActualTypeArguments()[0]);
|
|
72
|
+
assertEquals(Object.class, genericReturn.getActualTypeArguments()[1]);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Test
|
|
76
|
+
public void staticHelperDescriptorsRemainJavaCallable() throws Exception {
|
|
77
|
+
assertStatic("rejectPromiseWithExceptionMap", Promise.class, Exception.class);
|
|
78
|
+
assertStatic("rejectPromiseWithCodeAndMessage", Promise.class, String.class, String.class);
|
|
79
|
+
assertStatic(
|
|
80
|
+
"rejectPromiseWithCodeAndMessage",
|
|
81
|
+
Promise.class,
|
|
82
|
+
String.class,
|
|
83
|
+
String.class,
|
|
84
|
+
ReadableMap.class);
|
|
85
|
+
assertStatic(
|
|
86
|
+
"rejectPromiseWithCodeAndMessage", Promise.class, String.class, String.class, String.class);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@Test
|
|
90
|
+
public void staticOuterHelpersExecuteFromJava() {
|
|
91
|
+
Promise promise = mock(Promise.class);
|
|
92
|
+
WritableMap map = mock(WritableMap.class);
|
|
93
|
+
ReadableMap resolver = mock(ReadableMap.class);
|
|
94
|
+
try (MockedStatic<Arguments> arguments = mockStatic(Arguments.class)) {
|
|
95
|
+
when(Arguments.createMap()).thenReturn(map);
|
|
96
|
+
|
|
97
|
+
ReactNativeFirebaseModule.rejectPromiseWithCodeAndMessage(
|
|
98
|
+
promise, "resolver-code", "message", resolver);
|
|
99
|
+
ReactNativeFirebaseModule.rejectPromiseWithCodeAndMessage(promise, "plain-code", "message");
|
|
100
|
+
ReactNativeFirebaseModule.rejectPromiseWithCodeAndMessage(
|
|
101
|
+
promise, "native-code", "message", "native");
|
|
102
|
+
|
|
103
|
+
verify(promise).reject("resolver-code", "message", map);
|
|
104
|
+
verify(promise).reject("plain-code", "message", map);
|
|
105
|
+
verify(promise).reject("native-code", "message", map);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
Exception exception = new Exception("failure");
|
|
109
|
+
try (MockedStatic<Arguments> arguments = mockStatic(Arguments.class)) {
|
|
110
|
+
when(Arguments.createMap()).thenReturn(map);
|
|
111
|
+
|
|
112
|
+
ReactNativeFirebaseModule.rejectPromiseWithExceptionMap(promise, exception);
|
|
113
|
+
|
|
114
|
+
verify(promise).reject(exception, map);
|
|
115
|
+
verify(map).putString("code", "unknown");
|
|
116
|
+
verify(map).putString("nativeErrorCode", "unknown");
|
|
117
|
+
verify(map).putString("message", "failure");
|
|
118
|
+
verify(map).putString("nativeErrorMessage", "failure");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@SuppressWarnings({"deprecation", "removal"})
|
|
123
|
+
private static final class ExternalJavaModule extends ReactNativeFirebaseModule {
|
|
124
|
+
ExternalJavaModule(ReactApplicationContext reactContext) {
|
|
125
|
+
super(reactContext, null);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@Override
|
|
129
|
+
public void initialize() {
|
|
130
|
+
super.initialize();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
@Override
|
|
134
|
+
public void invalidate() {
|
|
135
|
+
super.invalidate();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@Override
|
|
139
|
+
public void onCatalystInstanceDestroy() {
|
|
140
|
+
super.onCatalystInstanceDestroy();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@Override
|
|
144
|
+
public String getName() {
|
|
145
|
+
return "ExternalJavaModule";
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@Override
|
|
149
|
+
public Map<String, Object> getConstants() {
|
|
150
|
+
return super.getConstants();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
ExecutorService executor(String identifier) {
|
|
154
|
+
return getTransactionalExecutor(identifier);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private static void assertOpen(String name, Class<?>... parameterTypes) throws Exception {
|
|
159
|
+
Method method = ReactNativeFirebaseModule.class.getMethod(name, parameterTypes);
|
|
160
|
+
assertTrue(Modifier.isPublic(method.getModifiers()));
|
|
161
|
+
assertFalse(Modifier.isFinal(method.getModifiers()));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private static void assertFinal(String name, Class<?>... parameterTypes) throws Exception {
|
|
165
|
+
Method method = ReactNativeFirebaseModule.class.getMethod(name, parameterTypes);
|
|
166
|
+
assertTrue(Modifier.isPublic(method.getModifiers()));
|
|
167
|
+
assertTrue(Modifier.isFinal(method.getModifiers()));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private static void assertStatic(String name, Class<?>... parameterTypes) throws Exception {
|
|
171
|
+
Method method = ReactNativeFirebaseModule.class.getMethod(name, parameterTypes);
|
|
172
|
+
assertTrue(Modifier.isPublic(method.getModifiers()));
|
|
173
|
+
assertTrue(Modifier.isStatic(method.getModifiers()));
|
|
174
|
+
assertEquals(void.class, method.getReturnType());
|
|
175
|
+
}
|
|
176
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
package io.invertase.firebase.commoncompat
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
20
|
+
import io.invertase.firebase.common.ReactNativeFirebaseModule
|
|
21
|
+
import org.junit.Assert.assertFalse
|
|
22
|
+
import org.junit.Test
|
|
23
|
+
import java.lang.reflect.Modifier
|
|
24
|
+
|
|
25
|
+
/** Compile-time contract for a Kotlin subclass outside the production package. */
|
|
26
|
+
class ReactNativeFirebaseModuleKotlinCompatibilityTest {
|
|
27
|
+
@Test
|
|
28
|
+
fun externalKotlinSubclassCanOverrideJavaVirtualSurface() {
|
|
29
|
+
assertFalse(Modifier.isFinal(ExternalKotlinModule::class.java.modifiers))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private open class ExternalKotlinModule(
|
|
33
|
+
reactContext: ReactApplicationContext?,
|
|
34
|
+
) : ReactNativeFirebaseModule(reactContext, null) {
|
|
35
|
+
override fun initialize() {
|
|
36
|
+
super.initialize()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
override fun invalidate() {
|
|
40
|
+
super.invalidate()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Suppress("DEPRECATION")
|
|
44
|
+
override fun onCatalystInstanceDestroy() {
|
|
45
|
+
super.onCatalystInstanceDestroy()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
override fun getName(): String = "ExternalKotlinModule"
|
|
49
|
+
|
|
50
|
+
override fun getConstants(): MutableMap<String, Any> = super.getConstants()
|
|
51
|
+
}
|
|
52
|
+
}
|
package/android/src/test/java/io/invertase/firebase/interfaces/InterfacesJavaCompatibilityTest.java
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
package io.invertase.firebase.interfaces;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import static org.junit.Assert.assertEquals;
|
|
21
|
+
import static org.junit.Assert.assertNull;
|
|
22
|
+
import static org.junit.Assert.assertTrue;
|
|
23
|
+
|
|
24
|
+
import android.app.Activity;
|
|
25
|
+
import android.content.Context;
|
|
26
|
+
import com.facebook.react.bridge.ReactContext;
|
|
27
|
+
import com.facebook.react.bridge.WritableMap;
|
|
28
|
+
import java.lang.reflect.Method;
|
|
29
|
+
import java.lang.reflect.Modifier;
|
|
30
|
+
import java.util.Arrays;
|
|
31
|
+
import java.util.Map;
|
|
32
|
+
import java.util.function.Function;
|
|
33
|
+
import java.util.stream.Collectors;
|
|
34
|
+
import org.junit.Test;
|
|
35
|
+
|
|
36
|
+
public class InterfacesJavaCompatibilityTest {
|
|
37
|
+
@Test
|
|
38
|
+
public void contextProvider_preservesExactAbstractGetterApi() {
|
|
39
|
+
Map<String, Method> methods = declaredMethods(ContextProvider.class);
|
|
40
|
+
|
|
41
|
+
assertEquals(
|
|
42
|
+
Arrays.asList("getActivity", "getApplicationContext", "getContext"),
|
|
43
|
+
methods.keySet().stream().sorted().collect(Collectors.toList()));
|
|
44
|
+
assertGetter(methods.get("getActivity"), Activity.class);
|
|
45
|
+
assertGetter(methods.get("getContext"), ReactContext.class);
|
|
46
|
+
assertGetter(methods.get("getApplicationContext"), Context.class);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Test
|
|
50
|
+
public void nativeError_preservesExactAbstractGetterApi() {
|
|
51
|
+
Map<String, Method> methods = declaredMethods(NativeError.class);
|
|
52
|
+
|
|
53
|
+
assertEquals(
|
|
54
|
+
Arrays.asList(
|
|
55
|
+
"getErrorCode",
|
|
56
|
+
"getErrorMessage",
|
|
57
|
+
"getFirebaseAppName",
|
|
58
|
+
"getFirebaseServiceName",
|
|
59
|
+
"getUserInfo"),
|
|
60
|
+
methods.keySet().stream().sorted().collect(Collectors.toList()));
|
|
61
|
+
assertGetter(methods.get("getErrorCode"), String.class);
|
|
62
|
+
assertGetter(methods.get("getErrorMessage"), String.class);
|
|
63
|
+
assertGetter(methods.get("getFirebaseAppName"), String.class);
|
|
64
|
+
assertGetter(methods.get("getFirebaseServiceName"), String.class);
|
|
65
|
+
assertGetter(methods.get("getUserInfo"), WritableMap.class);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@Test
|
|
69
|
+
public void javaCanImplementAndCallContextProviderWithNulls() {
|
|
70
|
+
ContextProvider provider =
|
|
71
|
+
new ContextProvider() {
|
|
72
|
+
@Override
|
|
73
|
+
public Activity getActivity() {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@Override
|
|
78
|
+
public ReactContext getContext() {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@Override
|
|
83
|
+
public Context getApplicationContext() {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
assertNull(provider.getActivity());
|
|
89
|
+
assertNull(provider.getContext());
|
|
90
|
+
assertNull(provider.getApplicationContext());
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@Test
|
|
94
|
+
public void javaCanImplementAndCallNativeErrorWithNulls() {
|
|
95
|
+
NativeError error =
|
|
96
|
+
new NativeError() {
|
|
97
|
+
@Override
|
|
98
|
+
public String getErrorCode() {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@Override
|
|
103
|
+
public String getErrorMessage() {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
@Override
|
|
108
|
+
public String getFirebaseAppName() {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@Override
|
|
113
|
+
public String getFirebaseServiceName() {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@Override
|
|
118
|
+
public WritableMap getUserInfo() {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
assertNull(error.getErrorCode());
|
|
124
|
+
assertNull(error.getErrorMessage());
|
|
125
|
+
assertNull(error.getFirebaseAppName());
|
|
126
|
+
assertNull(error.getFirebaseServiceName());
|
|
127
|
+
assertNull(error.getUserInfo());
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
private static Map<String, Method> declaredMethods(Class<?> interfaceClass) {
|
|
131
|
+
assertTrue(interfaceClass.isInterface());
|
|
132
|
+
assertTrue(Modifier.isPublic(interfaceClass.getModifiers()));
|
|
133
|
+
assertTrue(Modifier.isAbstract(interfaceClass.getModifiers()));
|
|
134
|
+
return Arrays.stream(interfaceClass.getDeclaredMethods())
|
|
135
|
+
.collect(Collectors.toMap(Method::getName, Function.identity()));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private static void assertGetter(Method method, Class<?> returnType) {
|
|
139
|
+
assertEquals(returnType, method.getReturnType());
|
|
140
|
+
assertEquals(0, method.getParameterCount());
|
|
141
|
+
assertTrue(Modifier.isPublic(method.getModifiers()));
|
|
142
|
+
assertTrue(Modifier.isAbstract(method.getModifiers()));
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
package io.invertase.firebase.interfaces
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import com.facebook.react.bridge.WritableMap
|
|
21
|
+
import org.junit.Assert.assertEquals
|
|
22
|
+
import org.junit.Assert.assertNull
|
|
23
|
+
import org.junit.Assert.assertTrue
|
|
24
|
+
import org.junit.Test
|
|
25
|
+
import java.lang.reflect.Modifier
|
|
26
|
+
|
|
27
|
+
class NativeEventTest {
|
|
28
|
+
@Test
|
|
29
|
+
fun javaVisibleApi_hasExactAbstractGetterSignatures() {
|
|
30
|
+
val methods = NativeEvent::class.java.declaredMethods.associateBy { it.name }
|
|
31
|
+
|
|
32
|
+
assertEquals(setOf("getEventName", "getEventBody", "getFirebaseAppName"), methods.keys)
|
|
33
|
+
assertEquals(String::class.java, methods.getValue("getEventName").returnType)
|
|
34
|
+
assertEquals(WritableMap::class.java, methods.getValue("getEventBody").returnType)
|
|
35
|
+
assertEquals(String::class.java, methods.getValue("getFirebaseAppName").returnType)
|
|
36
|
+
methods.values.forEach { method ->
|
|
37
|
+
assertEquals(0, method.parameterCount)
|
|
38
|
+
assertTrue(Modifier.isAbstract(method.modifiers))
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@Test
|
|
43
|
+
fun firebaseAppName_isNullableInKotlin() {
|
|
44
|
+
val event =
|
|
45
|
+
object : NativeEvent {
|
|
46
|
+
override fun getEventName(): String = "event_name"
|
|
47
|
+
|
|
48
|
+
override fun getEventBody(): WritableMap = error("Not used")
|
|
49
|
+
|
|
50
|
+
override fun getFirebaseAppName(): String? = null
|
|
51
|
+
}
|
|
52
|
+
val firebaseAppName: String? = event.getFirebaseAppName()
|
|
53
|
+
|
|
54
|
+
assertNull(firebaseAppName)
|
|
55
|
+
}
|
|
56
|
+
}
|