@@ -31,11 +31,15 @@ namespace {
31
31
32
32
using jni::ArrayList;
33
33
using jni::Env;
34
+ using jni::Global;
34
35
using jni::Local;
35
36
using jni::Object;
36
37
using jni::String;
38
+ using jni::Throwable;
37
39
40
+ using ::testing::IsEmpty;
38
41
using ::testing::Not;
42
+ using ::testing::StrEq;
39
43
40
44
TEST_F (FirestoreAndroidIntegrationTest, ToDebugStringWithNonNull) {
41
45
Env env;
@@ -57,7 +61,7 @@ TEST_F(FirestoreAndroidIntegrationTest,
57
61
ToDebugStringWithPendingExceptionAndNonNullObject) {
58
62
Env env;
59
63
Local<String> object = env.NewStringUtf (" Test Value" );
60
- env. Throw ( CreateException ( env, " forced exception " ) );
64
+ ThrowException ( env);
61
65
ASSERT_FALSE (env.ok ());
62
66
63
67
std::string debug_string = ToDebugString (object);
@@ -70,7 +74,7 @@ TEST_F(FirestoreAndroidIntegrationTest,
70
74
ToDebugStringWithPendingExceptionAndNullObject) {
71
75
Env env;
72
76
Object null_reference;
73
- env. Throw ( CreateException ( env, " forced exception " ) );
77
+ ThrowException ( env);
74
78
ASSERT_FALSE (env.ok ());
75
79
76
80
std::string debug_string = ToDebugString (null_reference);
@@ -125,6 +129,85 @@ TEST_F(FirestoreAndroidIntegrationTest,
125
129
EXPECT_THAT (list_object, Not (JavaEq (string_object)));
126
130
}
127
131
132
+ TEST_F (FirestoreAndroidIntegrationTest,
133
+ RefersToSameJavaObjectAsShouldReturnTrueForSameObjects) {
134
+ Env env;
135
+ Local<String> object1 = env.NewStringUtf (" string" );
136
+ Global<String> object2 = object1;
137
+
138
+ EXPECT_THAT (object1, RefersToSameJavaObjectAs (object2));
139
+ }
140
+
141
+ TEST_F (FirestoreAndroidIntegrationTest,
142
+ RefersToSameJavaObjectAsShouldReturnTrueForTwoNullReferences) {
143
+ Local<Object> null_reference1;
144
+ Local<Object> null_reference2;
145
+
146
+ EXPECT_THAT (null_reference1, RefersToSameJavaObjectAs (null_reference2));
147
+ }
148
+
149
+ TEST_F (FirestoreAndroidIntegrationTest,
150
+ RefersToSameJavaObjectAsShouldReturnFalseForDistinctObjects) {
151
+ Env env;
152
+ Local<String> object1 = env.NewStringUtf (" test string" );
153
+ Local<String> object2 = env.NewStringUtf (" test string" );
154
+ ASSERT_FALSE (env.IsSameObject (object1, object2));
155
+
156
+ EXPECT_THAT (object1, Not (RefersToSameJavaObjectAs (object2)));
157
+ }
158
+
159
+ TEST_F (FirestoreAndroidIntegrationTest,
160
+ RefersToSameJavaObjectAsShouldReturnFalseIfExactlyOneObjectIsNull) {
161
+ Env env;
162
+ Local<String> null_reference;
163
+ Local<String> non_null_reference = env.NewStringUtf (" string2" );
164
+
165
+ EXPECT_THAT (null_reference,
166
+ Not (RefersToSameJavaObjectAs (non_null_reference)));
167
+ EXPECT_THAT (non_null_reference,
168
+ Not (RefersToSameJavaObjectAs (null_reference)));
169
+ }
170
+
171
+ TEST_F (FirestoreAndroidIntegrationTest,
172
+ ThrowExceptionWithNoMessageShouldSetPendingExceptionWithAMessage) {
173
+ Env env;
174
+ Local<Throwable> throw_exception_return_value = ThrowException (env);
175
+ Local<Throwable> actually_thrown_exception = env.ClearExceptionOccurred ();
176
+ ASSERT_TRUE (actually_thrown_exception);
177
+ EXPECT_THAT (actually_thrown_exception,
178
+ RefersToSameJavaObjectAs (throw_exception_return_value));
179
+ EXPECT_THAT (actually_thrown_exception.GetMessage (env), Not (IsEmpty ()));
180
+ }
181
+
182
+ TEST_F (FirestoreAndroidIntegrationTest,
183
+ ThrowExceptionWithAMessageShouldSetPendingExceptionWithTheGivenMessage) {
184
+ Env env;
185
+ Local<Throwable> throw_exception_return_value =
186
+ ThrowException (env, " my test message" );
187
+ Local<Throwable> actually_thrown_exception = env.ClearExceptionOccurred ();
188
+ ASSERT_TRUE (actually_thrown_exception);
189
+ EXPECT_THAT (actually_thrown_exception,
190
+ RefersToSameJavaObjectAs (throw_exception_return_value));
191
+ EXPECT_THAT (actually_thrown_exception.GetMessage (env),
192
+ StrEq (" my test message" ));
193
+ }
194
+
195
+ TEST_F (FirestoreAndroidIntegrationTest,
196
+ CreateExceptionWithNoMessageShouldReturnAnExceptionWithAMessage) {
197
+ Env env;
198
+ Local<Throwable> exception = CreateException (env);
199
+ ASSERT_TRUE (exception );
200
+ EXPECT_THAT (exception .GetMessage (env), Not (IsEmpty ()));
201
+ }
202
+
203
+ TEST_F (FirestoreAndroidIntegrationTest,
204
+ CreateExceptionWithAMessageShouldReturnAnExceptionWithTheGivenMessage) {
205
+ Env env;
206
+ Local<Throwable> exception = CreateException (env, " my test message" );
207
+ ASSERT_TRUE (exception );
208
+ EXPECT_THAT (exception .GetMessage (env), StrEq (" my test message" ));
209
+ }
210
+
128
211
} // namespace
129
212
} // namespace firestore
130
213
} // namespace firebase
0 commit comments