Skip to content

Commit 2335d5e

Browse files
authored
Fix Firestore snapshot_metadata_android_test by using the new JNI API (#431)
1 parent 8c5fe0d commit 2335d5e

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

firestore/integration_test_internal/src/android/snapshot_metadata_android_test.cc

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "android/firestore_integration_test_android.h"
44
#include "firebase_test_framework.h"
55
#include "firestore/src/include/firebase/firestore/snapshot_metadata.h"
6+
#include "firestore/src/jni/declaration.h"
67
#include "firestore/src/jni/env.h"
78
#include "firestore_integration_test.h"
89
#include "gmock/gmock.h"
@@ -14,30 +15,33 @@ namespace firestore {
1415
using SnapshotMetadataAndroidTest = FirestoreAndroidIntegrationTest;
1516

1617
using jni::Class;
18+
using jni::Constructor;
1719
using jni::Env;
1820
using jni::Local;
1921

2022
TEST_F(SnapshotMetadataAndroidTest, Converts) {
21-
SKIP_TEST_ON_ANDROID; // TODO(b/183294303): Fix this test on Android.
22-
2323
Env env;
24-
25-
Local<Class> clazz =
26-
env.FindClass("com/google/firebase/firestore/SnapshotMetadata");
27-
jmethodID ctor = env.GetMethodId(clazz, "<init>", "(ZZ)V");
28-
29-
auto java_metadata = env.New<SnapshotMetadataInternal>(
30-
clazz, ctor, /*has_pending_writes=*/true, /*is_from_cache=*/false);
31-
SnapshotMetadata result = java_metadata.ToPublic(env);
32-
EXPECT_TRUE(result.has_pending_writes());
33-
EXPECT_FALSE(result.is_from_cache());
34-
35-
java_metadata = env.New<SnapshotMetadataInternal>(
36-
clazz, ctor, /*has_pending_writes=*/false,
37-
/*is_from_cache=*/true);
38-
result = java_metadata.ToPublic(env);
39-
EXPECT_FALSE(result.has_pending_writes());
40-
EXPECT_TRUE(result.is_from_cache());
24+
Constructor<SnapshotMetadataInternal> ctor("(ZZ)V");
25+
loader().LoadClass("com/google/firebase/firestore/SnapshotMetadata", ctor);
26+
ASSERT_TRUE(loader().ok());
27+
28+
{
29+
auto java_metadata =
30+
env.New(ctor, /*has_pending_writes=*/true, /*is_from_cache=*/false);
31+
SnapshotMetadata result = java_metadata.ToPublic(env);
32+
EXPECT_TRUE(env.ok());
33+
EXPECT_TRUE(result.has_pending_writes());
34+
EXPECT_FALSE(result.is_from_cache());
35+
}
36+
37+
{
38+
auto java_metadata =
39+
env.New(ctor, /*has_pending_writes=*/false, /*is_from_cache=*/true);
40+
SnapshotMetadata result = java_metadata.ToPublic(env);
41+
EXPECT_TRUE(env.ok());
42+
EXPECT_FALSE(result.has_pending_writes());
43+
EXPECT_TRUE(result.is_from_cache());
44+
}
4145
}
4246

4347
} // namespace firestore

0 commit comments

Comments
 (0)